Skip to content

Commit 1261151

Browse files
authored
Fix the deadlock issue caused by PAGAnimator calling nativeRelease (#3251)
1 parent dd74877 commit 1261151

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/platform/android/JPAGAnimator.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,21 @@ class JPAGAnimator {
123123
return animator;
124124
}
125125

126-
void clear() {
127-
std::lock_guard<std::mutex> autoLock(locker);
128-
animator->cancel();
129-
animator = nullptr;
130-
listener = nullptr;
131-
}
126+
void clear() {
127+
std::shared_ptr<pag::PAGAnimator> tempAnimator;
128+
std::shared_ptr<pag::AnimatorListener> tempListener;
129+
{
130+
std::lock_guard<std::mutex> autoLock(locker);
131+
tempAnimator = std::move(animator);
132+
tempListener = std::move(listener);
133+
}
134+
// Call cancel outside the lock to avoid deadlock
135+
if (tempAnimator) {
136+
tempAnimator->cancel();
137+
}
138+
}
132139

133-
private:
140+
private:
134141
std::mutex locker;
135142
std::shared_ptr<pag::AnimatorListener> listener;
136143
std::shared_ptr<pag::PAGAnimator> animator;

0 commit comments

Comments
 (0)