From df62a4139706b8bac38d104e3c5452439834fda2 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 30 Apr 2019 07:39:24 +0200 Subject: [PATCH] #4380 Preferences : Changing scene font size when geo mech view is open causes crash Guard access to annotationCollection, as this is nullptr for geo mech views. --- .../Application/RiaApplication.cpp | 2 +- .../ProjectDataModel/RimGridView.cpp | 27 ++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/ApplicationCode/Application/RiaApplication.cpp b/ApplicationCode/Application/RiaApplication.cpp index 0c36717e0e..9f994bef10 100644 --- a/ApplicationCode/Application/RiaApplication.cpp +++ b/ApplicationCode/Application/RiaApplication.cpp @@ -2031,7 +2031,7 @@ void RiaApplication::applyPreferences(const RiaPreferences* oldPreferences) } RimGridView* gridView = dynamic_cast(rim3dView); - if (gridView) + if (gridView && gridView->annotationCollection()) { RiaFontCache::FontSize oldFontSize = oldPreferences->defaultAnnotationFontSize(); existingObjectsWithCustomFonts = gridView->annotationCollection()->hasTextAnnotationsWithCustomFontSize(oldFontSize); diff --git a/ApplicationCode/ProjectDataModel/RimGridView.cpp b/ApplicationCode/ProjectDataModel/RimGridView.cpp index e52d2399a2..8d860691f1 100644 --- a/ApplicationCode/ProjectDataModel/RimGridView.cpp +++ b/ApplicationCode/ProjectDataModel/RimGridView.cpp @@ -295,9 +295,12 @@ bool RimGridView::hasCustomFontSizes(RiaDefines::FontSettingType fontSettingType bool hasCustomFonts = Rim3dView::hasCustomFontSizes(fontSettingType, defaultFontSize); if (fontSettingType == RiaDefines::ANNOTATION_FONT) { - auto annotations = annotationCollection(); - RiaFontCache::FontSize defaultFontSizeEnum = RiaFontCache::fontSizeEnumFromPointSize(defaultFontSize); - hasCustomFonts = annotations->hasTextAnnotationsWithCustomFontSize(defaultFontSizeEnum) || hasCustomFonts; + auto annotations = annotationCollection(); + if (annotations) + { + RiaFontCache::FontSize defaultFontSizeEnum = RiaFontCache::fontSizeEnumFromPointSize(defaultFontSize); + hasCustomFonts = annotations->hasTextAnnotationsWithCustomFontSize(defaultFontSizeEnum) || hasCustomFonts; + } } return hasCustomFonts; } @@ -313,14 +316,18 @@ bool RimGridView::applyFontSize(RiaDefines::FontSettingType fontSettingType, bool anyChange = Rim3dView::applyFontSize(fontSettingType, oldFontSize, fontSize, forceChange); if (fontSettingType == RiaDefines::ANNOTATION_FONT) { - auto annotations = annotationCollection(); - RiaFontCache::FontSize oldFontSizeEnum = RiaFontCache::fontSizeEnumFromPointSize(oldFontSize); - RiaFontCache::FontSize newFontSizeEnum = RiaFontCache::fontSizeEnumFromPointSize(fontSize); - bool applyFontSizes = forceChange || !annotations->hasTextAnnotationsWithCustomFontSize(oldFontSizeEnum); - - if (applyFontSizes) + auto annotations = annotationCollection(); + if (annotations) { - anyChange = annotations->applyFontSizeToAllTextAnnotations(oldFontSizeEnum, newFontSizeEnum, forceChange) || anyChange; + RiaFontCache::FontSize oldFontSizeEnum = RiaFontCache::fontSizeEnumFromPointSize(oldFontSize); + RiaFontCache::FontSize newFontSizeEnum = RiaFontCache::fontSizeEnumFromPointSize(fontSize); + bool applyFontSizes = forceChange || !annotations->hasTextAnnotationsWithCustomFontSize(oldFontSizeEnum); + + if (applyFontSizes) + { + anyChange = + annotations->applyFontSizeToAllTextAnnotations(oldFontSizeEnum, newFontSizeEnum, forceChange) || anyChange; + } } } return anyChange;