Skip to content

Commit

Permalink
Fix crash when changing sprite atlas and sprite has an invalid animat…
Browse files Browse the repository at this point in the history
…ion (#7550)

* fix crash when new atlas has more animations that the old one but without animation with the same name

* restore ancidently removed line
  • Loading branch information
AGulev authored and Jhonnyg committed Apr 14, 2023
1 parent b8d9c31 commit d8ab687
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion engine/gamesys/src/gamesys/components/comp_sprite.cpp
Expand Up @@ -1400,7 +1400,8 @@ namespace dmGameSystem
// Since the animation referred to the old texture, we need to update it
if (res == dmGameObject::PROPERTY_RESULT_OK)
{
uint32_t* anim_id = GetTextureSet(component, component->m_Resource)->m_AnimationIds.Get(component->m_CurrentAnimation);
TextureSetResource* texture_set = GetTextureSet(component, component->m_Resource);
uint32_t* anim_id = texture_set->m_AnimationIds.Get(component->m_CurrentAnimation);
if (anim_id)
{
PlayAnimation(component, component->m_CurrentAnimation, GetCursor(component), component->m_PlaybackRate);
Expand All @@ -1410,6 +1411,10 @@ namespace dmGameSystem
component->m_Playing = 0;
component->m_CurrentAnimation = 0x0;
component->m_CurrentAnimationFrame = 0;
dmGameSystemDDF::TextureSet* texture_set_ddf = texture_set->m_TextureSet;
if (texture_set_ddf->m_Animations.m_Count <= component->m_AnimationID) {
component->m_AnimationID = 0;
}
}
}
return res;
Expand Down

0 comments on commit d8ab687

Please sign in to comment.