Unable to create vertex buffer error

I sporadically see clients getting “Unable to create vertex buffer” and “Unable to create texture” errors. I always thought this was caused by memory limits, but I recently noticed it as well on a high end gaming PC. That one was not after a long session and also after a year of not having the error from that device. After a refresh of the page the next error from thinEngine was “WebGL not supported” which was resolved by restarting the browser.

What are the possible causes of the first error and how can I best catch it and show a message to the user?
Related: what is the best way to inspect the GPU memory? Amount used by the page, but also which assets are taking up the biggest chunk?

For memory leaks you may check
inside the render loop.

That’s hard to tell, the code throwing the first error is:

        var vbo = this._gl.createBuffer();

        if (!vbo) {
            throw new Error("Unable to create vertex buffer");

So it’s WebGL that can’t create a buffer. We can’t really do anything on Babylon.js side about this, that’s why we throw an exception. I think this error can show up if there’s not enough available resource to create the buffer.

One possibility is that the WebGL context has just been lost / is about to be lost. Note that we improved the handling of context lost/restoration in 5.0, that could help with your problem (the context lost/restoration handling must be enabled in Babylon.js for it to work - which is the default setting. See the options parameter to the Engine constructor). You can register a callback with Engine.onContextLostObservable and Engine.onContextRestoredObservable if you want to react on those events.

Regarding the GPU memory it’s a difficult thing, the driver is free to handle the memory in any way it wants. So, you could see (with an appropriate tool - I don’t know which) that all the GPU memory is used whereas it facts it is simply the driver that allocated all the memory and which is managing it itself.

1 Like