From 707a598e5dd9ab129ec0a2f74d2440df81625dc7 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Sun, 25 Sep 2022 23:04:13 -0400 Subject: [PATCH] Prevent a crash due to the 3d preview dummy board stealing setting ownership --- 3d-viewer/dialogs/panel_preview_3d_model.cpp | 2 +- pcbnew/board.cpp | 4 ++-- pcbnew/board.h | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/3d-viewer/dialogs/panel_preview_3d_model.cpp b/3d-viewer/dialogs/panel_preview_3d_model.cpp index f8f7f1fc7f..83b39a338a 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model.cpp +++ b/3d-viewer/dialogs/panel_preview_3d_model.cpp @@ -54,7 +54,7 @@ PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL( wxWindow* aParent, PCB_BASE_FRAM m_userUnits = aFrame->GetUserUnits(); m_dummyBoard = new BOARD(); - m_dummyBoard->SetProject( &aFrame->Prj() ); + m_dummyBoard->SetProject( &aFrame->Prj(), true ); // This board will only be used to hold a footprint for viewing m_dummyBoard->SetBoardUse( BOARD_USE::FPHOLDER ); diff --git a/pcbnew/board.cpp b/pcbnew/board.cpp index 7f04d09f0f..7f7bf89d9a 100644 --- a/pcbnew/board.cpp +++ b/pcbnew/board.cpp @@ -158,14 +158,14 @@ void BOARD::BuildConnectivity( PROGRESS_REPORTER* aReporter ) } -void BOARD::SetProject( PROJECT* aProject ) +void BOARD::SetProject( PROJECT* aProject, bool aReferenceOnly ) { if( m_project ) ClearProject(); m_project = aProject; - if( aProject ) + if( aProject && !aReferenceOnly ) { PROJECT_FILE& project = aProject->GetProjectFile(); diff --git a/pcbnew/board.h b/pcbnew/board.h index 11ac32d3c3..f3c6e7e033 100644 --- a/pcbnew/board.h +++ b/pcbnew/board.h @@ -445,8 +445,9 @@ public: * Should be called immediately after loading board in order for everything to work. * * @param aProject is a loaded project to link to. + * @param aReferenceOnly avoids taking ownership of settings stored in project if true */ - void SetProject( PROJECT* aProject ); + void SetProject( PROJECT* aProject, bool aReferenceOnly = false ); void ClearProject();