mirror of
https://github.com/gwdevhub/gMod.git
synced 2026-07-15 15:09:30 +00:00
Release replacement textures when a client is torn down (#38)
* 1.9 * Release replacement textures when a client is torn down TextureClient::~TextureClient deleted the per-texture side-state but never released the replacement IDirect3DTexture9 objects gMod created. That's fine when the client dies because the device hit refcount 0 (a texture refs its device, so by then every fake is already released and the maps are empty). But when gMod is unloaded via FreeLibrary while the game's device is still alive (late-injected/SetDevice integrations), the maps are full of textures gMod still owns and they all leak - and ExitInstance never deleted the clients, so the destructor didn't even run. - ~TextureClient now releases each replacement it still owns (a fake is still owned while it has a partner; an orphaned fake was already released and is left alone). No-op in the device-release path. - Add DestroyAllTextureClients() to delete the per-device clients. - ExitInstance calls it, gated on a genuine FreeLibrary (lpReserved == nullptr) so it's skipped during process termination where the device/d3d9 may already be gone. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Jon <> Co-authored-by: Marc <m@pyc.ac> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -159,10 +159,15 @@ TextureClient::~TextureClient()
|
||||
std::lock_guard lk(registry_mutex);
|
||||
shutting_down = true; // the texture Release hook now no-ops for our textures
|
||||
|
||||
// Drop side-state but don't Release the textures: the game already released
|
||||
// its originals (and our fakes with them), and the device may be gone.
|
||||
for (const auto state : fakes | std::views::values) {
|
||||
delete state;
|
||||
// Release replacements we still own (still partnered) so they aren't leaked when
|
||||
// torn down with the device alive (FreeLibrary). Orphaned fakes were already
|
||||
// released; a device-release teardown leaves the maps empty, so this is a no-op.
|
||||
for (const auto fake : fakes | std::views::values) {
|
||||
if (fake->partner != nullptr) {
|
||||
fake->partner->partner = nullptr; // detach the original's back-pointer
|
||||
if (fake->real) fake->real->Release();
|
||||
}
|
||||
delete fake;
|
||||
}
|
||||
fakes.clear();
|
||||
for (const auto state : originals | std::views::values) {
|
||||
|
||||
Reference in New Issue
Block a user