Bug fix, provided by Martin Dickopp;

The dynamical allocated arrays (rwenzlaff, april 03) for render vertices/
faces/halos were freed in a way that requires the last element of array to
be NULL.
This wasn't coded however, causing memory errors in exceptional cases;
like when amount of faces/vertices is exact between 261888 and 262144. :)
This commit is contained in:
Ton Roosendaal 2005-03-04 22:17:52 +00:00
parent 512aabd68e
commit c8a84be5f4
2 changed files with 23 additions and 20 deletions

@ -85,13 +85,13 @@ VertRen *RE_findOrAddVert(int nr)
} }
a= nr>>8; a= nr>>8;
if (a>=rblovelen){ /* Need to allocate more columns...*/ if (a>=rblovelen-1){ /* Need to allocate more columns..., and keep last element NULL for free loop */
// printf("Allocating %i more vert groups. %i total.\n", //printf("Allocating %i more vert groups. %i total.\n",
// TABLEINITSIZE, rblovelen+TABLEINITSIZE ); // TABLEINITSIZE, rblovelen+TABLEINITSIZE );
temp=R.blove; temp=R.blove;
R.blove=(VertRen**)MEM_callocN(sizeof(void*)*(rblovelen+TABLEINITSIZE) , "Blove"); R.blove=(VertRen**)MEM_callocN(sizeof(void*)*(rblovelen+TABLEINITSIZE) , "Blove");
memcpy(R.blove, temp, rblovelen*sizeof(void*)); memcpy(R.blove, temp, rblovelen*sizeof(void*));
memset(&(R.blove[a]), 0, TABLEINITSIZE*sizeof(void*)); memset(&(R.blove[rblovelen]), 0, TABLEINITSIZE*sizeof(void*));
rblovelen+=TABLEINITSIZE; rblovelen+=TABLEINITSIZE;
MEM_freeN(temp); MEM_freeN(temp);
} }
@ -118,13 +118,13 @@ HaloRen *RE_findOrAddHalo(int nr)
} }
a= nr>>8; a= nr>>8;
if (a>=rblohalen){ /* Need to allocate more columns...*/ if (a>=rblohalen-1){ /* Need to allocate more columns..., and keep last element NULL for free loop */
//printf("Allocating %i more halo groups. %i total.\n", //printf("Allocating %i more halo groups. %i total.\n",
// TABLEINITSIZE, rblohalen+TABLEINITSIZE ); // TABLEINITSIZE, rblohalen+TABLEINITSIZE );
temp=R.bloha; temp=R.bloha;
R.bloha=(HaloRen**)MEM_callocN(sizeof(void*)*(rblohalen+TABLEINITSIZE) , "Blove"); R.bloha=(HaloRen**)MEM_callocN(sizeof(void*)*(rblohalen+TABLEINITSIZE) , "Bloha");
memcpy(R.bloha, temp, rblohalen*sizeof(void*)); memcpy(R.bloha, temp, rblohalen*sizeof(void*));
memset(&(R.bloha[a]), 0, TABLEINITSIZE*sizeof(void*)); memset(&(R.bloha[rblohalen]), 0, TABLEINITSIZE*sizeof(void*));
rblohalen+=TABLEINITSIZE; /*Does this really need to be power of 2?*/ rblohalen+=TABLEINITSIZE; /*Does this really need to be power of 2?*/
MEM_freeN(temp); MEM_freeN(temp);
} }
@ -152,13 +152,13 @@ VlakRen *RE_findOrAddVlak(int nr)
} }
a= nr>>8; a= nr>>8;
if (a>=rblovllen){ /* Need to allocate more columns...*/ if (a>=rblovllen-1){ /* Need to allocate more columns..., and keep last element NULL for free loop */
// printf("Allocating %i more face groups. %i total.\n", // printf("Allocating %i more face groups. %i total.\n",
// TABLEINITSIZE, rblovllen+TABLEINITSIZE ); // TABLEINITSIZE, rblovllen+TABLEINITSIZE );
temp=R.blovl; temp=R.blovl;
R.blovl=(VlakRen**)MEM_callocN(sizeof(void*)*(rblovllen+TABLEINITSIZE) , "Blove"); R.blovl=(VlakRen**)MEM_callocN(sizeof(void*)*(rblovllen+TABLEINITSIZE) , "Blovl");
memcpy(R.blovl, temp, rblovllen*sizeof(void*)); memcpy(R.blovl, temp, rblovllen*sizeof(void*));
memset(&(R.blovl[a]), 0, TABLEINITSIZE*sizeof(void*)); memset(&(R.blovl[rblovllen]), 0, TABLEINITSIZE*sizeof(void*));
rblovllen+=TABLEINITSIZE; /*Does this really need to be power of 2?*/ rblovllen+=TABLEINITSIZE; /*Does this really need to be power of 2?*/
MEM_freeN(temp); MEM_freeN(temp);
} }

@ -961,6 +961,14 @@ static void render_particle_system(Object *ob, PartEff *paf)
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
/* when objects are duplicated, they are freed immediate, but still might be
in use for render... */
static Object *vlr_set_ob(Object *ob)
{
if(ob->flag & OB_FROMDUPLI) return (Object *)ob->id.newid;
return ob;
}
static void render_static_particle_system(Object *ob, PartEff *paf) static void render_static_particle_system(Object *ob, PartEff *paf)
{ {
Particle *pa=0; Particle *pa=0;
@ -1175,14 +1183,6 @@ static Material *give_render_material(Object *ob, int nr)
return ma; return ma;
} }
/* when objects are duplicated, they are freed immediate, but still might be
in use for render... */
static Object *vlr_set_ob(Object *ob)
{
if(ob->flag & OB_FROMDUPLI) return (Object *)ob->newid;
return ob;
}
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
static void init_render_mball(Object *ob) static void init_render_mball(Object *ob)
{ {
@ -2703,22 +2703,25 @@ void RE_freeRotateBlenderScene(void)
if(R.la[a]->jitter) MEM_freeN(R.la[a]->jitter); if(R.la[a]->jitter) MEM_freeN(R.la[a]->jitter);
MEM_freeN(R.la[a]); MEM_freeN(R.la[a]);
} }
/* note; these pointer arrays were allocated, with last element NULL to stop loop */
a=0; a=0;
while(R.blove[a]) { while(R.blove[a]) {
MEM_freeN(R.blove[a]); MEM_freeN(R.blove[a]);
R.blove[a]=0; R.blove[a]= NULL;
a++; a++;
} }
a=0; a=0;
while(R.blovl[a]) { while(R.blovl[a]) {
MEM_freeN(R.blovl[a]); MEM_freeN(R.blovl[a]);
R.blovl[a]=0; R.blovl[a]= NULL;
a++; a++;
} }
a=0; a=0;
while(R.bloha[a]) { while(R.bloha[a]) {
MEM_freeN(R.bloha[a]); MEM_freeN(R.bloha[a]);
R.bloha[a]=0; R.bloha[a]= NULL;
a++; a++;
} }