Skip to content

Commit ab699e3

Browse files
authored
Capture weak ref to this in AnimatedVisualPlayer::DestroyAnimations lambda (#7634)
1 parent 494719e commit ab699e3

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

dev/AnimatedVisualPlayer/AnimatedVisualPlayer.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -834,21 +834,28 @@ void AnimatedVisualPlayer::DestroyAnimations() {
834834
// Call RequestCommit to make sure that previous compositor calls complete before destroying animations.
835835
// RequestCommitAsync is available only for RS4+
836836
m_rootVisual.Compositor().RequestCommitAsync().Completed(
837-
[&, createAnimationsCounter = m_createAnimationsCounter](auto, auto) {
837+
[me_weak = get_weak(), createAnimationsCounter = m_createAnimationsCounter](auto, auto) {
838+
auto me = me_weak.get();
839+
840+
if (!me)
841+
{
842+
return;
843+
}
844+
838845
// Check if there was any CreateAnimations call after DestroyAnimations.
839846
// We should not destroy animations in this case,
840847
// they will be destroyed by the following DestroyAnimations call.
841-
if (createAnimationsCounter != m_createAnimationsCounter) {
848+
if (createAnimationsCounter != me->m_createAnimationsCounter) {
842849
return;
843850
}
844851

845852
// Check if current animated visual supports destroyig animations.
846-
if (const auto& animatedVisual = m_animatedVisual.get())
853+
if (const auto& animatedVisual = me->m_animatedVisual.get())
847854
{
848855
if (const auto& animatedVisual2 = animatedVisual.try_as<winrt::IAnimatedVisual2>())
849856
{
850857
animatedVisual2.DestroyAnimations();
851-
m_isAnimationsCreated = false;
858+
me->m_isAnimationsCreated = false;
852859
}
853860
}
854861
}

0 commit comments

Comments
 (0)