libtcod / python-tcod

A high-performance Python port of libtcod. Includes the libtcodpy module for backwards compatibility with older projects.
BSD 2-Clause "Simplified" License
404 stars 37 forks source link

SDL_DestroyTexture called with invalid textures #129

Open HexDecimal opened 1 year ago

HexDecimal commented 1 year ago

Enabling SDL logging allowed me to track down this error.

https://github.com/libtcod/python-tcod/blob/49ebc65ddf0fb0292f667dca9d43b7d5fe1ca7bd/tcod/sdl/render.py#L316

This line creates a texture and takes ownership, but SDL will sometimes destroy the texture owned by this object, causing SDL_DestroyTexture to fail later and sometimes crash the program.

This issue can crash the samples if you restart the renderer during that program.

I'm noting this now so that I don't forget to fix this. I'll probably have the renderer track its textures with weak references and release ownership of its them when the renderer itself is deleted.