Avoid a race in MatModels loading

Add a mutex to ensure an SGMatModels only loads its models once. Caught
be ASan, hurrah.
This commit is contained in:
James Turner 2020-08-14 16:48:51 +01:00
parent b874201806
commit 297e509576
2 changed files with 35 additions and 31 deletions

View File

@ -103,6 +103,8 @@ SGMatModel::get_model_count( SGPropertyNode *prop_root )
inline void inline void
SGMatModel::load_models( SGPropertyNode *prop_root ) SGMatModel::load_models( SGPropertyNode *prop_root )
{ {
std::lock_guard<std::mutex> g(_loadMutex);
// Load model only on demand // Load model only on demand
if (!_models_loaded) { if (!_models_loaded) {
for (unsigned int i = 0; i < _paths.size(); i++) { for (unsigned int i = 0; i < _paths.size(); i++) {

View File

@ -149,6 +149,8 @@ private:
double _spacing_m; double _spacing_m;
double _range_m; double _range_m;
HeadingType _heading_type; HeadingType _heading_type;
std::mutex _loadMutex;
}; };