Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Engine: fix overlays or cursor crash software render if sprite unloads
This problem with overlays might be dating back to the late 3.6.0 development, and is affecting mouse cursors probably since 3.6.1 (it may be difficult to specify now). But at some point I have missed this fact that if we do not clone a sprite assigned to a game object, and such sprite gets unloaded when freeing space in a sprite cache, then the Software renderer might crash when presenting visible objects on screen. Because in its current implementation Software renderer's pseudo-textures do not take ownership of a sprite's image, but only have a reference of it. For Characters and Room objects Software renderer already clones their sprites, primarily because it has to cache various visual effects done on them. But it no longer does for: Screen Overlays, and mouse cursor. This is very easy to test (with Software renderer): - create a screen overlay with non-dynamic sprite on it, and/or simply have a mouse cursor with non-dynamic sprite. - start loading very big regular sprites into memory. - as soon as sprite cache reaches the limit, it will free some sprites, and with very high chance overlay and/or cursor will cause a crash. Anyway, a proper long-term solution for this would perhaps be to lock the sprites that are in current use on visible game objects. This would require a precise control over locked state, and a sprite lock counter (instead of just a flag). For now I have to make a quick fix, which would simply test if a sprite is loaded, and tell to reupdate the texture if it's not.
- Loading branch information