custom textures: fix static deinit order issue

This commit is contained in:
Flyinghead 2025-02-27 11:20:31 +01:00
parent df3c075fba
commit 1d9f8ab438
2 changed files with 14 additions and 5 deletions

View File

@ -34,7 +34,6 @@
#include <stb_image_write.h>
CustomTexture custom_texture;
static WorkerThread loader_thread {"CustomTexLoader"};
void CustomTexture::loadTexture(BaseTextureCacheData *texture)
{
@ -90,7 +89,8 @@ bool CustomTexture::init()
{
NOTICE_LOG(RENDERER, "Found custom textures directory: %s", textures_path.c_str());
custom_textures_available = true;
loader_thread.run([this]() {
loaderThread = std::make_unique<WorkerThread>("CustomTexLoader");
loaderThread->run([this]() {
loadMap();
});
}
@ -102,9 +102,15 @@ bool CustomTexture::init()
return custom_textures_available;
}
CustomTexture::~CustomTexture() {
Terminate();
}
void CustomTexture::Terminate()
{
loader_thread.stop();
if (loaderThread)
loaderThread->stop();
loaderThread.reset();
texture_map.clear();
initialized = false;
}
@ -131,7 +137,7 @@ void CustomTexture::LoadCustomTextureAsync(BaseTextureCacheData *texture_data)
return;
texture_data->custom_load_in_progress++;
loader_thread.run([this, texture_data]() {
loaderThread->run([this, texture_data]() {
loadTexture(texture_data);
});
}

View File

@ -20,13 +20,15 @@
#include "texconv.h"
#include <string>
#include <map>
#include <memory>
class BaseTextureCacheData;
class WorkerThread;
class CustomTexture
{
public:
~CustomTexture() { Terminate(); }
~CustomTexture();
void LoadCustomTextureAsync(BaseTextureCacheData *texture_data);
void DumpTexture(u32 hash, int w, int h, TextureType textype, void *src_buffer);
void Terminate();
@ -42,6 +44,7 @@ private:
bool custom_textures_available = false;
std::string textures_path;
std::map<u32, std::string> texture_map;
std::unique_ptr<WorkerThread> loaderThread;
};
extern CustomTexture custom_texture;