summaryrefslogtreecommitdiffstats
path: root/src/imports/audioengine
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2015-04-11 23:17:18 +0400
committerKonstantin Ritt <ritt.ks@gmail.com>2015-04-13 10:00:56 +0000
commitfe1046794da6e547148bae9d384fafbb60e80304 (patch)
treecc943218cb6a6b4ca82aa586be01c4088c854ab1 /src/imports/audioengine
parent37d5b53faec7df4c4ca673599165c272848200fb (diff)
[AudioEngine] Do not crash on destruction after sample loading error
m_sampleLoader must be destroyed AFTER releasing the buffers it holds. Also properly release sample on error and be safer while destroying the buffer. Change-Id: I5e39c6c815b8760f72cc5fdc61fad020d3cd1cc1 Reviewed-by: Yoann Lopes <yoann.lopes@theqtcompany.com>
Diffstat (limited to 'src/imports/audioengine')
-rw-r--r--src/imports/audioengine/qaudioengine_openal_p.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/imports/audioengine/qaudioengine_openal_p.cpp b/src/imports/audioengine/qaudioengine_openal_p.cpp
index 9afdcb47d..0a34a6b03 100644
--- a/src/imports/audioengine/qaudioengine_openal_p.cpp
+++ b/src/imports/audioengine/qaudioengine_openal_p.cpp
@@ -89,7 +89,12 @@ public:
{
if (m_sample)
m_sample->release();
- alDeleteBuffers(1, &m_alBuffer);
+
+ if (m_alBuffer != 0) {
+ alGetError(); // clear error
+ alDeleteBuffers(1, &m_alBuffer);
+ QAudioEnginePrivate::checkNoError("delete buffer");
+ }
}
void bindToSource(ALuint alSource)
@@ -160,25 +165,34 @@ public Q_SLOTS:
alGenBuffers(1, &m_alBuffer);
if (!QAudioEnginePrivate::checkNoError("create buffer")) {
+ decoderError();
return;
}
alBufferData(m_alBuffer, alFormat, m_sample->data().data(),
m_sample->data().size(), m_sample->format().sampleRate());
if (!QAudioEnginePrivate::checkNoError("fill buffer")) {
+ decoderError();
return;
}
- m_isReady = true;
- emit ready();
m_sample->release();
m_sample = 0;
+
+ m_isReady = true;
+ emit ready();
}
void decoderError()
{
qWarning() << "loading [" << m_url << "] failed";
+
disconnect(m_sample, SIGNAL(error()), this, SLOT(decoderError()));
+ disconnect(m_sample, SIGNAL(ready()), this, SLOT(sampleReady()));
+
+ m_sample->release();
+ m_sample = 0;
+
emit error();
}
@@ -245,7 +259,6 @@ QAudioEnginePrivate::~QAudioEnginePrivate()
#ifdef DEBUG_AUDIOENGINE
qDebug() << "QAudioEnginePrivate::dtor";
#endif
- delete m_sampleLoader;
QObjectList children = this->children();
foreach (QObject *child, children) {
QSoundSourcePrivate* s = qobject_cast<QSoundSourcePrivate*>(child);
@@ -259,6 +272,8 @@ QAudioEnginePrivate::~QAudioEnginePrivate()
}
m_staticBufferPool.clear();
+ delete m_sampleLoader;
+
ALCcontext* context = alcGetCurrentContext();
ALCdevice *device = alcGetContextsDevice(context);
alcDestroyContext(context);