Backport a patch from svn r4546 to fix a crash when sound device is busy,

cf https://gna.org/bugs/index.php?11754

ok ajacoutot@
This commit is contained in:
landry 2008-05-30 11:40:24 +00:00
parent 3fbd9cc177
commit 05f00f6726
2 changed files with 51 additions and 1 deletions

View File

@ -1,8 +1,9 @@
# $OpenBSD: Makefile,v 1.5 2008/05/28 18:44:32 landry Exp $
# $OpenBSD: Makefile,v 1.6 2008/05/30 11:40:24 landry Exp $
COMMENT= free software clone of Worms(R) game concept
DISTNAME= wormux-0.8
PKGNAME= ${DISTNAME}p0
CATEGORIES= games
HOMEPAGE= http://wormux.org

View File

@ -0,0 +1,49 @@
$OpenBSD: patch-src_sound_jukebox_cpp,v 1.1 2008/05/30 11:40:24 landry Exp $
--- src/sound/jukebox.cpp.orig Fri May 16 00:47:19 2008
+++ src/sound/jukebox.cpp Fri May 30 11:05:52 2008
@@ -154,6 +154,9 @@ void JukeBox::ActiveMusic (bool on)
void JukeBox::LoadMusicXML()
{
+ if (!m_init) // the sound device has not be initialized (was busy?)
+ return;
+
// is xml_file already loaded ?
std::set<std::string>::iterator it_profile = m_profiles_loaded.find("music") ;
if (it_profile != m_profiles_loaded.end())
@@ -327,6 +330,9 @@ bool JukeBox::PlayMusicSample(const std::vector<std::s
void JukeBox::LoadXML(const std::string& profile)
{
+ if (!m_init) // the sound device has not be initialized (was busy?)
+ return;
+
// is xml_file already loaded ?
std::set<std::string>::iterator it_profile = m_profiles_loaded.find(profile);
if (it_profile != m_profiles_loaded.end())
@@ -390,7 +396,7 @@ void JukeBox::LoadXML(const std::string& profile)
int JukeBox::Play (const std::string& category, const std::string& sample,
const int loop)
{
- if (!UseEffects()) return -1;
+ if (!UseEffects() || !m_init) return -1;
uint nb_sons= m_soundsamples.count(category+"/"+sample);
if (nb_sons)
@@ -429,13 +435,15 @@ int JukeBox::Play (const std::string& category, const
int JukeBox::Stop (int channel) const
{
- if(!m_config.music && !m_config.effects) return 0;
+ if (!m_init) return 0;
+ if (!m_config.music && !m_config.effects) return 0;
if (channel == -1) return 0;
return Mix_HaltChannel(channel);
}
int JukeBox::StopAll() const
{
+ if (!m_init) return 0;
if (!m_config.music && !m_config.effects) return 0;
// halt playback on all channels