[Error] `this._attributes is undefined`

Babylon: 6.7.0
Devices: Desktop
Browsers: Firefox 78,102,112,114, 115, 116 and others

I see the error in the particle system. I’m using GPUParticleSystem.

I have two kind of PS - code-based and from the snippet. But unfortunately, I can’t tell you which one with this issue(maybe both).

TypeError: this._attributes is undefined

at e.prototype.getAttributeLocation
at e.prototype._bindVertexBuffersAttributes
at e.prototype.recordVertexArrayObject
at e.prototype._createUpdateVAO
at e.prototype.createVertexBuffers
at t.prototype._createVertexBuffers
at t.prototype._initialize
at t.prototype.render 
at e.prototype._renderParticles
at e.prototype.render
at e.prototype.render
at t.prototype._renderForCamera
at t.prototype._processSubCameras 
at t.prototype.render
at t.prototype._renderFrame 
at t.prototype._renderLoop

I have similar stack trace on others devices(Mobile Chrome 89.0.4389, Tablet Chrome 87.0.4280 …):

TypeError: Cannot read properties of undefined (reading ‘0’)

  at e.getAttributeLocation [js/babylon-6_7_0.js:1:238409]
  at e._bindVertexBuffersAttributes [js/babylon-6_7_0.js:1:315516]
  at e.recordVertexArrayObject [js/babylon-6_7_0.js:1:316246]
  at e._createUpdateVAO [js/babylon-6_7_0.js:1:3722062]
  at e.createVertexBuffers [js/babylon-6_7_0.js:1:3718697]
  at t._createVertexBuffers [js/babylon-6_7_0.js:1:3821078]
  at t._initialize [js/babylon-6_7_0.js:1:3823676]
  at t.render [js/babylon-6_7_0.js:1:3834246]
  at e._renderParticles [js/babylon-6_7_0.js:1:448080]
  at e.render [js/babylon-6_7_0.js:1:444174]

I found this line where _attributes has been assigned: https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Materials/effect.ts#L784

Seems like I start PS before it’s ready…

I see this._initialize() https://github.com/BabylonJS/Babylon.js/blob/8a42ad80d4419c668120f5eedac9be6a2b8f5a3a/packages/dev/core/src/Particles/gpuParticleSystem.ts#L1671 only on GPUParticleSystem.

Given your stack trace, I tried to reproduce the problem, but was unable to.

Accessing _attributes when it is not initialized can happen if _createUpdateVAO is called with an effect that is not yet ready. In this case, the effect is _updateEffect, but _initialize (and therefore, _createUpdateVAO) can only be called if _updateEffect is ready. At least, that’s what happens in my tests…

What you could test is to set engine.getCaps().parallelShaderCompile = null and see if that helps. This will force the shader compilation to be synchronous.

If you’re able to set up a repro, that would be a big help.

[…] I have been able to reproduce the problem when simulating a context lost!

This PR will fix the bug (hoping your problem stems from a context lost indeed!):

However, if you use your own particle effect from a node material, you have to recreate the effect when the context is restored.

Here’s how to do it:


Right now I replaced GPU PS to CPU PS :grin: But yeah, thank you for a possible test case. I’ll try to reproduce it.

You may not have, if the fix fixes it.

1 Like