Need to call resetDrawCache before setMaterialForRendering?

When calling setMaterialForRendering() on an effect, if changing e.g. from a StandardMaterial to a NodeMaterial (or vice versa) then a runtime error crashes the page…

And from checking the source and debugging I eventually found that a workaround is to first call resetDrawCache() on the mesh like below (comment this reset out on line 23 to see the error in the console).

So I wonder if setMaterialForRendering() should call resetDrawCache() on the mesh that we pass in for us to prevent this error? Or some other solution?

PS the node material in the playground is just the default saved from NME, so just sets the color to white. :slight_smile:

Yes, I think this call should be done. It had already been fixed in the glow layer when calling referenceMeshToUseItsOwnMaterial and unReferenceMeshFromUsingItsOwnMaterial for this very reason:

Fancy doing a PR for that? (note that you should reset the draw cache only for this._mainTexture.renderPassId).

OK here it is, I actually ended up adding it to setMaterialForRenderPass to make the fix more general. :slight_smile:

2 Likes