A memory leak a day keeps the doc away

This commit is contained in:
Magnus Norddahl 2025-04-11 23:55:40 +02:00
commit f87bcfd3a2
2 changed files with 5 additions and 4 deletions

View file

@ -42,7 +42,7 @@
#include "palettecontainer.h"
FMemArena ImageArena(32768);
TArray<FImageSource *>FImageSource::ImageForLump;
TArray<std::unique_ptr<FImageSource>>FImageSource::ImageForLump;
int FImageSource::NextID;
static PrecacheInfo precacheInfo;
@ -373,7 +373,7 @@ FImageSource * FImageSource::GetImage(int lumpnum, bool isflat)
for (; size < ImageForLump.Size(); size++) ImageForLump[size] = nullptr;
}
// An image for this lump already exists. We do not need another one.
if (ImageForLump[lumpnum] != nullptr) return ImageForLump[lumpnum];
if (ImageForLump[lumpnum] != nullptr) return ImageForLump[lumpnum].get();
auto data = fileSystem.OpenFileReader(lumpnum);
if (!data.isOpen())
@ -386,7 +386,7 @@ FImageSource * FImageSource::GetImage(int lumpnum, bool isflat)
auto image = CreateInfo[i].TryCreate(data, lumpnum);
if (image != nullptr)
{
ImageForLump[lumpnum] = image;
ImageForLump[lumpnum].reset(image);
return image;
}
}

View file

@ -1,6 +1,7 @@
#pragma once
#include <stdint.h>
#include <memory>
#include "tarray.h"
#include "bitmap.h"
#include "memarena.h"
@ -63,7 +64,7 @@ class FImageSource
friend class FBrightmapTexture;
protected:
static TArray<FImageSource *>ImageForLump;
static TArray<std::unique_ptr<FImageSource>> ImageForLump;
static int NextID;
int SourceLump;