From 1d9f8ab438adfb3cab3be38f3aa6a7177eb5b73f Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Thu, 27 Feb 2025 11:20:31 +0100 Subject: [PATCH] custom textures: fix static deinit order issue --- core/rend/CustomTexture.cpp | 14 ++++++++++---- core/rend/CustomTexture.h | 5 ++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/core/rend/CustomTexture.cpp b/core/rend/CustomTexture.cpp index 2df7fbf06..5a999c414 100644 --- a/core/rend/CustomTexture.cpp +++ b/core/rend/CustomTexture.cpp @@ -34,7 +34,6 @@ #include 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("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); }); } diff --git a/core/rend/CustomTexture.h b/core/rend/CustomTexture.h index df28e7692..9e929fa03 100644 --- a/core/rend/CustomTexture.h +++ b/core/rend/CustomTexture.h @@ -20,13 +20,15 @@ #include "texconv.h" #include #include +#include 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 texture_map; + std::unique_ptr loaderThread; }; extern CustomTexture custom_texture;