Browse Source

nviz_cmd: fixed segmentation fault when loading more surfaces

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@46813 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 14 years ago
parent
commit
40418dd54d
2 changed files with 13 additions and 6 deletions
  1. 8 1
      visualization/nviz2/cmd/args.c
  2. 5 5
      visualization/nviz2/cmd/surface.c

+ 8 - 1
visualization/nviz2/cmd/args.c

@@ -690,7 +690,7 @@ int opt_get_num_answers(const struct Option *opt)
 void check_parameters(const struct GParams *params)
 {
     int nelev_map, nelev_const, nelevs;
-    int nmaps, nconsts;
+    int nmaps, nconsts, ncoords;
 
     int nvlines;
 
@@ -779,6 +779,13 @@ void check_parameters(const struct GParams *params)
 	    G_fatal_error(_("Inconsistent number of attributes (<%s/%s> %d: <%s> %d)"),
 			  params->elev_map->key, params->elev_const->key,
 			  nelevs, params->wire_color->key, nconsts);
+                          
+        /* position */
+        ncoords = opt_get_num_answers(params->surface_pos);
+        if (ncoords > 0 && 3 * nelevs != ncoords)
+            G_fatal_error(_("Inconsistent number of attributes (<%s/%s> %d: <%s> %d)"),
+                              params->elev_map->key, params->elev_const->key, nelevs,
+                              params->surface_pos->key, ncoords);
     }
 
     /*

+ 5 - 5
visualization/nviz2/cmd/surface.c

@@ -74,9 +74,9 @@ int load_rasters(const struct GParams *params, nv_data * data)
 	}
 
 	/* set position */
-	x = atof(params->surface_pos->answers[i]);
-	y = atof(params->surface_pos->answers[i+1]);
-	z = atof(params->surface_pos->answers[i+2]);
+	x = atof(params->surface_pos->answers[i*3+0]);
+	y = atof(params->surface_pos->answers[i*3+1]);
+	z = atof(params->surface_pos->answers[i*3+2]);
 
 	GS_set_trans(id, x, y, z);
     }
@@ -229,7 +229,7 @@ void surface_set_draw_mode(const struct GParams *params)
 	}
 
 	/* style */
-	if (strcmp(params->style->answers[i], "wire") == 0) {
+	if (strcmp(style, "wire") == 0) {
 	    draw_mode |= DM_GRID_WIRE;
 	}
 	else {			/* surface */
@@ -237,7 +237,7 @@ void surface_set_draw_mode(const struct GParams *params)
 	}
 
 	/* shading */
-	if (strcmp(params->shade->answers[i], "flat") == 0) {
+	if (strcmp(shade, "flat") == 0) {
 	    draw_mode |= DM_FLAT;
 	}
 	else {			/* gouraud */