summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <franklin@rockbox.org>2019-08-02 23:00:30 -0400
committerFranklin Wei <franklin@rockbox.org>2019-08-03 05:05:05 +0200
commitfee68fc612a3c6c67c55aa194223002bdfda7261 (patch)
treebc1ec55bc3c7e30a3ff38d38c981bb7ba31052eb
parent9d2af8777fc179573867bf03a803e5188025eda7 (diff)
downloadrockbox-fee68fc612a3c6c67c55aa194223002bdfda7261.tar.gz
rockbox-fee68fc612a3c6c67c55aa194223002bdfda7261.zip
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
-rw-r--r--apps/plugins/sdl/progs/quake/model.c26
-rw-r--r--apps/plugins/sdl/progs/quake/snd_mem.c23
2 files changed, 47 insertions, 2 deletions
diff --git a/apps/plugins/sdl/progs/quake/model.c b/apps/plugins/sdl/progs/quake/model.c
index 7648590db4..64c53dfc3e 100644
--- a/apps/plugins/sdl/progs/quake/model.c
+++ b/apps/plugins/sdl/progs/quake/model.c
@@ -255,6 +255,18 @@ Loads a model into the cache
255*/ 255*/
256model_t *Mod_LoadModel (model_t *mod, qboolean crash) 256model_t *Mod_LoadModel (model_t *mod, qboolean crash)
257{ 257{
258 // prevents crashes
259 extern struct mutex snd_mutex;
260 extern int snd_mutex_init;
261
262 if(!snd_mutex_init)
263 {
264 rb->mutex_init(&snd_mutex);
265 snd_mutex_init = 1;
266 }
267
268 rb->mutex_lock(&snd_mutex);
269
258 //printf("loadmodel 1"); 270 //printf("loadmodel 1");
259 unsigned *buf; 271 unsigned *buf;
260 byte stackbuf[1024]; // avoid dirtying the cache heap 272 byte stackbuf[1024]; // avoid dirtying the cache heap
@@ -264,13 +276,17 @@ model_t *Mod_LoadModel (model_t *mod, qboolean crash)
264 if (Cache_Check (&mod->cache)) 276 if (Cache_Check (&mod->cache))
265 { 277 {
266 mod->needload = NL_PRESENT; 278 mod->needload = NL_PRESENT;
279 rb->mutex_unlock(&snd_mutex);
267 return mod; 280 return mod;
268 } 281 }
269 } 282 }
270 else 283 else
271 { 284 {
272 if (mod->needload == NL_PRESENT) 285 if (mod->needload == NL_PRESENT)
273 return mod; 286 {
287 rb->mutex_unlock(&snd_mutex);
288 return mod;
289 }
274 } 290 }
275 291
276// 292//
@@ -283,17 +299,23 @@ model_t *Mod_LoadModel (model_t *mod, qboolean crash)
283 299
284 //printf("loadmodel 2"); 300 //printf("loadmodel 2");
285 buf = (unsigned *)COM_LoadStackFile (mod->name, stackbuf, sizeof(stackbuf)); 301 buf = (unsigned *)COM_LoadStackFile (mod->name, stackbuf, sizeof(stackbuf));
302 //printf("LoadModel0: %08x (%08x)", buf[0], buf);
286 if (!buf) 303 if (!buf)
287 { 304 {
288 if (crash) 305 if (crash)
289 Sys_Error ("Mod_NumForName: %s not found", mod->name); 306 Sys_Error ("Mod_NumForName: %s not found", mod->name);
307
308 rb->mutex_unlock(&snd_mutex);
290 return NULL; 309 return NULL;
291 } 310 }
292 311
293// 312//
294// allocate a new model 313// allocate a new model
295// 314//
315 //printf("LoadModel1: %08x (%08x)", buf[0], buf);
316
296 COM_FileBase (mod->name, loadname); 317 COM_FileBase (mod->name, loadname);
318 //printf("LoadModel2: %08x (%08x)", buf[0], buf);
297 319
298 loadmodel = mod; 320 loadmodel = mod;
299 321
@@ -316,10 +338,12 @@ model_t *Mod_LoadModel (model_t *mod, qboolean crash)
316 break; 338 break;
317 339
318 default: 340 default:
341 //printf("unkn %08x (&=%08x), nat %08x def to brush", LittleLongUnaligned(buf[0]), &buf[0], buf[0]);
319 Mod_LoadBrushModel (mod, buf); 342 Mod_LoadBrushModel (mod, buf);
320 break; 343 break;
321 } 344 }
322 345
346 rb->mutex_unlock(&snd_mutex);
323 return mod; 347 return mod;
324} 348}
325 349
diff --git a/apps/plugins/sdl/progs/quake/snd_mem.c b/apps/plugins/sdl/progs/quake/snd_mem.c
index 71e32aa056..8b0a5ca9f7 100644
--- a/apps/plugins/sdl/progs/quake/snd_mem.c
+++ b/apps/plugins/sdl/progs/quake/snd_mem.c
@@ -89,6 +89,10 @@ void ResampleSfx (sfx_t *sfx, int inrate, int inwidth, byte *data)
89 89
90//============================================================================= 90//=============================================================================
91 91
92// used to synchronize with Mod_LoadModel, which causes crashes if not done.
93struct mutex snd_mutex;
94int snd_mutex_init = 0;
95
92/* 96/*
93============== 97==============
94S_LoadSound 98S_LoadSound
@@ -96,6 +100,7 @@ S_LoadSound
96*/ 100*/
97sfxcache_t *S_LoadSound (sfx_t *s) 101sfxcache_t *S_LoadSound (sfx_t *s)
98{ 102{
103 //return NULL;
99 char namebuffer[256]; 104 char namebuffer[256];
100 byte *data; 105 byte *data;
101 wavinfo_t info; 106 wavinfo_t info;
@@ -104,11 +109,21 @@ sfxcache_t *S_LoadSound (sfx_t *s)
104 sfxcache_t *sc; 109 sfxcache_t *sc;
105 byte stackbuf[1*1024]; // avoid dirtying the cache heap 110 byte stackbuf[1*1024]; // avoid dirtying the cache heap
106 111
107// see if still in memory 112// see if still in memory (no mutex)
108 sc = Cache_Check (&s->cache); 113 sc = Cache_Check (&s->cache);
109 if (sc) 114 if (sc)
115 {
110 return sc; 116 return sc;
117 }
118
119 if(!snd_mutex_init)
120 {
121 rb->mutex_init(&snd_mutex);
122 snd_mutex_init = 1;
123 }
111 124
125 rb->mutex_lock(&snd_mutex);
126
112//Con_Printf ("S_LoadSound: %x\n", (int)stackbuf); 127//Con_Printf ("S_LoadSound: %x\n", (int)stackbuf);
113// load it in 128// load it in
114 Q_strcpy(namebuffer, "sound/"); 129 Q_strcpy(namebuffer, "sound/");
@@ -120,6 +135,7 @@ sfxcache_t *S_LoadSound (sfx_t *s)
120 135
121 if (!data) 136 if (!data)
122 { 137 {
138 rb->mutex_unlock(&snd_mutex);
123 Con_Printf ("Couldn't load %s\n", namebuffer); 139 Con_Printf ("Couldn't load %s\n", namebuffer);
124 return NULL; 140 return NULL;
125 } 141 }
@@ -127,6 +143,7 @@ sfxcache_t *S_LoadSound (sfx_t *s)
127 info = GetWavinfo (s->name, data, com_filesize); 143 info = GetWavinfo (s->name, data, com_filesize);
128 if (info.channels != 1) 144 if (info.channels != 1)
129 { 145 {
146 rb->mutex_unlock(&snd_mutex);
130 Con_Printf ("%s is a stereo sample\n",s->name); 147 Con_Printf ("%s is a stereo sample\n",s->name);
131 return NULL; 148 return NULL;
132 } 149 }
@@ -138,7 +155,10 @@ sfxcache_t *S_LoadSound (sfx_t *s)
138 155
139 sc = Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name); 156 sc = Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name);
140 if (!sc) 157 if (!sc)
158 {
159 rb->mutex_unlock(&snd_mutex);
141 return NULL; 160 return NULL;
161 }
142 162
143 sc->length = info.samples; 163 sc->length = info.samples;
144 sc->loopstart = info.loopstart; 164 sc->loopstart = info.loopstart;
@@ -148,6 +168,7 @@ sfxcache_t *S_LoadSound (sfx_t *s)
148 168
149 ResampleSfx (s, sc->speed, sc->width, data + info.dataofs); 169 ResampleSfx (s, sc->speed, sc->width, data + info.dataofs);
150 170
171 rb->mutex_unlock(&snd_mutex);
151 return sc; 172 return sc;
152} 173}
153 174