From 92ef8cafb144f5b7e0b4343ae03502dc5b5ce3fd Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 28 Mar 2016 12:08:51 -0700 Subject: [PATCH] Make sure pos/rot getters don't crash --- interface/src/Application.cpp | 14 ++++++++++++-- libraries/audio-client/src/AudioClient.cpp | 7 ++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 7eb19557e5..13b8a565b4 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -598,8 +598,18 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : audioThread->setObjectName("Audio Thread"); auto audioIO = DependencyManager::get(); - audioIO->setPositionGetter([this]{ return getMyAvatar()->getPositionForAudio(); }); - audioIO->setOrientationGetter([this]{ return getMyAvatar()->getOrientationForAudio(); }); + audioIO->setPositionGetter([]{ + auto audioIO = DependencyManager::get(); + auto myAvatar = audioIO ? audioIO->getMyAvatar() : nullptr; + + return myAvatar ? myAvatar->getPositionForAudio() : Vectors::ZERO; + }); + audioIO->setOrientationGetter([]{ + auto audioIO = DependencyManager::get(); + auto myAvatar = audioIO ? audioIO->getMyAvatar() : nullptr; + + return myAvatar ? myAvatar->getOrientationForAudio() : Quaternions::IDENTITY; + }); audioIO->moveToThread(audioThread); recording::Frame::registerFrameHandler(AudioConstants::getAudioFrameName(), [=](recording::Frame::ConstPointer frame) { diff --git a/libraries/audio-client/src/AudioClient.cpp b/libraries/audio-client/src/AudioClient.cpp index 7e01196dc7..50e5b7591f 100644 --- a/libraries/audio-client/src/AudioClient.cpp +++ b/libraries/audio-client/src/AudioClient.cpp @@ -50,6 +50,9 @@ static const int RECEIVED_AUDIO_STREAM_CAPACITY_FRAMES = 100; +static const auto DEFAULT_POSITION_GETTER = []{ return Vectors::ZERO; }; +static const auto DEFAULT_ORIENTATION_GETTER = [] { return Quaternions::IDENTITY; }; + Setting::Handle dynamicJitterBuffers("dynamicJitterBuffers", DEFAULT_DYNAMIC_JITTER_BUFFERS); Setting::Handle maxFramesOverDesired("maxFramesOverDesired", DEFAULT_MAX_FRAMES_OVER_DESIRED); Setting::Handle staticDesiredJitterBufferFrames("staticDesiredJitterBufferFrames", @@ -103,7 +106,9 @@ AudioClient::AudioClient() : _outgoingAvatarAudioSequenceNumber(0), _audioOutputIODevice(_receivedAudioStream, this), _stats(&_receivedAudioStream), - _inputGate() + _inputGate(), + _positionGetter(DEFAULT_POSITION_GETTER), + _orientationGetter(DEFAULT_ORIENTATION_GETTER) { // clear the array of locally injected samples memset(_localProceduralSamples, 0, AudioConstants::NETWORK_FRAME_BYTES_PER_CHANNEL);