Catch resizes in the camera view.

Avoids a segfault when resizing the window.
This commit is contained in:
Bill Currie 2011-04-16 18:58:05 +09:00
parent 3337dc609f
commit b9d21cbe9a
4 changed files with 35 additions and 8 deletions

View file

@ -23,6 +23,7 @@ extern BOOL timedrawing;
float xa, ya, za; float xa, ya, za;
float move; float move;
int camwidth, camheight;
float *zbuffer; float *zbuffer;
unsigned *imagebuffer; unsigned *imagebuffer;

View file

@ -36,9 +36,11 @@ initWithFrame:
move = 16; move = 16;
size = _bounds.size.width * _bounds.size.height; camwidth = _bounds.size.width ;
zbuffer = malloc (size * 4); camheight = _bounds.size.height;
imagebuffer = malloc (size * 4); size = camwidth * camheight;
zbuffer = malloc (size * sizeof (float));
imagebuffer = malloc (size * sizeof (unsigned));
return self; return self;
} }
@ -422,6 +424,18 @@ drawSolid
r_width = _bounds.size.width; r_width = _bounds.size.width;
r_height = _bounds.size.height; r_height = _bounds.size.height;
if (r_width != camwidth || r_height != camheight) {
int size;
camwidth = r_width;
camheight = r_height;
size = camwidth * camheight;
if (imagebuffer) {
free (zbuffer);
free (imagebuffer);
}
zbuffer = malloc (size * sizeof (float));
imagebuffer = malloc (size * sizeof (unsigned));
}
r_picbuffer = imagebuffer; r_picbuffer = imagebuffer;
r_zbuffer = zbuffer; r_zbuffer = zbuffer;
@ -463,6 +477,18 @@ drawWire
r_width = _bounds.size.width; r_width = _bounds.size.width;
r_height = _bounds.size.height; r_height = _bounds.size.height;
if (r_width != camwidth || r_height != camheight) {
int size;
camwidth = r_width;
camheight = r_height;
size = camwidth * camheight;
if (imagebuffer) {
free (zbuffer);
free (imagebuffer);
}
zbuffer = malloc (size * sizeof (float));
imagebuffer = malloc (size * sizeof (unsigned));
}
r_picbuffer = imagebuffer; r_picbuffer = imagebuffer;
r_zbuffer = zbuffer; r_zbuffer = zbuffer;

View file

@ -762,8 +762,8 @@ drawSolid
free (xypicbuffer); free (xypicbuffer);
free (xyzbuffer); free (xyzbuffer);
} }
xypicbuffer = malloc (r_width * (r_height + 1) * 4); xypicbuffer = malloc (r_width * (r_height + 1) * sizeof (unsigned));
xyzbuffer = malloc (r_width * (r_height + 1) * 4); xyzbuffer = malloc (r_width * (r_height + 1) * sizeof (float));
} }
r_picbuffer = xypicbuffer; r_picbuffer = xypicbuffer;

View file

@ -35,10 +35,10 @@ REN_ClearBuffers (void)
{ {
int size; int size;
size = r_width * r_height * 4; size = r_width * r_height;
memset (r_zbuffer, 0, size); memset (r_zbuffer, 0, size * sizeof (float));
memset (r_picbuffer, 0, size); memset (r_picbuffer, 0, size * sizeof (unsigned));
} }
/* /*