fix many crashes when out of memory
This commit is contained in:
parent
8ec0f41fb1
commit
3c78cce7a5
@ -2279,6 +2279,8 @@ void menu_ui(pixel *vid_buf, int i, int *sl, int *sr)
|
||||
{
|
||||
int b=1,bq,mx,my,h,x,y,n=0,height,width,sy,rows=0;
|
||||
pixel *old_vid=(pixel *)calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
|
||||
if (!old_vid)
|
||||
return;
|
||||
fillrect(vid_buf, -1, -1, XRES+1, YRES+MENUSIZE, 0, 0, 0, 192);
|
||||
memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
|
||||
|
||||
@ -3306,6 +3308,8 @@ int search_ui(pixel *vid_buf)
|
||||
void *thumb, *data;
|
||||
int thlen, dlen;
|
||||
|
||||
if (!v_buf)
|
||||
return 0;
|
||||
memset(v_buf, 0, ((YRES+MENUSIZE)*(XRES+BARSIZE))*PIXELSIZE);
|
||||
|
||||
memset(img_http, 0, sizeof(img_http));
|
||||
@ -4102,6 +4106,8 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date)
|
||||
ui_copytext ctb;
|
||||
|
||||
pixel *old_vid=(pixel *)calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
|
||||
if (!old_vid || !info)
|
||||
return 0;
|
||||
fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
|
||||
viewcountbuffer[0] = 0;
|
||||
|
||||
@ -5448,6 +5454,8 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) {
|
||||
ed.multiline = 0;
|
||||
ed.cursor = 0;
|
||||
//fillrect(vid_buf, -1, -1, XRES, 220, 0, 0, 0, 190);
|
||||
if (!old_buf)
|
||||
return NULL;
|
||||
memcpy(old_buf,vid_buf,(XRES+BARSIZE)*YRES*PIXELSIZE);
|
||||
|
||||
fillrect(old_buf, -1, -1, XRES+BARSIZE, 220, 0, 0, 0, 190);
|
||||
@ -5663,6 +5671,8 @@ unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int saved
|
||||
box_B.cursor = 0;
|
||||
|
||||
|
||||
if (!old_buf)
|
||||
return PIXRGB(currR,currG,currB);
|
||||
memcpy(old_buf,vid_buf,(XRES+BARSIZE)*YRES*PIXELSIZE);
|
||||
while (!sdl_poll())
|
||||
{
|
||||
@ -6423,6 +6433,8 @@ void catalogue_ui(pixel * vid_buf)
|
||||
ui_edit ed;
|
||||
|
||||
vid_buf2 = calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
|
||||
if (!vid_buf2)
|
||||
return;
|
||||
|
||||
ed.w = xsize-16-4;
|
||||
ed.x = x0+11;
|
||||
@ -6811,6 +6823,8 @@ void render_ui(pixel * vid_buf, int xcoord, int ycoord, int orientation)
|
||||
part_vbuf = calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); //Extra video buffer
|
||||
part_vbuf_store = part_vbuf;
|
||||
|
||||
if (!o_vid_buf || !part_vbuf || !part_vbuf_store)
|
||||
return;
|
||||
while (!sdl_poll())
|
||||
{
|
||||
b = mouse_get_state(&mx, &my);
|
||||
|
@ -1648,7 +1648,7 @@ int main(int argc, char *argv[])
|
||||
dump_frame(vid_buf, XRES, YRES, XRES+BARSIZE);
|
||||
if (sdl_key=='v'&&(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)))
|
||||
{
|
||||
if (clipboard_ready==1)
|
||||
if (clipboard_ready==1 && clipboard_data)
|
||||
{
|
||||
load_data = malloc(clipboard_length);
|
||||
memcpy(load_data, clipboard_data, clipboard_length);
|
||||
@ -2185,6 +2185,7 @@ int main(int argc, char *argv[])
|
||||
if (copy_mode==1)//CTRL-C, copy
|
||||
{
|
||||
clipboard_data=build_save(&clipboard_length, save_x, save_y, save_w, save_h, bmap, vx, vy, pv, fvx, fvy, signs, parts);
|
||||
if (clipboard_data)
|
||||
clipboard_ready = 1;
|
||||
save_mode = 0;
|
||||
copy_mode = 0;
|
||||
@ -2192,10 +2193,13 @@ int main(int argc, char *argv[])
|
||||
else if (copy_mode==2)//CTRL-X, cut
|
||||
{
|
||||
clipboard_data=build_save(&clipboard_length, save_x, save_y, save_w, save_h, bmap, vx, vy, pv, fvx, fvy, signs, parts);
|
||||
if (clipboard_data)
|
||||
{
|
||||
clipboard_ready = 1;
|
||||
clear_area(save_x, save_y, save_w, save_h);
|
||||
}
|
||||
save_mode = 0;
|
||||
copy_mode = 0;
|
||||
clear_area(save_x, save_y, save_w, save_h);
|
||||
}
|
||||
else//normal save
|
||||
{
|
||||
|
38
src/save.c
38
src/save.c
@ -494,6 +494,12 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h
|
||||
wallDataLen = blockW*blockH;
|
||||
fanData = malloc((blockW*blockH)*2);
|
||||
fanDataLen = 0;
|
||||
if (!wallData || !fanData)
|
||||
{
|
||||
puts("Save Error, out of memory\n");
|
||||
outputData = NULL;
|
||||
goto fin;
|
||||
}
|
||||
for(x = blockX; x < blockX+blockW; x++)
|
||||
{
|
||||
for(y = blockY; y < blockY+blockH; y++)
|
||||
@ -534,6 +540,12 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h
|
||||
partsPosLastMap = calloc(fullW*fullH, sizeof(unsigned));
|
||||
partsPosCount = calloc(fullW*fullH, sizeof(unsigned));
|
||||
partsPosLink = calloc(NPART, sizeof(unsigned));
|
||||
if (!partsPosFirstMap || !partsPosLastMap || !partsPosCount || !partsPosLink)
|
||||
{
|
||||
puts("Save Error, out of memory\n");
|
||||
outputData = NULL;
|
||||
goto fin;
|
||||
}
|
||||
for(i = 0; i < NPART; i++)
|
||||
{
|
||||
if(partsptr[i].type)
|
||||
@ -565,6 +577,12 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h
|
||||
//Store number of particles in each position
|
||||
partsPosData = malloc(fullW*fullH*3);
|
||||
partsPosDataLen = 0;
|
||||
if (!partsPosData)
|
||||
{
|
||||
puts("Save Error, out of memory\n");
|
||||
outputData = NULL;
|
||||
goto fin;
|
||||
}
|
||||
for (y=0;y<fullH;y++)
|
||||
{
|
||||
for (x=0;x<fullW;x++)
|
||||
@ -586,6 +604,12 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h
|
||||
partsDataLen = 0;
|
||||
partsSaveIndex = calloc(NPART, sizeof(unsigned));
|
||||
partsCount = 0;
|
||||
if (!partsData || !partsSaveIndex)
|
||||
{
|
||||
puts("Save Error, out of memory\n");
|
||||
outputData = NULL;
|
||||
goto fin;
|
||||
}
|
||||
for (y=0;y<fullH;y++)
|
||||
{
|
||||
for (x=0;x<fullW;x++)
|
||||
@ -726,6 +750,12 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h
|
||||
|
||||
soapLinkData = malloc(3*elementCount[PT_SOAP]);
|
||||
soapLinkDataLen = 0;
|
||||
if (!soapLinkData)
|
||||
{
|
||||
puts("Save Error, out of memory\n");
|
||||
outputData = NULL;
|
||||
goto fin;
|
||||
}
|
||||
//Iterate through particles in the same order that they were saved
|
||||
for (y=0;y<fullH;y++)
|
||||
{
|
||||
@ -822,7 +852,13 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h
|
||||
finalData = bson_data(&b);
|
||||
finalDataLen = bson_size(&b);
|
||||
outputDataLen = finalDataLen*2+12;
|
||||
outputData = malloc(outputDataLen);
|
||||
outputData = (unsigned char*)malloc(outputDataLen);
|
||||
if (!outputData)
|
||||
{
|
||||
puts("Save Error, out of memory\n");
|
||||
outputData = NULL;
|
||||
goto fin;
|
||||
}
|
||||
|
||||
outputData[0] = 'O';
|
||||
outputData[1] = 'P';
|
||||
|
Loading…
Reference in New Issue
Block a user