greggman / twgl.js

A Tiny WebGL helper Library
http://twgljs.org
MIT License
2.61k stars 258 forks source link

Fixes uncaught TypeError in certain conditions #156

Closed jamesplease closed 4 years ago

jamesplease commented 4 years ago

In this loop, there is no guarantee that lastUsedBufferInfo is not null at the time that this conditional is reached. Consequently, you can find yourself in a situation where calling this method throws an uncaught exception.

I'm running into this when loading ~60 images into memory using twgl.createTextures and then calling this method after the images are loaded. Sometimes this method errors when I am doing this, perhaps due to some race condition? I'm not sure the specific cause, but this change makes this function type safe, and ensures the uncaught exception will never happen.