SpritePackedManager cleanup issue

It seems SpritePackedManager leaves something behind if you call dispose functions too quickly.

I’m using Babylon.js with React for my project. Since React is a “reactive” system, it provides a way to interact with imperative ones, which is called Effect. So, I’ve had to write cleanup codes appropriately for every Babylon.js objects. Plus, React runs its Effect twice in development environment, for developers to spot bugs in their cleanups.

As it turns out, SpritePackedManager, if created synchronously using React Effect, generates an infinite number of log warnings, seemingly because some objects weren’t cleaned up properly during the immediately followed dispose calls.

I’m not sure if this is a right usage of Playground, but I managed to repro the issue below. (I injected another canvas element to the DOM. Please let me know if this isn’t allowed.)

There, some code keeps itself running with some supposed-to-be-deleted things, and the browser would deny logging anything more about the WebGL context.

BTW, this only happens with a SpritePackedManager created. You can see a version without one runs peacefully :slight_smile:

Would anyone fix this? Thanks.

The problem lies not with the sprite manager, but with the fact that when shaders are compiled asynchronously, if the effect linked to that shader or the entire engine is disposed during this time, the program crashes.

Here’s the PR that will fix the problem:

1 Like

Perfect! Thanks :+1: