Sorry for reviving this old thread, but I’m seeing a similar issue currently in my project but in a different function of the engine.
Was wondering if anyone here might be able to point me in the right direction for how to solve this. It’s happening on the latest stable release (1.39) and was happening on the previous release as well (1.38.4). Those are the only two engine versions we’ve been working with.
This is the error that is thrown:
playcanvas-stable.js:22098 Uncaught TypeError: Cannot read property 'cull' of null
at ForwardRenderer.setCullMode (playcanvas-stable.js:22098)
at ForwardRenderer.renderForward (playcanvas-stable.js:22273)
at ForwardRenderer.renderComposition (playcanvas-stable.js:23205)
at Application.render (playcanvas-stable.js:66055)
at playcanvas-stable.js:66763
Our project is set up of multiple scenes, and this error happens when switching between scenes roughly 8 times, and can get it to happen consistently.
This is good info I appreciate it, I will continue to dig and and see if I can find the culprit.
We have some scripts that work with the layers a little bit, do you think there’s a possibility that something is being held onto between scene switches there?
it’s possible some mesh instances are deleted but not removed from layers or something like that, and so when the engine tries to render them, it fails.
Alright I have an update on this and wondering if anyone here might be able to shed a bit more light. We have a script that runs in 3 out of 5 of our scenes. In that script we copy over the meshes from the world layer into our own custom layer like so:
When this works fine, the resulting array of meshes is 7 in length.
When it fails, there are 10 items in: this.layerRefraction.opaqueMeshInstances
The 3 MeshInstances that are different all have their node property set as an Entity with the name: "Untitled" and their materials are of course null which is causing the error.
Whereas the rest of the MeshInstances all have their node properties set as GraphNode with names that should appear in the scene.
Hopefully these details make sense, and maybe shed some more light on what might be happening.
Odd that they are untitled? Do you create entities at run time? Might be worth use specific entity name when creating so it’s easier to narrow down when/what they are.
Updated my answer above with a bit more info. But yes I thought it was strange these were entities with no names.
I just double checked and we aren’t adding any Entities programmatically either, so not sure why/how these suddenly appear. The weirdest part is that it doesn’t happen every time, it still only happens intermittently.
You could walk through the parent hierarchy to see what it is attached to if anything?
Without a reproducible it’s really difficult to tell. Is there any reparenting done in the app? Is it possible that an Entity isn’t part of hierarchy because it is created or unparented to something?
Ok so the print graph might be onto something here, unless I’m interpreting things wrongly. I’ve attached a piece of the printed graph and the same setup as reflected in the scene editor, it looks like there are “untitled” entities coming out of primitives in the scene that have been disabled?
It’s the strangest thing. Anyway I’ve managed to hack together a fix.
When copying the MeshInstances from the world layer into our custom layer, I’m checking to see if the mesh instance has a material or not, and also if the name is “Untitled” as we don’t purposefully add any “Untitled” enitities to our scene.
I noticed last night that I could loop through and the Entities that are named “Untitled” actually have a material set at the time of copying them into our custom layer. It’s only at some point after that these entities materials are set to null. I’m not sure why or how that is happening, but regardless, this hack will do the job for our purposes.
Refraction.prototype.addMeshes = function() {
var oMeshes = [];
for ( var i=0; i < this.layerWorld.opaqueMeshInstances.length; i++ ) {
if ( this.layerWorld.opaqueMeshInstances[i].material !== null &&
this.layerWorld.opaqueMeshInstances[i].node.name !== "Untitled" ) {
console.log( "ADD", this.layerWorld.opaqueMeshInstances[i], this.layerWorld.opaqueMeshInstances[i].material );
oMeshes.push( this.layerWorld.opaqueMeshInstances[i] );
}
}
this.layerRefraction.addMeshInstances( oMeshes );
var tMeshes = [];
for ( var j=0; j < this.layerWorld.transparentMeshInstances.length; j++ ) {
if ( this.layerWorld.transparentMeshInstances[j].material !== null &&
this.layerWorld.transparentMeshInstances[j].node.name !== "Untitled" ) {
tMeshes.push( this.layerWorld.transparentMeshInstances[j] );
}
}
this.layerRefraction.addMeshInstances( tMeshes );
};
Question for you though? Why do those primitives add their materials to the scene as MeshInstances with the name “Untitled” and not the name given to the material in the editor?
MeshInstances do not have names … the name you check is meshInstance.node.name … which is either Entity, or GraphNode (so a part of the hierarchy) - so there are some of these with name Untitled. These could have been added from code maybe? And not from the scene in the editor. Maybe if you use batching, those were created as batches and similar as well.