WebGL errors with custom mesh in a webpack project

I wrote a voxel mesher which you can see working here:
https://www.babylonjs-playground.com/#XKG7EX#9

but when I use it in my local project I get a bunch of WebGL errors:
babylon.js:1 WebGL: INVALID_OPERATION: uniformMatrix4fv: location is not from current program
WebGL: INVALID_OPERATION: uniform3f: location not for current program

And the model seems to be missing its normals and colored vertices.
A difference I can think of is that my project is using webpack and is placing babylonjs in the vendor.js bundle outside of the main gamelogic and site code.

These errors only happened when using the custom mesh object. Has anyone seen anything like this? Do I need to not split the codebase? Are there guidelines about how to use babylonjs with webpack and code splitting?

Thanks!

Bundling with webpack should not change anything. This is really weird. Could you share a github project containing the repro ? This would help a lot for troubleshooting. Thx.

When I removed all of my other game logic out, and setup a single scene and create the custom mesh everything is fine. So now I need to start adding the bits of my game back in to find out which part caused the problem. I’ll let you know what I find. Thanks!

Sounds good to me :slight_smile: do not hesitate would you need anything :wink:

The crash error I was getting in my game was:
Uncaught TypeError: Cannot read property ‘getViewCount’ of undefined
at Function.e.PrepareDefinesForMultiview (babylon.js:16)
at t.isReadyForSubMesh (babylon.js:16)
at t.render (babylon.js:16)
at t.render (babylon.js:16)
at i.25.i.renderUnsorted (loglevel.js:250)
at i.25.i.render (loglevel.js:250)
at p.25.p.render (loglevel.js:250)
at E.25.E._renderForCamera (loglevel.js:250)
at E.25.E._processSubCameras (loglevel.js:250)
at E.25.E.render (loglevel.js:250)

okay… it took a bunch of hunting and turning systems on and off and what I’ve found is that commenting out a single line solved the problem.
const loaders = require('babylonjs-loaders')

I don’t know why, loaders is never used. Before writing my own mesher I tried using the babylon assets manager to load some obj models. it never worked. it would always fail and so I tried adding this loader library and it still didn’t work and forgot about it as I moved onto rebuilding the voxel mesh in babylon.

So, I can remove that line and it won’t cause me any problems since it was a failed attempt at something I don’t need. But I don’t understand why requiring/importing the babylonjs-loaders library would break viewing a custom mesh. If I put any custom mesh in front of the camera with that library imported babylonjs would crash.

Thanks!

This sounds pretty weird indeed it might aversion conflict between both i have seen it happen often and as you are not even using it it is even easier to fall out of sync.