Fix crash with no grid unit
authormano-wii <germano.costa@ig.com.br>
Tue, 20 Aug 2019 12:11:32 +0000 (09:11 -0300)
committermano-wii <germano.costa@ig.com.br>
Tue, 20 Aug 2019 12:11:32 +0000 (09:11 -0300)
source/blender/editors/space_view3d/view3d_draw.c

index aa4b92062a30bcbc47705fa81a6b25f2733cbac8..7f6dc66d4a7622f4fb4145cb113c20082c8139bf 100644 (file)
@@ -1420,18 +1420,20 @@ static void draw_grid_unit_name(
     Scene *scene, RegionView3D *rv3d, View3D *v3d, int xoffset, int *yoffset)
 {
   if (!rv3d->is_persp && RV3D_VIEW_IS_AXIS(rv3d->view)) {
-    char numstr[32] = "";
-    const char *grid_unit;
+    const char *grid_unit = NULL;
     ED_view3d_grid_view_scale(scene, v3d, rv3d, &grid_unit);
 
-    UI_FontThemeColor(BLF_default(), TH_TEXT_HI);
-    if (v3d->grid != 1.0f) {
-      BLI_snprintf(numstr, sizeof(numstr), "%s x %.4g", grid_unit, v3d->grid);
-    }
+    if (grid_unit) {
+      char numstr[32] = "";
+      UI_FontThemeColor(BLF_default(), TH_TEXT_HI);
+      if (v3d->grid != 1.0f) {
+        BLI_snprintf(numstr, sizeof(numstr), "%s x %.4g", grid_unit, v3d->grid);
+      }
 
-    *yoffset -= U.widget_unit;
-    BLF_draw_default_ascii(
-        xoffset, *yoffset, 0.0f, numstr[0] ? numstr : grid_unit, sizeof(numstr));
+      *yoffset -= U.widget_unit;
+      BLF_draw_default_ascii(
+          xoffset, *yoffset, 0.0f, numstr[0] ? numstr : grid_unit, sizeof(numstr));
+    }
   }
 }