From 031da6280d80b31fb2fcfc1dd3a917824e83e3da Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sun, 15 Jan 2012 22:39:59 +0000 Subject: [PATCH] Remove the allocache() allocation type for 'intptr_t *lookups'. Always malloc that buffer. This allows us to remove suckcache() from cache1d.c, which I believe to be buggy (see comments in the source). git-svn-id: https://svn.eduke32.com/eduke32@2261 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/cache1d.h | 2 +- polymer/eduke32/build/src/cache1d.c | 6 ++++-- polymer/eduke32/build/src/engine.c | 20 ++++++++------------ 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/polymer/eduke32/build/include/cache1d.h b/polymer/eduke32/build/include/cache1d.h index 7c764388b..10ea2204a 100644 --- a/polymer/eduke32/build/include/cache1d.h +++ b/polymer/eduke32/build/include/cache1d.h @@ -17,7 +17,7 @@ extern char filegrp[MAXOPENFILES]; void initcache(intptr_t dacachestart, int32_t dacachesize); void allocache(intptr_t *newhandle, int32_t newbytes, char *newlockptr); -void suckcache(intptr_t *suckptr); +//void suckcache(intptr_t *suckptr); void agecache(void); extern int32_t pathsearchmode; // 0 = gamefs mode (default), 1 = localfs mode (editor's mode) diff --git a/polymer/eduke32/build/src/cache1d.c b/polymer/eduke32/build/src/cache1d.c index bac425f39..955f5f9bc 100644 --- a/polymer/eduke32/build/src/cache1d.c +++ b/polymer/eduke32/build/src/cache1d.c @@ -181,6 +181,7 @@ void allocache(intptr_t *newhandle, int32_t newbytes, char *newlockptr) cac[bestz].lock = &zerochar; } +#if 0 void suckcache(intptr_t *suckptr) { int32_t i; @@ -198,16 +199,17 @@ void suckcache(intptr_t *suckptr) if ((i > 0) && (*cac[i-1].lock == 0)) { cac[i-1].leng += cac[i].leng; - cacnum--; copybuf(&cac[i+1],&cac[i],(cacnum-i)*sizeof(cactype)); + cacnum--; copybuf(&cac[i+1],&cac[i],(cacnum-i)*sizeof(cactype)); // XXX: this looks suspicious, copybuf already multiplies by 4... } else if ((i < cacnum-1) && (*cac[i+1].lock == 0)) { cac[i+1].leng += cac[i].leng; - cacnum--; copybuf(&cac[i+1],&cac[i],(cacnum-i)*sizeof(cactype)); + cacnum--; copybuf(&cac[i+1],&cac[i],(cacnum-i)*sizeof(cactype)); // XXX: see above } } } } +#endif void agecache(void) { diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index f97b348c1..a88f2cf4a 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -97,7 +97,6 @@ static int32_t lowrecip[1024], nytooclose, nytoofar; static uint32_t distrecip[65536+256]; static intptr_t *lookups = NULL; -static char lookupsalloctype = 255; int32_t dommxoverlay = 1, beforedrawrooms = 1, indrawroomsandmasks = 0; static int32_t oxdimen = -1, oviewingrange = -1, oxyaspect = -1; @@ -7883,8 +7882,7 @@ void uninitengine(void) if (pic != NULL) { Bfree(pic); pic = NULL; } if (lookups != NULL) { - if (lookupsalloctype == 0) Bfree((void *)lookups); - //if (lookupsalloctype == 1) suckcache(lookups); //Cache already gone + Bfree((void *)lookups); lookups = NULL; } @@ -10061,16 +10059,14 @@ int32_t setgamemode(char davidoption, int32_t daxdim, int32_t daydim, int32_t da j = ydim*4*sizeof(intptr_t); //Leave room for horizlookup&horizlookup2 if (lookups != NULL) + Bfree((void *)lookups); + lookups = Bmalloc(j<<1); + + if (lookups == NULL) { - if (lookupsalloctype == 0) Bfree((void *)lookups); - if (lookupsalloctype == 1) suckcache(lookups); - lookups = NULL; - } - lookupsalloctype = 0; - if ((lookups = (intptr_t *)Bmalloc(j<<1)) == NULL) - { - allocache((intptr_t *)&lookups,j<<1,&permanentlock); - lookupsalloctype = 1; + initprintf("OUT OF MEMORY in setgamemode!\n"); + uninitengine(); + exit(1); } horizlookup = lookups;