Decal Graffiti sample has an error

The Decal Graffiti sample below seems to be giving me an error. I think it used to work. Has something changed?

sourceMesh.decalMap.renderTexture(decalsTex[decal.current], position, normal, decal.currentSize, decal.angle);
VM70:144 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'renderTexture')
    at createDecal (<anonymous>:144:33)
createDecal	@	VM70:144
await in createDecal		
(anonymous)	@	VM70:185
e.notifyObservers	@	observable.ts:405
e._processPointerUp	@	scene.inputManager.ts:545
(anonymous)	@	scene.inputManager.ts:1018
_initClickEvent	@	scene.inputManager.ts:698
_onPointerUp	@	scene.inputManager.ts:947
(anonymous)	@	scene.inputManager.ts:1084
e.notifyObservers	@	observable.ts:405
e._onInputChanged	@	deviceSourceManager.ts:164
a	@	internalDeviceSourceManager.ts:81
_pointerUpEvent	@	webDeviceInputSystem.ts:637

I’ve tried it a few times and it seems to work sometimes and not others.

I can repro:

Works on WebGL however fails on WebGPU…

The issue is that the decal map plugin is not initialized on the material:
Temporary fix at line 80:

Thanks for checking, I encountered this error in WebGL2.

Is it working with the temporary fix?

Digging deeper: Returns null because _uniformBufferLayoutBuilt === true

Works if the material is cloned.

meshes.brickSphere.material = meshes.brickSphere.material.clone()

This leads me to conclude that there is a timing issue, so I tried loading the model in the scene.onReadyObservable callback, and that also fixes the issue:

1 Like

Thank you for the explanation and sample! :folded_hands:

To make sure I’m understanding the problem correctly, I tried to summarize the issue and solution in the diagram below.
This is just my interpretation based on your explanation—please let me know if I misunderstood anything.

I believe @Evgeni_Popov could shed more light on this issue and possibly propose a permanent solution. I just did some quick research into the cause of the problem.

1 Like