|
From: Lasse Kärkkäi. <tr...@us...> - 2009-09-06 15:44:00
|
Module: performous
Branch: master
Commit: 10cbeefe11764ee337b73212b93707ccd7f899f1
Author: Lasse Karkkainen <tro...@tr...>
Date: Sun Sep 6 18:41:45 2009 +0300
Proper mixer destruction order/cleanup, should avoid segfaults on exit.
---
game/audio.hh | 2 +-
libs/libda/include/libda/mixer.hpp | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/game/audio.hh b/game/audio.hh
index e7ed18e..6accaa4 100644
--- a/game/audio.hh
+++ b/game/audio.hh
@@ -105,8 +105,8 @@ class Audio {
Notes const* volatile m_notes;
da::settings m_rs;
da::volume m_volume;
+ std::string m_volumeSetting;
da::mixer m_mixer;
std::map<std::string,boost::shared_ptr<Stream> > m_streams;
- std::string m_volumeSetting;
};
diff --git a/libs/libda/include/libda/mixer.hpp b/libs/libda/include/libda/mixer.hpp
index 20915ce..a44946f 100644
--- a/libs/libda/include/libda/mixer.hpp
+++ b/libs/libda/include/libda/mixer.hpp
@@ -175,8 +175,13 @@ namespace da {
mutex_stream(callback_t const& stream): m_stream(stream) {}
bool operator()(pcm_data& data) {
scoped_lock l(*this);
+ if (!m_stream) return false;
return m_stream(data);
}
+ void clear() {
+ scoped_lock l(*this);
+ m_stream.clear();
+ }
private:
callback_t m_stream;
mutable boost::recursive_mutex m_mutex;
@@ -211,6 +216,12 @@ namespace da {
public:
mixer(): m_mutex(boost::ref(m_select)) { init(); }
mixer(settings& s): m_mutex(boost::ref(m_select)) { init(); start(s); }
+ ~mixer() {
+ // Make sure that all processing has stopped before exiting
+ scoped_lock l(m_mutex);
+ m_mutex.clear();
+ m_playback.reset();
+ }
void start(settings& s) { m_settings = s; start(); s = m_settings; }
void start() {
stop();
|