]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
added safety checks in S_PlaySfxOnChannel due to a report of a crash
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 12 Apr 2009 23:22:57 +0000 (23:22 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 12 Apr 2009 23:22:57 +0000 (23:22 +0000)
with ch->sfx == NULL in the mixer thread

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8916 d7cf8633-e32d-0410-b094-e92efae38249

snd_main.c

index 6ea262f64f4051755708edbdff9ee8f34dbde16a..e6eb7699cd49cb6361dba6f235480b0340b75567 100644 (file)
@@ -1394,7 +1394,19 @@ void SND_Spatialize(channel_t *ch, qboolean isstatic)
 
 void S_PlaySfxOnChannel (sfx_t *sfx, channel_t *target_chan, unsigned int flags, vec3_t origin, float fvol, float attenuation, qboolean isstatic)
 {
+       if (!sfx)
+       {
+               Con_Printf("S_PlaySfxOnChannel called with NULL??\n");
+               return;
+       }
        // Initialize the channel
+       // a crash was reported on an in-use channel, so check here...
+       if (target_chan->sfx)
+       {
+               int channelindex = (int)(target_chan - channels);
+               Con_Printf("S_PlaySfxOnChannel(%s): channel %i already in use??  Clearing.\n", sfx->name, channelindex);
+               S_StopChannel (channelindex, true);
+       }
        // We MUST set sfx LAST because otherwise we could crash a threaded mixer
        // (otherwise we'd have to call SndSys_LockRenderBuffer here)
        memset (target_chan, 0, sizeof (*target_chan));