From 835d9f1f3d962fab290c39959b159245a315c984 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sat, 24 Dec 2011 18:22:58 +0000 Subject: [PATCH] Fix crash with clear_sim if gravity not initialised, fix renderer --- src/gravity.c | 22 ++++++++++++---------- src/main.c | 18 +++++++++++++----- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/gravity.c b/src/gravity.c index 7e7b37c2a..5fe13f9e8 100644 --- a/src/gravity.c +++ b/src/gravity.c @@ -10,17 +10,17 @@ #endif -float *gravmap;//Maps to be used by the main thread -float *gravp; -float *gravy; -float *gravx; -unsigned *gravmask; +float *gravmap = NULL;//Maps to be used by the main thread +float *gravp = NULL; +float *gravy = NULL; +float *gravx = NULL; +unsigned *gravmask = NULL; -float *th_ogravmap;// Maps to be processed by the gravity thread -float *th_gravmap; -float *th_gravx; -float *th_gravy; -float *th_gravp; +float *th_ogravmap = NULL;// Maps to be processed by the gravity thread +float *th_gravmap = NULL; +float *th_gravx = NULL; +float *th_gravy = NULL; +float *th_gravp = NULL; int gravwl_timeout = 0; int gravityMode = 0; // starts enabled in "vertical" mode... @@ -454,6 +454,8 @@ void gravity_mask() unsigned maskvalue; mask_el *t_mask_el = NULL; mask_el *c_mask_el = NULL; + if(!gravmask) + return; memset(checkmap, 0, sizeof(checkmap)); for(x = 0; x < XRES/CELL; x++) { diff --git a/src/main.c b/src/main.c index 62fafe764..90bb06599 100644 --- a/src/main.c +++ b/src/main.c @@ -1153,10 +1153,14 @@ void clear_sim(void) memset(fire_r, 0, sizeof(fire_r)); memset(fire_g, 0, sizeof(fire_g)); memset(fire_b, 0, sizeof(fire_b)); - memset(gravmask, 0xFFFFFFFF, (XRES/CELL)*(YRES/CELL)*sizeof(unsigned)); - memset(gravy, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); - memset(gravx, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); - memset(gravp, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); + if(gravmask) + memset(gravmask, 0xFFFFFFFF, (XRES/CELL)*(YRES/CELL)*sizeof(unsigned)); + if(gravy) + memset(gravy, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); + if(gravx) + memset(gravx, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); + if(gravp) + memset(gravp, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); for(x = 0; x < XRES/CELL; x++){ for(y = 0; y < YRES/CELL; y++){ hv[y][x] = 273.15f+22.0f; //Set to room temperature @@ -1470,7 +1474,11 @@ int main(int argc, char *argv[]) pers_bg = calloc((XRES+BARSIZE)*YRES, PIXELSIZE); - prepare_alpha(4, 1.0f); + prepare_alpha(CELL, 1.0f); + prepare_graphicscache(); + flm_data = generate_gradient(flm_data_colours, flm_data_pos, flm_data_points, 200); + plasma_data = generate_gradient(plasma_data_colours, plasma_data_pos, plasma_data_points, 200); + player.elem = player2.elem = PT_DUST; player.frames = player2.frames = 0;