From c0054dc6cf0e1fe7089fd2b3e28b3647a05ccd29 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 23 Oct 2021 08:06:55 -0700 Subject: [PATCH] Replacement: Ensurely orderly stop on reset. If the texture is being loaded and we stop or reset, make sure it stops to avoid any crash or hang. --- Core/TextureReplacer.cpp | 10 ++++++++++ Core/TextureReplacer.h | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Core/TextureReplacer.cpp b/Core/TextureReplacer.cpp index f79ae13730..3c7e0c7ec6 100644 --- a/Core/TextureReplacer.cpp +++ b/Core/TextureReplacer.cpp @@ -781,6 +781,8 @@ public: void Run() override { for (int i = (int)tex_.levelData_.size(); i <= tex_.MaxLevel(); ++i) { + if (tex_.cancelPrepare_) + break; tex_.levelData_.resize(i + 1); tex_.PrepareData(i); } @@ -931,6 +933,14 @@ void ReplacedTexture::PurgeIfOlder(double t) { } } +ReplacedTexture::~ReplacedTexture() { + if (threadWaitable_) { + cancelPrepare_ = true; + threadWaitable_->WaitAndRelease(); + threadWaitable_ = nullptr; + } +} + bool ReplacedTexture::Load(int level, void *out, int rowPitch) { _assert_msg_((size_t)level < levels_.size(), "Invalid miplevel"); _assert_msg_(out != nullptr && rowPitch > 0, "Invalid out/pitch"); diff --git a/Core/TextureReplacer.h b/Core/TextureReplacer.h index 11a0226389..9b9551396c 100644 --- a/Core/TextureReplacer.h +++ b/Core/TextureReplacer.h @@ -127,6 +127,8 @@ namespace std { } struct ReplacedTexture { + ~ReplacedTexture(); + inline bool Valid() { return !levels_.empty(); } @@ -167,7 +169,8 @@ protected: std::vector> levelData_; ReplacedTextureAlpha alphaStatus_; double lastUsed_ = 0.0; - LimitedWaitable * threadWaitable_ = nullptr; + LimitedWaitable *threadWaitable_ = nullptr; + bool cancelPrepare_ = false; friend TextureReplacer; friend ReplacedTextureTask;