Skip to content

Commit

Permalink
fix crash while resource release without context
Browse files Browse the repository at this point in the history
  • Loading branch information
Hparty committed Nov 30, 2023
1 parent 44ea2d5 commit ef84e42
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/rendering/CompositionReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ CompositionReader::CompositionReader(std::shared_ptr<BitmapDrawable> bitmapDrawa
}

CompositionReader::~CompositionReader() {
auto result = drawable->lockDevice();
delete pagPlayer;
if (result) {
drawable->unlockDevice();
}
}

std::shared_ptr<PAGComposition> CompositionReader::getComposition() {
Expand Down
8 changes: 8 additions & 0 deletions src/rendering/drawables/BitmapDrawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ void BitmapDrawable::setBitmap(std::shared_ptr<BitmapBuffer> buffer) {
freeSurface();
}

bool BitmapDrawable::lockDevice() {
return device->lockContext() != nullptr;
}

void BitmapDrawable::unlockDevice() {
device->unlock();
}

void BitmapDrawable::present(tgfx::Context* context) {
if (bitmap == nullptr) {
return;
Expand Down
4 changes: 4 additions & 0 deletions src/rendering/drawables/BitmapDrawable.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class BitmapDrawable : public Drawable {
return pixelCopied;
}

bool lockDevice();

void unlockDevice();

protected:
std::shared_ptr<tgfx::Device> onCreateDevice() override {
return device;
Expand Down
4 changes: 4 additions & 0 deletions src/rendering/drawables/Drawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ std::shared_ptr<tgfx::Surface> Drawable::getSurface(tgfx::Context* context, bool
}

void Drawable::freeSurface() {
auto context = lockContext(false);
surface = nullptr;
if (context != nullptr) {
device->unlock();
}
}

} // namespace pag

0 comments on commit ef84e42

Please sign in to comment.