Skip to content

Commit 6e7a707

Browse files
committed
[SUTK] Fix for segfault when the last tab is destroyed, added more comments on onStepAll() method in AnimationGroup
1 parent f027a2f commit 6e7a707

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

sutk/include/sutk/AnimationEngine.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ namespace SUTK
5656
// Called when all the animations in this group have ended
5757
virtual void onWhenAllEnd() noexcept { }
5858
// Called after when onStep() is invoked over all animations in this group
59+
// NOTE: It is called even if the last stepped animation is ended resulting in zero animation count.
60+
// So, if you're destroy some objects in onEnd() of an Animation then make sure to check of nulls.
5961
virtual void onStepAll() noexcept { }
6062
};
6163
class AnimContextBase : public UIDriverObject

sutk/source/NotebookView.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,10 @@ namespace SUTK
358358
void TabAnimGroup::onStepAll() noexcept
359359
{
360360
auto* tabBar = m_notebook->getTabBar();
361-
tabBar->scrollToTab(tabBar->getSelectedTab());
361+
// onStepAll() is called even for the last (only one is left) stepped animation and that animation might destroy the only tab left in the TabBar
362+
// Causing tabBar->getSelectedTab() to return nullptr, so we need to check for null here.
363+
if(tabBar->getSelectedTab())
364+
tabBar->scrollToTab(tabBar->getSelectedTab());
362365
}
363366
TabAnimGroup::TabAnimGroup(UIDriver& driver, NotebookView* notebook) noexcept : AnimGroup(driver), m_notebook(notebook)
364367
{

0 commit comments

Comments
 (0)