mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 02:33:37 +02:00
use a QPointer to trigger delayed delete
This commit is contained in:
parent
79674fb94f
commit
43e777163e
4 changed files with 15 additions and 1 deletions
libraries
audio/src
script-engine/src
|
@ -55,6 +55,12 @@ void AudioInjector::setIsFinished(bool isFinished) {
|
|||
|
||||
_isStarted = false;
|
||||
_shouldStop = false;
|
||||
|
||||
if (_shouldDeleteAfterFinish) {
|
||||
// we've been asked to delete after finishing, trigger a queued deleteLater here
|
||||
qDebug() << "triggering the delete since we are finished";
|
||||
QMetaObject::invokeMethod(this, "deleteLater", Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,9 @@ public:
|
|||
public slots:
|
||||
void injectAudio();
|
||||
void restart();
|
||||
|
||||
void stop();
|
||||
void triggerDeleteAfterFinish() { _shouldDeleteAfterFinish = true; }
|
||||
void stopAndDeleteLater();
|
||||
|
||||
void setOptions(AudioInjectorOptions& options) { _options = options; }
|
||||
|
@ -69,6 +71,7 @@ private:
|
|||
float _loudness = 0.0f;
|
||||
bool _isStarted = false;
|
||||
bool _isFinished = false;
|
||||
bool _shouldDeleteAfterFinish = false;
|
||||
int _currentSendPosition = 0;
|
||||
AbstractAudioInterface* _localAudioInterface = NULL;
|
||||
AudioInjectorLocalBuffer* _localBuffer = NULL;
|
||||
|
|
|
@ -29,6 +29,11 @@ ScriptAudioInjector::ScriptAudioInjector(AudioInjector* injector) :
|
|||
}
|
||||
|
||||
ScriptAudioInjector::~ScriptAudioInjector() {
|
||||
if (!_injector.isNull()) {
|
||||
// we've been asked to delete after finishing, trigger a queued deleteLater here
|
||||
QMetaObject::invokeMethod(_injector.data(), "triggerDeleteAfterFinish", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ScriptAudioInjector::stopInjectorImmediately() {
|
||||
|
|
|
@ -39,7 +39,7 @@ signals:
|
|||
protected slots:
|
||||
void stopInjectorImmediately();
|
||||
private:
|
||||
AudioInjector* _injector;
|
||||
QPointer<AudioInjector> _injector;
|
||||
|
||||
friend QScriptValue injectorToScriptValue(QScriptEngine* engine, ScriptAudioInjector* const& in);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue