From 120b9502912ccf81962b0fa1d67ba2472791cf80 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 20 Dec 2018 18:10:06 +0100 Subject: [PATCH] - changed FTextureManager::ReplaceTexture to only append the new texture instead of replacing the old one. This should ensure that other references to the original will remain valid. --- src/textures/texture.cpp | 2 +- src/textures/texturemanager.cpp | 15 ++++----------- src/textures/textures.h | 1 - 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index 44203413a..118bbf5bc 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -138,7 +138,7 @@ FTexture::FTexture (const char *name, int lumpnum) : Scale(1,1), SourceLump(lumpnum), UseType(ETextureType::Any), bNoDecals(false), bNoRemap0(false), bWorldPanning(false), - bMasked(true), bAlphaTexture(false), bHasCanvas(false), bWarped(0), bComplex(false), bMultiPatch(false), bKeepAround(false), bFullNameTexture(false), + bMasked(true), bAlphaTexture(false), bHasCanvas(false), bWarped(0), bComplex(false), bMultiPatch(false), bFullNameTexture(false), Rotations(0xFFFF), SkyOffset(0), Width(0), Height(0) { bBrightmapChecked = false; diff --git a/src/textures/texturemanager.cpp b/src/textures/texturemanager.cpp index 799edb4aa..584664d3f 100644 --- a/src/textures/texturemanager.cpp +++ b/src/textures/texturemanager.cpp @@ -468,17 +468,10 @@ void FTextureManager::ReplaceTexture (FTextureID picnum, FTexture *newtexture, b newtexture->Name = oldtexture->Name; newtexture->UseType = oldtexture->UseType; - Textures[index].Texture = newtexture; - - newtexture->id = oldtexture->id; - if (free && !oldtexture->bKeepAround) - { - delete oldtexture; - } - else - { - oldtexture->id.SetInvalid(); - } + // Add the new texture at the end of the texture list and clear the old one's name to ensure it won't be found anymore + // We cannot actually replace it because it may be referenced by some other texture. + oldtexture->Name = ""; + AddTexture(newtexture); } //========================================================================== diff --git a/src/textures/textures.h b/src/textures/textures.h index a91be051b..52ed052db 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -407,7 +407,6 @@ protected: // fully composited before subjected to any kind of postprocessing instead of // doing it per patch. uint8_t bMultiPatch:2; // This is a multipatch texture (we really could use real type info for textures...) - uint8_t bKeepAround:1; // This texture was used as part of a multi-patch texture. Do not free it. uint8_t bFullNameTexture : 1; uint8_t bBrightmapChecked : 1; // Set to 1 if brightmap has been checked uint8_t bGlowing : 1; // Texture glow color