Fix project directory lock on Windows after project close
On Windows, processes hold a handle to their current working directory, preventing it from being deleted. When LoadProject() sets the CWD to the project directory, that handle persists even after CloseProject() is called. This also causes handle inheritance issues when launching external processes, such as the browser for "Report Bug". Reset the working directory to the user settings path when unloading an active project on GUI applications. This mirrors the wxSetWorkingDirectory call in LoadProject and releases the directory lock. Fixes https://gitlab.com/kicad/code/kicad/-/issues/20577
This commit is contained in:
@@ -1092,6 +1092,14 @@ bool SETTINGS_MANAGER::UnloadProject( PROJECT* aProject, bool aSave )
|
||||
// Remove the reference in the environment to the previous project
|
||||
wxSetEnv( PROJECT_VAR_NAME, wxS( "" ) );
|
||||
|
||||
#ifdef _WIN32
|
||||
// On Windows, processes hold a handle to their current working directory, preventing
|
||||
// it from being deleted. Reset to the user settings path to release the project
|
||||
// directory. This mirrors the wxSetWorkingDirectory call in LoadProject.
|
||||
if( wxTheApp && wxTheApp->IsGUI() )
|
||||
wxSetWorkingDirectory( PATHS::GetUserSettingsPath() );
|
||||
#endif
|
||||
|
||||
if( m_kiway )
|
||||
m_kiway->ProjectChanged();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user