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.
This commit is contained in:
Emmanuel BENOîT 2017-11-27 07:12:04 +01:00
parent 8ec79f591d
commit 4992f7bccb

View file

@ -217,8 +217,11 @@ struct T_SyncViewImpl_
POINT_VALUE , POINT_VALUE ,
}; };
// Make sure all displayed curves/inputs/overrides still exist // Make sure all displayed inputs/overrides still exist
void checkSelectedCurves( ) noexcept; void checkTracks( ) noexcept;
// Make sure the currently selected track/segment/point is still valid
void checkSelection( ) noexcept;
// Display the toolbar
void displayToolbar( ) noexcept; void displayToolbar( ) noexcept;
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -340,17 +343,38 @@ bool T_SyncViewImpl_::display( ) noexcept
return false; return false;
} }
checkSelectedCurves( ); checkTracks( );
checkSelection( );
displayToolbar( ); displayToolbar( );
//---------------------------------------------------------------------- // Sequencer widget
// Sequencer widget & subwindows
PushItemWidth( -1 ); PushItemWidth( -1 );
sequencerWidget( ); sequencerWidget( );
PopItemWidth( ); PopItemWidth( );
End( ); 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 ) { switch ( sub ) {
case SW_NONE: case SW_NONE:
break; break;
@ -376,7 +400,7 @@ bool T_SyncViewImpl_::display( ) noexcept
return true; return true;
} }
void T_SyncViewImpl_::checkSelectedCurves( ) noexcept void T_SyncViewImpl_::checkTracks( ) noexcept
{ {
auto& sync{ Common::Sync( ) }; 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 void T_SyncViewImpl_::displayToolbar( ) noexcept
{ {
using namespace ImGui; using namespace ImGui;