From 6cab8cf4e0a7d2c452a25088e4dbd32a0ef574ce Mon Sep 17 00:00:00 2001 From: Adam Olsen Date: Fri, 31 Aug 2001 03:48:26 +0000 Subject: [PATCH] - change Cache_Get calls to Cache_TryGet (which I just added), so they can tollerate failure. - minor error message tweak (an emptry string is not NULL!) --- include/QF/zone.h | 1 + libs/audio/renderer/snd_dma.c | 15 +++++++-------- libs/audio/renderer/snd_mix.c | 2 +- libs/models/model.c | 2 +- libs/util/zone.c | 18 ++++++++++++------ 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/include/QF/zone.h b/include/QF/zone.h index 24989ca5a..882ff71ba 100644 --- a/include/QF/zone.h +++ b/include/QF/zone.h @@ -146,6 +146,7 @@ void Cache_Report (void); void Cache_Add (cache_user_t *c, const char *filename, cache_loader_t loader); void Cache_Remove (cache_user_t *c); void *Cache_Get (cache_user_t *c); +void *Cache_TryGet (cache_user_t *c); void Cache_Release (cache_user_t *c); /* Modes, pick one */ diff --git a/libs/audio/renderer/snd_dma.c b/libs/audio/renderer/snd_dma.c index 4a96156e7..05822756d 100644 --- a/libs/audio/renderer/snd_dma.c +++ b/libs/audio/renderer/snd_dma.c @@ -360,10 +360,9 @@ SND_PrecacheSound (const char *name) sfx = SND_FindName (name); // cache it in - if (precache->int_val) { - Cache_Get (&sfx->cache); - Cache_Release (&sfx->cache); - } + if (precache->int_val) + if (Cache_TryGet (&sfx->cache)) + Cache_Release (&sfx->cache); return sfx; } @@ -499,7 +498,7 @@ SND_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, return; // not audible at all // new channel - sc = Cache_Get (&sfx->cache); + sc = Cache_TryGet (&sfx->cache); if (!sc) { target_chan->sfx = NULL; return; // couldn't load the sound's data @@ -617,7 +616,7 @@ SND_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation) ss = &channels[total_channels]; total_channels++; - sc = Cache_Get (&sfx->cache); + sc = Cache_TryGet (&sfx->cache); if (!sc) return; @@ -899,7 +898,7 @@ SND_SoundList (void) int size, total; int load; - if (Cmd_Argc() >= 2 && !strcmp (Cmd_Argv (1), "known")) + if (Cmd_Argc() >= 2 && Cmd_Argv (1)[0]) load = 1; else load = 0; @@ -907,7 +906,7 @@ SND_SoundList (void) total = 0; for (sfx = known_sfx, i = 0; i < num_sfx; i++, sfx++) { if (load) - sc = Cache_Get (&sfx->cache); + sc = Cache_TryGet (&sfx->cache); else sc = Cache_Check (&sfx->cache); diff --git a/libs/audio/renderer/snd_mix.c b/libs/audio/renderer/snd_mix.c index 2b9751ee7..cf0d2b132 100644 --- a/libs/audio/renderer/snd_mix.c +++ b/libs/audio/renderer/snd_mix.c @@ -237,7 +237,7 @@ SND_PaintChannels (int endtime) continue; if (!ch->leftvol && !ch->rightvol) continue; - sc = Cache_Get (&ch->sfx->cache); + sc = Cache_TryGet (&ch->sfx->cache); if (!sc) continue; diff --git a/libs/models/model.c b/libs/models/model.c index b5ce5230f..8840268bb 100644 --- a/libs/models/model.c +++ b/libs/models/model.c @@ -130,7 +130,7 @@ Mod_FindName (const char *name) model_t *mod; if (!name[0]) - Sys_Error ("Mod_FindName: NULL name"); + Sys_Error ("Mod_FindName: empty name"); // search the currently loaded models for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++) diff --git a/libs/util/zone.c b/libs/util/zone.c index a16f2f4f5..60ea8d746 100644 --- a/libs/util/zone.c +++ b/libs/util/zone.c @@ -999,7 +999,7 @@ Cache_Remove (cache_user_t *c) } void * -Cache_Get (cache_user_t *c) +Cache_TryGet (cache_user_t *c) { void *mem; CACHE_WRITE_LOCK; @@ -1009,16 +1009,22 @@ Cache_Get (cache_user_t *c) c->loader (c, Cache_RealAlloc); mem = Cache_RealCheck (c); } - - if (!mem) - Sys_Error ("Cache_Get: couldn't get cache!\n"); - - (((cache_system_t *)c->data) - 1)->readlock++; + if (mem) + (((cache_system_t *)c->data) - 1)->readlock++; CACHE_WRITE_UNLOCK; return mem; } +void * +Cache_Get (cache_user_t *c) +{ + void *mem = Cache_TryGet (c); + if (!mem) + Sys_Error ("Cache_Get: couldn't get cache!\n"); + return mem; +} + void Cache_Release (cache_user_t *c) {