From 52f3f87359726998ad6c74d8cda389e18c47ed2e Mon Sep 17 00:00:00 2001 From: zicodxx Date: Mon, 26 Sep 2011 23:00:24 +0200 Subject: [PATCH] Avoided variable array initializations which some compilers do not like; Also made sure declarations happen first inside (sub)functions; Fixed set but unused variables --- 3d/interp.c | 14 +++++++------- CHANGELOG.txt | 1 + arch/ogl/ogl.c | 51 ++++++++++++++++++++++++++++++++----------------- main/bm.c | 12 +++++++----- main/endlevel.c | 3 ++- 5 files changed, 51 insertions(+), 30 deletions(-) diff --git a/3d/interp.c b/3d/interp.c index 0fe638136..ea7f0f4d5 100644 --- a/3d/interp.c +++ b/3d/interp.c @@ -1,4 +1,3 @@ -/* $Id: interp.c,v 1.1.1.1 2006/03/17 19:52:13 zicodxx Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -18,10 +17,6 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. * */ -#ifdef RCS -static char rcsid[] = "$Id: interp.c,v 1.1.1.1 2006/03/17 19:52:13 zicodxx Exp $"; -#endif - #include #include "error.h" @@ -453,8 +448,9 @@ bool g3_draw_polygon_model(void *model_ptr,grs_bitmap **model_bitmaps,vms_angvec Assert( nv < MAX_POINTS_PER_POLY ); if (g3_check_normal_facing(vp(p+4),vp(p+16)) > 0) { int i; - g3s_lrgb light, lrgb_list[nv]; + g3s_lrgb light, *lrgb_list; + MALLOC(lrgb_list, g3s_lrgb, nv); //calculate light from surface normal if (glow_num < 0) //no glow { @@ -487,6 +483,7 @@ bool g3_draw_polygon_model(void *model_ptr,grs_bitmap **model_bitmaps,vms_angvec point_list[i] = Interp_point_list + wp(p+30)[i]; g3_draw_tmap(nv,point_list,uvl_list,lrgb_list,model_bitmaps[w(p+28)]); + d_free(lrgb_list); } p += 30 + ((nv&~1)+1)*2 + nv*12; @@ -623,10 +620,12 @@ bool g3_draw_morphing_model(void *model_ptr,grs_bitmap **model_bitmaps,vms_angve case OP_TMAPPOLY: { int nv = w(p+2); g3s_uvl *uvl_list; - g3s_lrgb light, lrgb_list[nv]; + g3s_lrgb light, *lrgb_list; g3s_uvl morph_uvls[3]; int i,ntris; + MALLOC(lrgb_list, g3s_lrgb, nv); + //calculate light from surface normal if (glow_num < 0) //no glow { @@ -680,6 +679,7 @@ bool g3_draw_morphing_model(void *model_ptr,grs_bitmap **model_bitmaps,vms_angve } p += 30 + ((nv&~1)+1)*2 + nv*12; + d_free(lrgb_list); break; } diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 4b3ae5b91..3c125480b 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -5,6 +5,7 @@ D2X-Rebirth Changelog main/collide.c, main/escort.c, main/laser.c, main/fireball.c, main/lighting.c: Code consistency checks by _Tyr_; Fixed set but unused variables d2x-rebirth.desktop, SConstruct, misc/physfsx.c: Patches by Hans de Goede: Made the .desktop file follow the official specifications; Added explicit link to libmath for newer versions of binutils; Fixed crash using PhysFS 1.x in PHYSFSX_addArchiveContent() main/kconfig.c, main/menu.c, main/playsave.c, main/playsave.h: Gave throttle it's own sensitivity and deadzone settings; Added patch by Hans de Goede to let Slide-On and Bank-On settings use invert settings from Slide- and Bank-axes +3d/interp.c, arch/ogl/ogl.c, main/bm.c, main/endlevel.c: Avoided variable array initializations which some compilers do not like; Also made sure declarations happen first inside (sub)functions; Fixed set but unused variables 20110925 -------- diff --git a/arch/ogl/ogl.c b/arch/ogl/ogl.c index 71f5d5abc..d7dcae264 100644 --- a/arch/ogl/ogl.c +++ b/arch/ogl/ogl.c @@ -818,10 +818,12 @@ bool g3_draw_poly(int nv,g3s_point **pointlist) { int c, index3, index4; float color_r, color_g, color_b, color_a; - r_polyc++; - GLfloat vertex_array[nv*3]; - GLfloat color_array[nv*4]; + GLfloat *vertex_array, *color_array; + MALLOC(vertex_array, GLfloat, nv*3); + MALLOC(color_array, GLfloat, nv*4); + + r_polyc++; glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); c = grd_curcanv->cv_color; @@ -852,7 +854,10 @@ bool g3_draw_poly(int nv,g3s_point **pointlist) glDrawArrays(GL_TRIANGLE_FAN, 0, nv); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); - + + d_free(vertex_array); + d_free(color_array); + return 0; } @@ -872,11 +877,8 @@ extern void (*tmap_drawer_ptr)(grs_bitmap *bm,int nv,g3s_point **vertlist); bool g3_draw_tmap(int nv,g3s_point **pointlist,g3s_uvl *uvl_list,g3s_lrgb *light_rgb,grs_bitmap *bm) { int c, index2, index3, index4; - GLfloat vertex_array[nv*3]; - GLfloat color_array[nv*4]; - GLfloat texcoord_array[nv*2]; - GLfloat color_alpha = 1.0; - + GLfloat *vertex_array, *color_array, *texcoord_array, color_alpha = 1.0; + glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); @@ -895,7 +897,11 @@ bool g3_draw_tmap(int nv,g3s_point **pointlist,g3s_uvl *uvl_list,g3s_lrgb *light glmprintf((0,"g3_draw_tmap: unhandled tmap_drawer %p\n",tmap_drawer_ptr)); return 0; } - + + MALLOC(vertex_array, GLfloat, nv*3); + MALLOC(color_array, GLfloat, nv*4); + MALLOC(texcoord_array, GLfloat, nv*2); + for (c=0; cbm_h; - a = (double) grd_curscreen->sc_w / (double) grd_curscreen->sc_h; h = (double) scale / (double) F1_0; xo = x / ((double) last_width * h); diff --git a/main/bm.c b/main/bm.c index b6ef6ac68..92275db91 100644 --- a/main/bm.c +++ b/main/bm.c @@ -276,8 +276,7 @@ void bm_free_extra_models() void bm_read_extra_robots(char *fname,int type) { PHYSFS_file *fp; - int t,i; - int version; + int t,i,version; fp = PHYSFSX_openReadBuffered(fname); @@ -291,6 +290,7 @@ void bm_read_extra_robots(char *fname,int type) } else version = 0; + (void)version; // NOTE: we do not need it, but keep it for possible further use bm_free_extra_models(); bm_free_extra_objbitmaps(); @@ -586,7 +586,7 @@ int load_exit_models() void compute_average_rgb(grs_bitmap *bm, fix *rgb) { - ubyte buf[bm->bm_w*bm->bm_h]; + ubyte *buf; int i, x, y, color, count; fix t_rgb[3] = { 0, 0, 0 }; @@ -595,7 +595,8 @@ void compute_average_rgb(grs_bitmap *bm, fix *rgb) if (!bm->bm_data) return; - memset(&buf,0,bm->bm_w*bm->bm_h); + MALLOC(buf, ubyte, bm->bm_w*bm->bm_h); + memset(buf,0,bm->bm_w*bm->bm_h); if (bm->bm_flags & BM_FLAG_RLE){ unsigned char * dbits; @@ -620,7 +621,7 @@ void compute_average_rgb(grs_bitmap *bm, fix *rgb) } else { - memcpy(&buf, bm->bm_data, sizeof(unsigned char)*(bm->bm_w*bm->bm_h)); + memcpy(buf, bm->bm_data, sizeof(unsigned char)*(bm->bm_w*bm->bm_h)); } i = 0; @@ -641,4 +642,5 @@ void compute_average_rgb(grs_bitmap *bm, fix *rgb) } } } + d_free(buf); } diff --git a/main/endlevel.c b/main/endlevel.c index 8fecc90c1..fd09e537f 100644 --- a/main/endlevel.c +++ b/main/endlevel.c @@ -970,9 +970,10 @@ void render_external_scene(fix eye_offset) #ifdef OGL int orig_Render_depth = Render_depth; #endif - Viewer_eye = Viewer->pos; g3s_lrgb lrgb = { f1_0, f1_0, f1_0 }; + Viewer_eye = Viewer->pos; + if (eye_offset) vm_vec_scale_add2(&Viewer_eye,&Viewer->orient.rvec,eye_offset);