changeset 1357:d532204d76c1 draft

delete malloc.add new
author e095732 <e095732@ie.u-ryukyu.ac.jp>
date Thu, 19 Jan 2012 20:10:29 +0900
parents 58a02f491f51
children db8bba42ad80
files Renderer/Engine/SceneGraphRoot.cc
diffstat 1 files changed, 31 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraphRoot.cc	Thu Jan 19 17:55:16 2012 +0900
+++ b/Renderer/Engine/SceneGraphRoot.cc	Thu Jan 19 20:10:29 2012 +0900
@@ -400,6 +400,7 @@
     char *name;
     char *tex_picname;
     int vcsum;
+    int limit;
 }; 
 
 static texture_list list[TABLE_SIZE];
@@ -478,9 +479,14 @@
     for (int i = 0;i < s->polylist_count;i++){
        s->vcsum += s->vcount[i];
     }
-
-    //s->pcount = (float*)malloc(sizeof(float)*vcsum);
-    s->pcount = new float[s->vcsum];
+    s->limit = s->vcsum * 2;
+    if (s->texcoord_offset == 2){
+        s->limit = s->vcsum * 3;
+    }
+    s->pcount = new float[s->limit];
+    for (int i=0;i<s->limit;i++){
+        s->pcount[i] = 0;
+    }
     for (int i=0; pcont != NULL; i++) {
         pcont = pickup_float(pcont, s->pcount+i);
     }
@@ -488,35 +494,26 @@
 
 SceneGraph*
 decode_points(xmlNodePtr cur, collada_state *s, TaskManager *manager){
-    printf("start decode points\n");
-    int vertexp[s->vcsum];
+    int *vertexp;
+    vertexp = new int[s->vcsum];
+    //int vertexp[s->vcsum];
     for (int i=0;i<s->vcsum;i++){
        vertexp[i]=0;
     }
-    //float *vertex_table;
-    //float *normal_table;
-    //float *texcoord_table;
-
-    float vertex_table[s->vertex_float->count];
-    //vertex_table = new float[s->vertex_float->count];
-    //float *vertex_table = (float*)malloc(sizeof(float)*s->vertex_float->count) ;
+    float *vertex_table;
+    float *normal_table;
+    float *texcoord_table; 
+    vertex_table = new float[s->vcsum];
+    normal_table = new float[s->vcsum];
+    texcoord_table = new float[s->vcsum];
 
-    float normal_table[s->normal_float->count];
-    //normal_table = new float[s->normal_float->count];
-    //float *normal_table = (float*)malloc(sizeof(float)*s->normal_float->count);
-
-    float texcoord_table[s->texcoord_float->count];
-    //texcoord_table = new float[s->texcoord_float->count];
-    //float *texcoord_table = (float*)malloc(sizeof(float)*s->texcoord_float->count) ;
-
-    int limit = s->vcsum * 2;
-    if (s->texcoord_offset == 2){
-        limit = s->vcsum * 3;
-    }
+    /**
+     * s->vcsum と s->vertex_float->countの値が違うので大きい方をとりあえず使っておく
+     */
 
     /* p separate vertex position and nomal position. */
-    for (int i=0,j=0; i < limit; i+=2,j++) {
-        vertexp[j] = s->pcount[i];
+    for (int i=0,j=0; i < s->limit; i+=2,j++) {
+        vertexp[j] = (int)s->pcount[i];
 	normal_table[j] = s->normal_float->u.array[(int)s->pcount[i+1]];
 	if (s->texcoord_offset == 2) {
 	    texcoord_table[j] = s->texcoord_float->u.array[(int)s->pcount[i+2]];
@@ -549,9 +546,9 @@
     
     for (int i = 0;i < sg->pp_num; i++ ){
         PolygonPackPtr pp = sg->pp;
-	    TrianglePackPtr tri =  pp[i].tri;
-	    // TrianglePack の size のチェック
-	    int tri_size = (count < MAX_SIZE_TRIANGLE) ? count : MAX_SIZE_TRIANGLE ;
+	TrianglePackPtr tri =  pp[i].tri;
+	// TrianglePack の size のチェック
+        int tri_size = (count < MAX_SIZE_TRIANGLE) ? count : MAX_SIZE_TRIANGLE ;
 	pp[i].info.size = tri_size;
 	int k = 0;
 	int m = 0;
@@ -595,23 +592,14 @@
     }
     sg->c_xyz[0] = sg->c_xyz[1] = sg->c_xyz[2] = 0;
     
-    /*TEST*/
-    for (int i=0; i<s->vcsum; i++) {
-        printf("vertexp = %d\n", vertexp[i]);
-        //printf("vertex_table= %f\n", s->vertex_table[i]);
-    } 
-
     int tex_id = 0;
     sgid_hash.sg_hash_regist(s->name, tex_id);
     //get_texpic(s->tex_picname, sg, cur , manager);
-    //free(vertexp);
-    //free(vertex_table);
-    //free(normal_table);
-    //free(texcoord_table);
-    
-    //delete []vertex_table;
-    //delete []normal_table;
-    //delete []texcoord_table;
+ 
+    delete []vertexp;
+    delete []vertex_table;
+    delete []normal_table;
+    delete []texcoord_table;
 
     /* got out of polylist */
     s->polylist = 0;