- fixed crash in texture deinit code and ensure that everything gets deleted.

This commit is contained in:
Christoph Oelckers 2019-10-16 21:16:40 +02:00
parent 37322d001d
commit 4cd2c024fc
6 changed files with 45 additions and 28 deletions

View file

@ -649,7 +649,7 @@ FHardwareTexture *mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t
*texidx = 0;
auto texture = FTexture::GetTexture(fn);
auto texture = TileFiles.GetTexture(fn);
if (texture == nullptr)
{

View file

@ -524,7 +524,7 @@ int32_t polymost_maskWallHasTranslucency(uwalltype const * const wall)
if (palookup[pal] == NULL)
pal = 0;
auto tex = FTexture::GetTexture(si->filename);
auto tex = TileFiles.GetTexture(si->filename);
return tex && tex->GetTranslucency();
}
@ -545,7 +545,7 @@ int32_t polymost_spriteHasTranslucency(uspritetype const * const tspr)
if (palookup[pal] == NULL)
pal = 0;
auto tex = FTexture::GetTexture(si->filename);
auto tex = TileFiles.GetTexture(si->filename);
return tex && tex->GetTranslucency();
}

View file

@ -174,7 +174,7 @@ int32_t gloadtile_hi(int32_t dapic, int32_t dapalnum, int32_t facen, hicreplctyp
fn = hicr->filename;
}
auto texture = FTexture::GetTexture(fn);
auto texture = TileFiles.GetTexture(fn);
if (texture == nullptr)
{

View file

@ -127,6 +127,7 @@ FArtTile* GetTileTexture(const char* name, const TArray<uint8_t>& backingstore,
void BuildFiles::AddTile(int tilenum, FTexture* tex, bool permap)
{
assert(AllTiles.Find(tex) == AllTiles.Size() && AllMapTiles.Find(tex) == AllMapTiles.Size());
auto& array = permap ? AllMapTiles : AllTiles;
array.Push(tex);
tiles[tilenum] = tex;
@ -415,7 +416,7 @@ int32_t tileCRC(int tileNum)
int tileImportFromTexture(const char* fn, int tilenum, int alphacut, int istexture)
{
FTexture* tex = FTexture::GetTexture(fn);
FTexture* tex = TileFiles.GetTexture(fn);
if (tex == nullptr) return -1;
tex->alphaThreshold = 255 - alphacut;
@ -424,8 +425,6 @@ int tileImportFromTexture(const char* fn, int tilenum, int alphacut, int istextu
if (xsiz <= 0 || ysiz <= 0)
return -2;
TileFiles.AddTile(tilenum, tex);
#if 0
// Does this make any difference when the texture gets *properly* inserted into the tile array?
if (istexture)
@ -630,6 +629,41 @@ void tileSetAnim(int tile, const picanm_t& anm)
}
//==========================================================================
//
//
//
//==========================================================================
FTexture* BuildFiles::GetTexture(const char* path)
{
auto res = textures.CheckKey(path);
if (res) return *res;
auto tex = FTexture::CreateTexture(path);
if (tex) textures.Insert(path, tex);
return tex;
}
//==========================================================================
//
//
//
//==========================================================================
void BuildFiles::CloseAll()
{
decltype(textures)::Iterator it(textures);
decltype(textures)::Pair* pair;
while (it.NextPair(pair)) delete pair->Value;
textures.Clear();
CloseAllMapArt();
ArtFiles.DeleteAndClear();
AllTiles.DeleteAndClear();
if (Placeholder) delete Placeholder;
Placeholder = nullptr;
}
TileSiz tilesiz;
PicAnm picanm;
PicSiz picsiz;

View file

@ -421,14 +421,3 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits)
#endif
TMap<FString, FTexture *> textures;
FTexture *FTexture::GetTexture(const char *path)
{
auto res = textures.CheckKey(path);
if (res) return *res;
auto tex = FTexture::CreateTexture(path);
if (tex) textures.Insert(path, tex);
return tex;
}

View file

@ -202,7 +202,6 @@ public:
};
static FTexture *CreateTexture(const char *name);
static FTexture* GetTexture(const char* path);
virtual ~FTexture ();
virtual FImageSource *GetImage() const { return nullptr; }
@ -480,6 +479,7 @@ struct BuildFiles
TDeletingArray<FTexture*> AllMapTiles; // Same for map tiles;
FTexture* tiles[MAXTILES];
FTexture* tilesbak[MAXTILES];
TMap<FString, FTexture*> textures;
BuildFiles()
{
@ -489,17 +489,11 @@ struct BuildFiles
}
~BuildFiles()
{
delete Placeholder;
if (Placeholder) delete Placeholder;
}
void CloseAll()
{
CloseAllMapArt();
ArtFiles.DeleteAndClear();
AllTiles.DeleteAndClear();
delete Placeholder;
Placeholder = nullptr;
}
void CloseAll();
FTexture* GetTexture(const char* path);
void AddTile(int tilenum, FTexture* tex, bool permap = false);