diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e5e318..2d43fc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,14 +10,11 @@ The format is based on `Keep a Changelog (http://keepachangelog.com/en/1.0.0/) < * Added a configuration file schema ``FmuImporterConfiguration.schema.json`` for FmuImporter and included it in release package and extended documentation how to use it. ---- - -## [1.2.0] - TBD - ### Fixed * Fixed configuration of boolean parameters via config file -* The importer did not run with an 'autonomous' lifecycle if the time synchronization mode was set to 'unsynchronized' - this is now working as intended. +* The importer did not run with an 'autonomous' lifecycle if the time synchronization mode was set to 'unsynchronized' - this is now working as intended +* Fixed a crash that occurred if an FMU's model description had a unit definition that did not use a base unit --- diff --git a/FmuImporter/FmiBridge/FmiModel/Internal/ModelDescription.cs b/FmuImporter/FmiBridge/FmiModel/Internal/ModelDescription.cs index 0d1e7cd..6f53093 100644 --- a/FmuImporter/FmiBridge/FmiModel/Internal/ModelDescription.cs +++ b/FmuImporter/FmiBridge/FmiModel/Internal/ModelDescription.cs @@ -223,11 +223,15 @@ private void InitUnitMap(Fmi3.fmiModelDescriptionUnitDefinitions input) { var unitDefinition = new UnitDefinition { - Name = fmi3Unit.name, - Offset = fmi3Unit.BaseUnit.offset, - Factor = fmi3Unit.BaseUnit.factor + Name = fmi3Unit.name }; + if (fmi3Unit.BaseUnit != null) + { + unitDefinition.Offset = fmi3Unit.BaseUnit.offset; + unitDefinition.Factor = fmi3Unit.BaseUnit.factor; + } + UnitDefinitions.Add(unitDefinition.Name, unitDefinition); } } @@ -239,15 +243,19 @@ private void InitUnitMap(Fmi2.fmiModelDescriptionUnitDefinitions input) return; } - foreach (var fmi3Unit in input.Unit) + foreach (var fmi2Unit in input.Unit) { var unitDefinition = new UnitDefinition { - Name = fmi3Unit.name, - Offset = fmi3Unit.BaseUnit.offset, - Factor = fmi3Unit.BaseUnit.factor + Name = fmi2Unit.name }; + if (fmi2Unit.BaseUnit != null) + { + unitDefinition.Offset = fmi2Unit.BaseUnit.offset; + unitDefinition.Factor = fmi2Unit.BaseUnit.factor; + } + UnitDefinitions.Add(unitDefinition.Name, unitDefinition); } }