*/}}
Browse Source

Fix totv crash from mesh merging

YimingWu 1 year ago
parent
commit
39e913f6d4
2 changed files with 2 additions and 1 deletions
  1. 1 0
      la_tns_mesh.c
  2. 1 1
      resources/la_properties.c

+ 1 - 0
la_tns_mesh.c

@@ -101,6 +101,7 @@ int tnsMergeMeshObjects(tnsMeshObject* into, tnsMeshObject* mo){
     for(int i=0;i<mo->tote;i++){ mo->e[i].l+=into->totv; mo->e[i].r+=into->totv; }
     for(int i=0;i<mo->totf;i++){ for(int l=0;l<mo->f[i].looplen;l++){ mo->f[i].loop[l]+=into->totv; } }
     int origv=into->totv, orige=into->tote, origf=into->totf;
+    into->maxv=into->totv; into->maxe=into->tote; into->maxf=into->totf;
     into->totv+=mo->totv; into->tote+=mo->tote; into->totf+=mo->totf;
     arrEnsureLength(&into->v, into->totv, &into->maxv, sizeof(tnsVert)); if(mo->totv) memcpy(&into->v[origv],mo->v,sizeof(tnsVert)*mo->totv);
     arrEnsureLength(&into->e, into->tote, &into->maxe, sizeof(tnsEdge)); if(mo->tote) memcpy(&into->e[orige],mo->e,sizeof(tnsEdge)*mo->tote);

+ 1 - 1
resources/la_properties.c

@@ -797,7 +797,7 @@ void tnsset_MeshObjectFaceRaw(tnsMeshObject* o, int* data, int s){
         for(int fi=0;fi<o->maxf;fi++){ // ??? due to undo property order, maxf can be != totf, will it have problems?
             if(o->f[fi].loop){ free(o->f[fi].loop); o->f[fi].loop=0; }
         }
-        arrFree(&o->f, &o->maxf); o->totf=0; 
+        arrFree(&o->f, &o->maxf); o->totf=0; o->maxf=0;
     }
     if(!data) return;
     int totf=data[0]; int i=1;