Skip to content

Commit

Permalink
Capture weak ref to this in AnimatedVisualPlayer::DestroyAnimations l…
Browse files Browse the repository at this point in the history
…ambda (#7634)
  • Loading branch information
aborziak-ms authored Aug 30, 2022
1 parent 494719e commit ab699e3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions dev/AnimatedVisualPlayer/AnimatedVisualPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,21 +834,28 @@ void AnimatedVisualPlayer::DestroyAnimations() {
// Call RequestCommit to make sure that previous compositor calls complete before destroying animations.
// RequestCommitAsync is available only for RS4+
m_rootVisual.Compositor().RequestCommitAsync().Completed(
[&, createAnimationsCounter = m_createAnimationsCounter](auto, auto) {
[me_weak = get_weak(), createAnimationsCounter = m_createAnimationsCounter](auto, auto) {
auto me = me_weak.get();

if (!me)
{
return;
}

// Check if there was any CreateAnimations call after DestroyAnimations.
// We should not destroy animations in this case,
// they will be destroyed by the following DestroyAnimations call.
if (createAnimationsCounter != m_createAnimationsCounter) {
if (createAnimationsCounter != me->m_createAnimationsCounter) {
return;
}

// Check if current animated visual supports destroyig animations.
if (const auto& animatedVisual = m_animatedVisual.get())
if (const auto& animatedVisual = me->m_animatedVisual.get())
{
if (const auto& animatedVisual2 = animatedVisual.try_as<winrt::IAnimatedVisual2>())
{
animatedVisual2.DestroyAnimations();
m_isAnimationsCreated = false;
me->m_isAnimationsCreated = false;
}
}
}
Expand Down

0 comments on commit ab699e3

Please sign in to comment.