From 757c33ea13d97bfd6f9d8740d9d661ea3fbea983 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 27 Oct 2022 14:25:41 +0100 Subject: [PATCH] Fix MRU logic errors. The most serious was that we were keeping a reference to a string which changed out from under the reference when it was deleted from the wxArrayString. Fixes https://gitlab.com/kicad/code/kicad/issues/12770 --- 3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp b/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp index a5ec182e4b..42b6082a2e 100644 --- a/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp +++ b/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp @@ -486,6 +486,12 @@ void EDA_3D_VIEWER_FRAME::applyViewport( const wxString& aViewportName ) m_canvas->Request_refresh(); else m_canvas->RenderRaytracingRequest(); + + if( !m_lastSelectedViewport->name.IsEmpty() ) + { + m_viewportMRU.Remove( m_lastSelectedViewport->name ); + m_viewportMRU.Insert( m_lastSelectedViewport->name, 0 ); + } } else { @@ -500,19 +506,13 @@ void EDA_3D_VIEWER_FRAME::onViewportChanged( wxCommandEvent& aEvent ) int count = m_cbViewports->GetCount(); int index = m_cbViewports->GetSelection(); - if( index >= 0 && index < count - 3 ) + if( index >= 0 && index < count - 3 /* separator */ ) { VIEWPORT3D* viewport = static_cast( m_cbViewports->GetClientData( index ) ); wxCHECK( viewport, /* void */ ); applyViewport( viewport->name ); - - if( !viewport->name.IsEmpty() ) - { - m_viewportMRU.Remove( viewport->name ); - m_viewportMRU.Insert( viewport->name, 0 ); - } } else if( index == count - 2 ) {