From c7da189263a9479265d032c2f8cef0c04f086890 Mon Sep 17 00:00:00 2001 From: havoc Date: Sun, 12 Apr 2009 23:22:57 +0000 Subject: [PATCH] added safety checks in S_PlaySfxOnChannel due to a report of a crash 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 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/snd_main.c b/snd_main.c index 6ea262f6..e6eb7699 100644 --- a/snd_main.c +++ b/snd_main.c @@ -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)); -- 2.39.2