From 0d07fb255033c881409e25990192e345fb34c3d2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 10 Dec 2018 02:50:22 +0100 Subject: [PATCH] Use FImageTexture for thre null texture FDummyTexture had a big problem: Whenever it was accessed by accident it crashed the app because it wasn't fully implemented. What it should do is return empty pixels of the given size, and an unextended FImageTexture is doing just that. --- src/textures/multipatchtexturebuilder.cpp | 2 +- src/textures/texture.cpp | 20 -------------------- src/textures/texturemanager.cpp | 4 +++- src/textures/textures.h | 18 +++++++++--------- 4 files changed, 13 insertions(+), 31 deletions(-) diff --git a/src/textures/multipatchtexturebuilder.cpp b/src/textures/multipatchtexturebuilder.cpp index ac2b06917..aa727bef1 100644 --- a/src/textures/multipatchtexturebuilder.cpp +++ b/src/textures/multipatchtexturebuilder.cpp @@ -364,7 +364,7 @@ void FMultipatchTextureBuilder::AddTexturesLump(const void *lumpdata, int lumpsi // It still needs to be created in case someone uses it by name. offset = LittleLong(directory[1]); const maptexture_t *tex = (const maptexture_t *)((const uint8_t *)maptex + offset); - FDummyTexture *tex0 = static_cast(TexMan.ByIndex(0)); + FTexture *tex0 = TexMan.ByIndex(0); tex0->SetSize(SAFESHORT(tex->width), SAFESHORT(tex->height)); } diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index 4f6257f24..0b22866ef 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -761,26 +761,6 @@ TArray FTexture::Get8BitPixels(bool alphatex) return Pixels; } -//=========================================================================== -// -// Dummy texture for the 0-entry. -// -//=========================================================================== - -FDummyTexture::FDummyTexture () -{ - Width = 64; - Height = 64; - UseType = ETextureType::Null; -} - -void FDummyTexture::SetSize (int width, int height) -{ - Width = width; - Height = height; -} - - //========================================================================== // // diff --git a/src/textures/texturemanager.cpp b/src/textures/texturemanager.cpp index 66c43ac62..558a6243c 100644 --- a/src/textures/texturemanager.cpp +++ b/src/textures/texturemanager.cpp @@ -1003,7 +1003,9 @@ void FTextureManager::Init() FTexture::InitGrayMap(); // Texture 0 is a dummy texture used to indicate "no texture" - AddTexture (new FDummyTexture); + auto nulltex = new FImageTexture(nullptr); + nulltex->SetUseType(ETextureType::Null); + AddTexture (nulltex); // some special textures used in the game. AddTexture(CreateShaderTexture(false, false)); AddTexture(CreateShaderTexture(false, true)); diff --git a/src/textures/textures.h b/src/textures/textures.h index 54c10aab1..56a90608b 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -382,7 +382,15 @@ protected: float shaderspeed = 1.f; int shaderindex = 0; - + // This is only legal for the null texture! + void SetSize(int w, int h) + { + if (UseType == ETextureType::Null) + { + Width = w; + Height = h; + } + } // Returns true if GetPixelsBgra includes mipmaps virtual bool Mipmapped() { return true; } @@ -657,14 +665,6 @@ public: }; -// A texture that doesn't really exist -class FDummyTexture : public FTexture -{ -public: - FDummyTexture (); - void SetSize (int width, int height); -}; - // A texture that can be drawn to. class DCanvas;