stackgl / headless-gl

🎃 Windowless WebGL for node.js
1.73k stars 166 forks source link

fix(*): fix draw elements when WebGLVertexArrayObjectAttribute cleanedUp #258

Closed stepancar closed 1 year ago

stepancar commented 1 year ago

Hello! I'm trying to fix this issue with skottie animation

https://github.com/michaeljherrmann/skottie-issue

Under the hood at some point skia, calles WebGLVertexArrayObjectAttribute._clear which sets

this._vertexObjectState._attribs[0]._isPointer to false.

and this code executes https://github.com/stackgl/headless-gl/blob/master/src/javascript/webgl-rendering-context.js#L1974-L1976

After that rendering anything with webgl canvas does not any effect.

When I removed if statement, it worked fine.

I found this PR https://github.com/stackgl/headless-gl/pull/160 It seems like the problem is similar

Could you validate it? does it make sense?

Thank you!

As a workaround we create new webgl context on every frame 👎

stepancar commented 1 year ago

Maybe call stack will be helpful Frame 3: enableVertexAttribArray 2 drawElements disableVertexAttribArray 2 enableVertexAttribArray 2 disableVertexAttribArray 2

Frame 5: enableVertexAttribArray 2 set point buffer for attrib 0 true set point buffer for attrib 1 true set point buffer for attrib 2 true drawElements disableVertexAttribArray 2 enableVertexAttribArray 2 disableVertexAttribArray 2 deleteBuffer releaseArrayBuffer 0 releaseArrayBuffer 1 releaseArrayBuffer 2

Next frames are transparent >>> Frame 35: enableVertexAttribArray 2 set point buffer for attrib 0 true set point buffer for attrib 1 true set point buffer for attrib 2 true _drawElementsInstanced <<<<< HERE disableVertexAttribArray 2 enableVertexAttribArray 2 disableVertexAttribArray 2 deleteBuffer releaseArrayBuffer 0 releaseArrayBuffer 1 releaseArrayBuffer 2

dhritzkiv commented 1 year ago

Thanks for the fix!

stepancar commented 1 year ago

@dhritzkiv , Are you sure it's a good fix? Because I've checked it only for my case, I tried to figure out with code, but no luck.

@dhritzkiv If you could explain how does it work it would be awesome! Thank you!

stepancar commented 1 year ago

@dhritzkiv , we are running this fix on production for a week and don't see any issues. Can we release new package version with this fix?

stepancar commented 1 year ago

@dhritzkiv , can we release new version?