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.
This commit is contained in:
Christoph Oelckers 2018-12-10 02:50:22 +01:00
parent b32aa60760
commit 0d07fb2550
4 changed files with 13 additions and 31 deletions

View file

@ -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. // It still needs to be created in case someone uses it by name.
offset = LittleLong(directory[1]); offset = LittleLong(directory[1]);
const maptexture_t *tex = (const maptexture_t *)((const uint8_t *)maptex + offset); const maptexture_t *tex = (const maptexture_t *)((const uint8_t *)maptex + offset);
FDummyTexture *tex0 = static_cast<FDummyTexture *>(TexMan.ByIndex(0)); FTexture *tex0 = TexMan.ByIndex(0);
tex0->SetSize(SAFESHORT(tex->width), SAFESHORT(tex->height)); tex0->SetSize(SAFESHORT(tex->width), SAFESHORT(tex->height));
} }

View file

@ -761,26 +761,6 @@ TArray<uint8_t> FTexture::Get8BitPixels(bool alphatex)
return Pixels; 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;
}
//========================================================================== //==========================================================================
// //
// //

View file

@ -1003,7 +1003,9 @@ void FTextureManager::Init()
FTexture::InitGrayMap(); FTexture::InitGrayMap();
// Texture 0 is a dummy texture used to indicate "no texture" // 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. // some special textures used in the game.
AddTexture(CreateShaderTexture(false, false)); AddTexture(CreateShaderTexture(false, false));
AddTexture(CreateShaderTexture(false, true)); AddTexture(CreateShaderTexture(false, true));

View file

@ -382,7 +382,15 @@ protected:
float shaderspeed = 1.f; float shaderspeed = 1.f;
int shaderindex = 0; 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 // Returns true if GetPixelsBgra includes mipmaps
virtual bool Mipmapped() { return true; } 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. // A texture that can be drawn to.
class DCanvas; class DCanvas;