Cleanup 3D caches before d'tors run.

Fixes https://gitlab.com/kicad/code/kicad/issues/10973
This commit is contained in:
Jeff Young 2022-12-05 22:36:44 +00:00
parent 6f43915b25
commit c771d866f5
4 changed files with 35 additions and 13 deletions

View File

@ -3,6 +3,7 @@
*
* Copyright (C) 2015-2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2018-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2022 CERN
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -194,19 +195,6 @@ S3D_CACHE::S3D_CACHE()
S3D_CACHE::~S3D_CACHE()
{
FlushCache();
// We'll delete ".3dc" cache files older than this many days
int clearCacheInterval = 0;
if( Pgm().GetCommonSettings() )
clearCacheInterval = Pgm().GetCommonSettings()->m_System.clear_3d_cache_interval;
// An interval of zero means the user doesn't want to ever clear the cache
if( clearCacheInterval > 0 )
CleanCacheDir( clearCacheInterval );
delete m_FNResolver;
delete m_Plugins;
}
@ -710,6 +698,29 @@ void S3D_CACHE::CleanCacheDir( int aNumDaysOld )
}
void PROJECT::Cleanup3DCache()
{
std::lock_guard<std::mutex> lock( mutex3D_cacheManager );
// Get the existing cache from the project
S3D_CACHE* cache = dynamic_cast<S3D_CACHE*>( GetElem( ELEM_3DCACHE ) );
if( cache )
{
// We'll delete ".3dc" cache files older than this many days
int clearCacheInterval = 0;
if( Pgm().GetCommonSettings() )
clearCacheInterval = Pgm().GetCommonSettings()->m_System.clear_3d_cache_interval;
// An interval of zero means the user doesn't want to ever clear the cache
if( clearCacheInterval > 0 )
cache->CleanCacheDir( clearCacheInterval );
}
}
S3D_CACHE* PROJECT::Get3DCacheManager( bool aUpdateProjDir )
{
std::lock_guard<std::mutex> lock( mutex3D_cacheManager );

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2022 CERN
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -281,6 +282,8 @@ public:
*/
S3D_CACHE* Get3DCacheManager( bool updateProjDir = false );
void Cleanup3DCache();
/// Accessor for 3D path resolver
FILENAME_RESOLVER* Get3DFilenameResolver();
#endif

View File

@ -36,6 +36,9 @@ public:
m_userUnits( aUnits )
{}
virtual ~UNITS_PROVIDER()
{}
EDA_UNITS GetUserUnits() const { return m_userUnits; }
void SetUserUnits( EDA_UNITS aUnits ) { m_userUnits = aUnits; }

View File

@ -5,6 +5,7 @@
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2022 CERN
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -104,6 +105,10 @@ bool PCB_BASE_FRAME::canCloseWindow( wxCloseEvent& aEvent )
if( viewer3D )
viewer3D->Close( true );
// Similarly, wxConvBrokenFileNames uses some statically allocated variables that make it
// crash when run later from a d'tor.
Prj().Cleanup3DCache();
return true;
}