Hello,
When I dispose meshes with mesh.dispose();
disposing meshes give me error:
Uncaught TypeError: Cannot read property 'meshes' of null
at Array.e.splice (babylonjs.js:16)
at Array.e.splice (babylonjs.js:16)
at Array.e.splice (babylonjs.js:16)
at Array.e.splice (babylonjs.js:16)
at Array.e.splice (babylonjs.js:16)
at Array.e.splice (babylonjs.js:16)
at Array.e.splice (babylonjs.js:16)
at Array.e.splice (babylonjs.js:16)
at Array.e.splice (babylonjs.js:16)
at Array.e.splice (babylonjs.js:16)
It happen when only there is a mesh remains in scene. If more than one mesh exist, error not triggered.
I donāt have any scene.dispose or engine.dispose in my code, but it was working till a few weeks ago, I donāt know what happened? I did a few steps to optimize me scene from this page
It is a huge project, but your help let me think checking where scene customized. I will try to make it a Playground. Thanks @Evgeni_Popov
I found the problem, but it is so weird!!!
One of my optimizations was reduce mapSize of shadowGenerator by FPS after loading each new mesh and this is the code:
Are you doing this each frame? You should not, it recreates a number of textures under the hood, and the system may not have time to render a new frame that you already change for a new size. Also, you should not change the size if the difference in fps is not significant enough from the last time you changed the size. Thereās no point to change from 503 to 494 for eg (if fps changes from 59 to 58).
I played around with mapSize of shadowGenerator, it has huge effect on cpu usage. My point is to reduce mapSize based on userās device, doesnāt matter when and where for me, I just want higher quality for better devices, and higher fps for lower devices.
Thanks for considering the issue
At last I made it,
It happen when a mesh added and mesh accepts shadow, and after that change mapSize of shadowGenerator then remove mesh.
And I successfully made playground (check console) Note: If another mesh exist in scene that accepts shadow, error will not shows up.
Thanks @Evgeni_Popov , Iām not using .ts and so I did my own changes on babaylonjs.js file like so:
In case someone need:
(e.prototype.recreateShadowMap = function () {
var e = this._shadowMap;
if (e) {
var t = e.renderList;
this._disposeRTTandPostProcesses(), this._initializeGenerator(), (this.filter = this.filter), this._applyFilterValues();
//(this._shadowMap.renderList = t);
if (t) {
// Note: don't do this._shadowMap!.renderList = renderList;
// The renderList hooked array is accessing the old RenderTargetTexture (see RenderTargetTexture._hookArray), which is disposed at this point (by the call to _disposeRTTandPostProcesses)
if (!this._shadowMap.renderList) {
this._shadowMap.renderList = [];
}
for (const mesh of t) {
this._shadowMap.renderList.push(mesh);
}
} else {
this._shadowMap.renderList = null;
}
}
})