From 4992f7bccb154c2da3c60e4a9fe4e4eaadf8716d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Mon, 27 Nov 2017 07:12:04 +0100 Subject: [PATCH] Sequencer - Make sure that selection is valid When something is selected, it can become invalid due to e.g. undo or file reload, so we need to NOT CRASH like a turd. --- ui-sequencer.cc | 82 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 75 insertions(+), 7 deletions(-) diff --git a/ui-sequencer.cc b/ui-sequencer.cc index 79cbffc..b2b9711 100644 --- a/ui-sequencer.cc +++ b/ui-sequencer.cc @@ -217,8 +217,11 @@ struct T_SyncViewImpl_ POINT_VALUE , }; - // Make sure all displayed curves/inputs/overrides still exist - void checkSelectedCurves( ) noexcept; + // Make sure all displayed inputs/overrides still exist + void checkTracks( ) noexcept; + // Make sure the currently selected track/segment/point is still valid + void checkSelection( ) noexcept; + // Display the toolbar void displayToolbar( ) noexcept; //---------------------------------------------------------------------- @@ -340,17 +343,38 @@ bool T_SyncViewImpl_::display( ) noexcept return false; } - checkSelectedCurves( ); + checkTracks( ); + checkSelection( ); displayToolbar( ); - //---------------------------------------------------------------------- - // Sequencer widget & subwindows - + // Sequencer widget PushItemWidth( -1 ); sequencerWidget( ); PopItemWidth( ); End( ); + // Close sub-window if e.g. selection has changed + switch( sub ) { + case SW_POINT: + if ( !selPoint ) { + sub = SW_SEGMENT; + } + // fallthrough + case SW_SEGMENT: + if ( !selSegment ) { + sub = SW_TRACK; + } + // fallthrough + case SW_TRACK: + if ( !selId ) { + sub = SW_NONE; + } + break; + + default: break; + } + + // Display selected sub-window switch ( sub ) { case SW_NONE: break; @@ -376,7 +400,7 @@ bool T_SyncViewImpl_::display( ) noexcept return true; } -void T_SyncViewImpl_::checkSelectedCurves( ) noexcept +void T_SyncViewImpl_::checkTracks( ) noexcept { auto& sync{ Common::Sync( ) }; @@ -418,6 +442,50 @@ void T_SyncViewImpl_::checkSelectedCurves( ) noexcept } } +void T_SyncViewImpl_::checkSelection( ) noexcept +{ + if ( !selId ) { + return; + } + assert( !selIsOverride ); // XXX + auto const* const curve{ Common::Sync( ).getCurve( selId ) }; + + // Missing curve + if ( !curve ) { + // Remove segment/point selection + if ( selSegment ) { + selSegment.clear( ); + selPoint.clear( ); + } + // If there's no matching input, unselect the track + if ( !Common::Sync( ).hasInput( selId ) ) { + selId = T_String{}; + } + } else { + // No segment selected? We're ok. + if ( !selSegment ) { + return; + } + + // Check segment and point + if ( *selSegment >= curve->segments.size( ) ) { + selSegment.clear( ); + selPoint.clear( ); + } else if ( selPoint && *selPoint >= curve->segments[ + *selSegment ].values.size( ) ) { + selPoint.clear( ); + } else { + return; + } + } + // If we were doing something with the curve, get rid of that too + if ( selUpdate != E_ChangeType::NONE ) { + selUpdate = E_ChangeType::NONE; + selUpdatingCopy.clear( ); + selUpdatingOriginal.clear( ); + } +} + void T_SyncViewImpl_::displayToolbar( ) noexcept { using namespace ImGui;