diff --git a/src/common.c b/src/common.c index 656b2f1..10d7cfc 100644 --- a/src/common.c +++ b/src/common.c @@ -1152,8 +1152,11 @@ void Z_Free (void *ptr) z = ((zhead_t *)ptr) - 1; - if (z->magic != Z_MAGIC) + if (z->magic != Z_MAGIC) { + printf("free: %p failed\n", ptr); + abort(); Com_Error (ERR_FATAL, "Z_Free: bad magic"); + } z->prev->next = z->next; z->next->prev = z->prev; diff --git a/src/gl_local.h b/src/gl_local.h index fdeff6f..421c4e2 100644 --- a/src/gl_local.h +++ b/src/gl_local.h @@ -27,23 +27,23 @@ #include #include + #ifdef HAVE_OPENGL_GLEXT -#include -#endif // HAVE_OPENGL_GLEXT +# include +#else /* HAVE_OPENGL_GLEXT */ +# include +# ifndef GL_COLOR_INDEX8_EXT +# define GL_COLOR_INDEX8_EXT GL_COLOR_INDEX +# endif +#endif /* HAVE_OPENGL_GLEXT */ + #include #ifndef _WIN32 char *strlwr (char *s); #endif -#ifdef __sun__ -# ifndef GL_COLOR_INDEX8_EXT -# define GL_COLOR_INDEX8_EXT GL_COLOR_INDEX -# endif -#endif - #include "ref.h" - #include "qgl.h" #define REF_VERSION "GL 0.01" diff --git a/src/main.c b/src/main.c index 96a767b..5c402cc 100644 --- a/src/main.c +++ b/src/main.c @@ -61,12 +61,39 @@ #include "game.h" #include "rw.h" +#ifdef SOL8_XIL_WORKAROUND +#include +typedef struct { + qboolean restart_sound; + int s_rate; + int s_width; + int s_channels; + + int width; + int height; + byte * pic; + byte * pic_pending; + + /* order 1 huffman stuff */ + int * hnodes1; /* [256][256][2] */ + int numhnodes1[256]; + int h_used[512]; + int h_count[512]; +} cinematics_t; +#endif + + cvar_t *nostdout; unsigned sys_frame_time; uid_t saved_euid; qboolean stdin_active = true; +char display_name[1024]; +/* FIXME: replace with configure test for hrtime_t */ +#ifdef __sun__ +hrtime_t base_hrtime; +#endif // ======================================================================= // General routines @@ -126,7 +153,7 @@ void Sys_Error (char *error, ...) va_list argptr; char string[1024]; -// change stdin to non blocking + /* change stdin to non blocking */ fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY); CL_Shutdown (); @@ -285,9 +312,42 @@ void Sys_SendKeyEvents (void) } /*****************************************************************************/ +#ifdef SOL8_XIL_WORKAROUND +XilSystemState xil_state; +#endif int main (int argc, char **argv) { int time, oldtime, newtime; + sigset_t sigs; + +#ifdef SOL8_XIL_WORKAROUND + { + extern cinematics_t cin; + + if ((xil_state = xil_open()) == NULL) { + fprintf(stderr, "Can't open XIL\n"); + exit(1); + } + memset(&cin, 0, sizeof(cin)); + } +#endif + + /* save the contents of the DISPLAY environment variable. + * if we don't, it gets overwritten after reloading + * the renderer libraries (solaris) */ + { + char * tmp_name = getenv("DISPLAY"); + if (tmp_name == NULL) { + display_name[0] = '\0'; + } else { + strncpy(display_name, tmp_name, sizeof(display_name)); + } + } + + /* block the SIGPOLL signal so that only the audio thread gets it */ + sigemptyset(&sigs); + sigaddset(&sigs, SIGPOLL); + pthread_sigmask(SIG_BLOCK, &sigs, NULL); /* go back to real user for config loads */ saved_euid = geteuid(); @@ -449,3 +509,39 @@ void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length) } #endif + +size_t verify_fread(void * ptr, size_t size, size_t nitems, FILE * fp) { + size_t ret; + int err; + + clearerr(fp); + ret = fread(ptr, size, nitems, fp); + err = errno; + if (ret != nitems) { + printf("verify_fread(...,%d,%d,...): return value: %d\n", size, nitems, ret); + if (ret == 0 && ferror(fp)) { + printf(" error: %s\n", strerror(err)); + printf(" fileno=%d\n", fileno(fp)); + } + /* sleep(5); */ + } + return ret; +} + +size_t verify_fwrite(void * ptr, size_t size, size_t nitems, FILE * fp) { + size_t ret; + int err; + + clearerr(fp); + ret = fwrite(ptr, size, nitems, fp); + err = errno; + if (ret != nitems) { + printf("verify_fwrite(...,%d,%d,...) = %d\n", size, nitems, ret); + if (ret == 0 && ferror(fp)) { + printf(" error: %s\n", strerror(err)); + printf(" fileno=%d\n", fileno(fp)); + } + } + /* sleep(5); */ + return ret; +} diff --git a/src/menu.c b/src/menu.c index f8700ad..cc5160e 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1,22 +1,24 @@ -/* -Copyright (C) 1997-2001 Id Software, Inc. +/* $Id$ + * + * Copyright (C) 1997-2001 Id Software, Inc. + * Copyright (c) 2002 The Quakeforge Project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ #include #ifdef _WIN32 #include @@ -3477,7 +3479,7 @@ static qboolean PlayerConfig_ScanDirectories( void ) char findname[1024]; char scratch[1024]; int ndirs = 0, npms = 0; - char **dirnames; + char **dirnames = NULL; char *path = NULL; int i; @@ -3491,6 +3493,11 @@ static qboolean PlayerConfig_ScanDirectories( void ) do { path = FS_NextPath( path ); + /* If FS_NextPath returns NULL we get a segv on the next line on solaris. + * Other platforms work probably because path becomes the null string + * or something */ + if (path == NULL) + break; Com_sprintf( findname, sizeof(findname), "%s/players/*.*", path ); if ( ( dirnames = FS_ListFiles( findname, &ndirs, SFF_SUBDIR, 0 ) ) != 0 ) diff --git a/src/q_sh.c b/src/q_sh.c index 38bfa51..32e2edc 100644 --- a/src/q_sh.c +++ b/src/q_sh.c @@ -51,12 +51,15 @@ void *Hunk_Begin (int maxsize) maxhunksize = maxsize + sizeof(int); curhunksize = 0; /* merged in from q_sh*.c -- jaq */ +/* FIXME: clean all this up into configure tests for mmap, MAP_ANONYMOUS and malloc */ #if defined(__linux__) membase = mmap(0, maxhunksize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); #elif defined(__FreeBSD__) || defined(__bsd__) || defined(__NetBSD__) membase = mmap(0, maxhunksize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); #elif defined(__sun__) || defined(__sgi) membase = malloc(maxhunksize); + /* the following line is for debugging purposes */ + memset(membase, 0, maxhunksize); #endif if (membase == NULL || membase == (byte *)-1) Sys_Error("unable to virtual allocate %d bytes", maxsize); @@ -170,6 +173,18 @@ Sys_Milliseconds ================ */ int curtime; +/* FIXME: replace with a configure test for gethrtime() */ +#ifdef __sun__ +extern hrtime_t base_hrtime + +int Sys_Milliseconds(void) { + hrtime_t curr_hrtime; + + curr_hrtime = gethrtime(); + curtime = (curr_hrtime - base_hrtime) / 1000000LL; + return curtime; +} +#else int Sys_Milliseconds (void) { struct timeval tp; @@ -188,6 +203,7 @@ int Sys_Milliseconds (void) return curtime; } +#endif void Sys_Mkdir (char *path) { @@ -214,8 +230,10 @@ static DIR *fdir; static qboolean CompareAttributes(char *path, char *name, unsigned musthave, unsigned canthave ) { +#if 0 struct stat st; char fn[MAX_OSPATH]; +#endif // . and .. never match if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) @@ -223,10 +241,9 @@ static qboolean CompareAttributes(char *path, char *name, /* FIXME: what's the point of the return? -- jaq */ #if 1 - sprintf(fn, "%s/%s", path, name); -#else return true; -#endif +#else + sprintf(fn, "%s/%s", path, name); if (stat(fn, &st) == -1) return false; // shouldn't happen @@ -238,6 +255,7 @@ static qboolean CompareAttributes(char *path, char *name, return false; return true; +#endif } char *Sys_FindFirst (char *path, unsigned musthave, unsigned canhave) diff --git a/src/q_shared.h b/src/q_shared.h index 3779166..96fd914 100644 --- a/src/q_shared.h +++ b/src/q_shared.h @@ -1209,3 +1209,7 @@ typedef struct extern int vidref_val; // PGM // ================== + +/* error save versions of fread and fwrite */ +size_t verify_fread(void *, size_t, size_t, FILE *); +size_t verify_fwrite(void *, size_t, size_t, FILE *); diff --git a/src/qgl.h b/src/qgl.h index 588b28c..9572d00 100644 --- a/src/qgl.h +++ b/src/qgl.h @@ -29,9 +29,10 @@ #endif #include + #ifdef HAVE_OPENGL_GLEXT -#include -#endif // HAVE_OPENGL_GLEXT +# include +#endif /* HAVE_OPENGL_GLEXT */ qboolean QGL_Init( const char *dllname ); void QGL_Shutdown( void ); @@ -462,34 +463,32 @@ extern void (*qgl3DfxSetPaletteEXT)(GLuint *); #define GL_TEXTURE0_SGIS 0x835E #define GL_TEXTURE1_SGIS 0x835F +#ifndef HAVE_OPENGL_GLEXT +/* these are in glext.h */ +/* extension constants */ +# define GL_POINT_SIZE_MIN_EXT 0x8126 +# define GL_POINT_SIZE_MAX_EXT 0x8127 +# define GL_POINT_FADE_THRESHOLD_SIZE_EXT 0x8128 +# define GL_DISTANCE_ATTENUATION_EXT 0x8129 -#ifndef HAVE_OPENGL_GLEXT // FIXME: these are in glext.h, delete after testing -// extension constants -#define GL_POINT_SIZE_MIN_EXT 0x8126 -#define GL_POINT_SIZE_MAX_EXT 0x8127 -#define GL_POINT_FADE_THRESHOLD_SIZE_EXT 0x8128 -#define GL_DISTANCE_ATTENUATION_EXT 0x8129 +# ifdef __sgi +# define GL_SHARED_TEXTURE_PALETTE_EXT GL_TEXTURE_COLOR_TABLE_SGI +# else +# define GL_SHARED_TEXTURE_PALETTE_EXT 0x81FB +# endif -#ifdef __sgi -#define GL_SHARED_TEXTURE_PALETTE_EXT GL_TEXTURE_COLOR_TABLE_SGI -#else -#define GL_SHARED_TEXTURE_PALETTE_EXT 0x81FB -#endif +# ifdef GL_DISTANCE_ATTENUATION_ARB +# define GL_DISTANCE_ATTENUATION_EXT GL_DISTANCE_ATTENUATION_ARB +# endif /* GL_DISTANCE_ATTENUATION_ARB */ -#ifdef __sun__ -#ifdef GL_DISTANCE_ATTENUATION_ARB -#define GL_DISTANCE_ATTENUATION_EXT GL_DISTANCE_ATTENUATION_ARB -#endif // GL_DISTANCE_ATTENUATION_ARB -#endif // __sun__ +# ifndef GL_TEXTURE0_ARB +# define GL_TEXTURE0_ARB 0x84C0 +# endif +# ifndef GL_TEXTURE1_ARB +# define GL_TEXTURE1_ARB 0x84C1 +# endif -#ifndef GL_TEXTURE0_ARB -#define GL_TEXTURE0_ARB 0x84C0 -#endif -#ifndef GL_TEXTURE1_ARB -#define GL_TEXTURE1_ARB 0x84C1 -#endif - -#endif // HAVE_OPENGL_GLEXT, end of glext.h defines +#endif /* HAVE_OPENGL_GLEXT */ extern int QGL_TEXTURE0, QGL_TEXTURE1; diff --git a/src/r_model.c b/src/r_model.c index ff8c8c8..da8f26a 100644 --- a/src/r_model.c +++ b/src/r_model.c @@ -1,26 +1,28 @@ -/* -Copyright (C) 1997-2001 Id Software, Inc. +/* $Id$ + * + * model loading and caching + * + * Copyright (C) 1997-2001 Id Software, Inc. + * Copyright (c) 2002 The Quakeforge Project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ -// models.c -- model loading and caching - -// models are the only shared resource between a client and server running -// on the same machine. +/* models are the only shared resource between a client and server running + * on the same machine. */ #include "r_local.h" @@ -386,6 +388,9 @@ void Mod_LoadVertexes (lump_t *l) count = l->filelen / sizeof(*in); out = Hunk_Alloc ( (count+8)*sizeof(*out)); // extra for skybox + /* stop the games dumping core when changing levels */ + memset(out, 0, (count + 6) * sizeof(*out)); + loadmodel->vertexes = out; loadmodel->numvertexes = count; @@ -508,6 +513,9 @@ void Mod_LoadTexinfo (lump_t *l) next = LittleLong (in->nexttexinfo); if (next > 0) out->next = loadmodel->texinfo + next; + else + /* stop game dumping core when loading a new level */ + out->next = NULL; Com_sprintf (name, sizeof(name), "textures/%s.wal", in->texture); out->image = R_FindImage (name, it_wall); diff --git a/src/snd_dma.c b/src/snd_dma.c index 1a79c2e..ede0057 100644 --- a/src/snd_dma.c +++ b/src/snd_dma.c @@ -905,8 +905,15 @@ void S_AddLoopSounds (void) ch->rightvol = right_total; ch->autosound = true; // remove next frame ch->sfx = sfx; + /* sometimes, the sc->length argument can become 0, and in that + * case we get a SIGFPE in the next modulo. The workaround checks + * for this situation and sets the pos and end to zero if true */ + if (sc->length == 0) { + ch->pos = ch->end = 0; + } else { ch->pos = paintedtime % sc->length; ch->end = paintedtime + sc->length - ch->pos; + } } }