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.
This commit is contained in:
Unknown W. Brackets 2021-10-23 08:06:55 -07:00
parent 09f0578a64
commit c0054dc6cf
2 changed files with 14 additions and 1 deletions

View File

@ -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");

View File

@ -127,6 +127,8 @@ namespace std {
}
struct ReplacedTexture {
~ReplacedTexture();
inline bool Valid() {
return !levels_.empty();
}
@ -167,7 +169,8 @@ protected:
std::vector<std::vector<uint8_t>> levelData_;
ReplacedTextureAlpha alphaStatus_;
double lastUsed_ = 0.0;
LimitedWaitable * threadWaitable_ = nullptr;
LimitedWaitable *threadWaitable_ = nullptr;
bool cancelPrepare_ = false;
friend TextureReplacer;
friend ReplacedTextureTask;