forked from len0rd/rockbox
quake: synchronize Mod_LoadModel and S_LoadSound
This is not a very pretty fix, but code that doesn't crash is better than code that crashes... "If it runs, it's done." Change-Id: Ia1d0c537e5e5e60fb80cf7d7de2332e1c712806f
This commit is contained in:
parent
9d2af8777f
commit
fee68fc612
2 changed files with 47 additions and 2 deletions
|
@ -255,6 +255,18 @@ Loads a model into the cache
|
||||||
*/
|
*/
|
||||||
model_t *Mod_LoadModel (model_t *mod, qboolean crash)
|
model_t *Mod_LoadModel (model_t *mod, qboolean crash)
|
||||||
{
|
{
|
||||||
|
// prevents crashes
|
||||||
|
extern struct mutex snd_mutex;
|
||||||
|
extern int snd_mutex_init;
|
||||||
|
|
||||||
|
if(!snd_mutex_init)
|
||||||
|
{
|
||||||
|
rb->mutex_init(&snd_mutex);
|
||||||
|
snd_mutex_init = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
rb->mutex_lock(&snd_mutex);
|
||||||
|
|
||||||
//printf("loadmodel 1");
|
//printf("loadmodel 1");
|
||||||
unsigned *buf;
|
unsigned *buf;
|
||||||
byte stackbuf[1024]; // avoid dirtying the cache heap
|
byte stackbuf[1024]; // avoid dirtying the cache heap
|
||||||
|
@ -264,13 +276,17 @@ model_t *Mod_LoadModel (model_t *mod, qboolean crash)
|
||||||
if (Cache_Check (&mod->cache))
|
if (Cache_Check (&mod->cache))
|
||||||
{
|
{
|
||||||
mod->needload = NL_PRESENT;
|
mod->needload = NL_PRESENT;
|
||||||
|
rb->mutex_unlock(&snd_mutex);
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (mod->needload == NL_PRESENT)
|
if (mod->needload == NL_PRESENT)
|
||||||
return mod;
|
{
|
||||||
|
rb->mutex_unlock(&snd_mutex);
|
||||||
|
return mod;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -283,17 +299,23 @@ model_t *Mod_LoadModel (model_t *mod, qboolean crash)
|
||||||
|
|
||||||
//printf("loadmodel 2");
|
//printf("loadmodel 2");
|
||||||
buf = (unsigned *)COM_LoadStackFile (mod->name, stackbuf, sizeof(stackbuf));
|
buf = (unsigned *)COM_LoadStackFile (mod->name, stackbuf, sizeof(stackbuf));
|
||||||
|
//printf("LoadModel0: %08x (%08x)", buf[0], buf);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
{
|
{
|
||||||
if (crash)
|
if (crash)
|
||||||
Sys_Error ("Mod_NumForName: %s not found", mod->name);
|
Sys_Error ("Mod_NumForName: %s not found", mod->name);
|
||||||
|
|
||||||
|
rb->mutex_unlock(&snd_mutex);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// allocate a new model
|
// allocate a new model
|
||||||
//
|
//
|
||||||
|
//printf("LoadModel1: %08x (%08x)", buf[0], buf);
|
||||||
|
|
||||||
COM_FileBase (mod->name, loadname);
|
COM_FileBase (mod->name, loadname);
|
||||||
|
//printf("LoadModel2: %08x (%08x)", buf[0], buf);
|
||||||
|
|
||||||
loadmodel = mod;
|
loadmodel = mod;
|
||||||
|
|
||||||
|
@ -316,10 +338,12 @@ model_t *Mod_LoadModel (model_t *mod, qboolean crash)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
//printf("unkn %08x (&=%08x), nat %08x def to brush", LittleLongUnaligned(buf[0]), &buf[0], buf[0]);
|
||||||
Mod_LoadBrushModel (mod, buf);
|
Mod_LoadBrushModel (mod, buf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rb->mutex_unlock(&snd_mutex);
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,10 @@ void ResampleSfx (sfx_t *sfx, int inrate, int inwidth, byte *data)
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
|
|
||||||
|
// used to synchronize with Mod_LoadModel, which causes crashes if not done.
|
||||||
|
struct mutex snd_mutex;
|
||||||
|
int snd_mutex_init = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
==============
|
==============
|
||||||
S_LoadSound
|
S_LoadSound
|
||||||
|
@ -96,6 +100,7 @@ S_LoadSound
|
||||||
*/
|
*/
|
||||||
sfxcache_t *S_LoadSound (sfx_t *s)
|
sfxcache_t *S_LoadSound (sfx_t *s)
|
||||||
{
|
{
|
||||||
|
//return NULL;
|
||||||
char namebuffer[256];
|
char namebuffer[256];
|
||||||
byte *data;
|
byte *data;
|
||||||
wavinfo_t info;
|
wavinfo_t info;
|
||||||
|
@ -104,11 +109,21 @@ sfxcache_t *S_LoadSound (sfx_t *s)
|
||||||
sfxcache_t *sc;
|
sfxcache_t *sc;
|
||||||
byte stackbuf[1*1024]; // avoid dirtying the cache heap
|
byte stackbuf[1*1024]; // avoid dirtying the cache heap
|
||||||
|
|
||||||
// see if still in memory
|
// see if still in memory (no mutex)
|
||||||
sc = Cache_Check (&s->cache);
|
sc = Cache_Check (&s->cache);
|
||||||
if (sc)
|
if (sc)
|
||||||
|
{
|
||||||
return sc;
|
return sc;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!snd_mutex_init)
|
||||||
|
{
|
||||||
|
rb->mutex_init(&snd_mutex);
|
||||||
|
snd_mutex_init = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
rb->mutex_lock(&snd_mutex);
|
||||||
|
|
||||||
//Con_Printf ("S_LoadSound: %x\n", (int)stackbuf);
|
//Con_Printf ("S_LoadSound: %x\n", (int)stackbuf);
|
||||||
// load it in
|
// load it in
|
||||||
Q_strcpy(namebuffer, "sound/");
|
Q_strcpy(namebuffer, "sound/");
|
||||||
|
@ -120,6 +135,7 @@ sfxcache_t *S_LoadSound (sfx_t *s)
|
||||||
|
|
||||||
if (!data)
|
if (!data)
|
||||||
{
|
{
|
||||||
|
rb->mutex_unlock(&snd_mutex);
|
||||||
Con_Printf ("Couldn't load %s\n", namebuffer);
|
Con_Printf ("Couldn't load %s\n", namebuffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -127,6 +143,7 @@ sfxcache_t *S_LoadSound (sfx_t *s)
|
||||||
info = GetWavinfo (s->name, data, com_filesize);
|
info = GetWavinfo (s->name, data, com_filesize);
|
||||||
if (info.channels != 1)
|
if (info.channels != 1)
|
||||||
{
|
{
|
||||||
|
rb->mutex_unlock(&snd_mutex);
|
||||||
Con_Printf ("%s is a stereo sample\n",s->name);
|
Con_Printf ("%s is a stereo sample\n",s->name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -138,7 +155,10 @@ sfxcache_t *S_LoadSound (sfx_t *s)
|
||||||
|
|
||||||
sc = Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name);
|
sc = Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name);
|
||||||
if (!sc)
|
if (!sc)
|
||||||
|
{
|
||||||
|
rb->mutex_unlock(&snd_mutex);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
sc->length = info.samples;
|
sc->length = info.samples;
|
||||||
sc->loopstart = info.loopstart;
|
sc->loopstart = info.loopstart;
|
||||||
|
@ -148,6 +168,7 @@ sfxcache_t *S_LoadSound (sfx_t *s)
|
||||||
|
|
||||||
ResampleSfx (s, sc->speed, sc->width, data + info.dataofs);
|
ResampleSfx (s, sc->speed, sc->width, data + info.dataofs);
|
||||||
|
|
||||||
|
rb->mutex_unlock(&snd_mutex);
|
||||||
return sc;
|
return sc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue