FWGS / xash3d

DEPRECATED in favor of https://github.com/FWGS/xash3d-fwgs. Only bugfixes are accepted.
https://xash.su
GNU General Public License v3.0
549 stars 107 forks source link

Add reference count for GL_LoadTexture/GL_FreeTexture #433

Closed MoeMod closed 5 years ago

MoeMod commented 5 years ago

Problem

When both A and B get an texture id from engine by GL_LoadTexture, it's possible to reuse the id by hash table. However, if A frees it by GL_FreeTexture but B doesn't, the texture will be invalid for B... It means that B may try to draw / free an invalid texture that was already freed.

Possible solution

Add a reference count for r_textures, and only really free it if (count==0).

Associated source file

engine/client/gl_image.c

a1batross commented 5 years ago

While it will not give potential overhead, may I ask, how it's happened if A releases texture while B still using it? I mean, typically resource releasing should happen on map reloading, engine shutdown and such. In that case B should re-load texture again.

If you need to update content of GL texture, it's better to use GL functions for that, omitting Xash's texture management.

a1batross commented 5 years ago

Maybe it's an architectural problem and isn't an engine bug.

MoeMod commented 5 years ago

OK, maybe something was wrong in my client code...