From af3ad484550ac0c6cd09e528cc9acd2725d355fa Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Thu, 1 Oct 2015 14:21:21 -0500 Subject: [PATCH] Attempting to fix a race condition when edits are being made to the timeline while frames are being cached and played back. This seems to fix the crashes for me. =) --- src/AudioReaderSource.cpp | 9 ++++++--- src/RendererBase.cpp | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/AudioReaderSource.cpp b/src/AudioReaderSource.cpp index c054b8c8..aceb14f4 100644 --- a/src/AudioReaderSource.cpp +++ b/src/AudioReaderSource.cpp @@ -99,7 +99,9 @@ void AudioReaderSource::GetMoreSamplesFromReader() } bool frame_completed = false; - int amount_to_copy = frame->GetAudioSamplesCount() - frame_position; + int amount_to_copy = 0; + if (frame) + amount_to_copy = frame->GetAudioSamplesCount() - frame_position; if (amount_to_copy > amount_needed) { // Don't copy too many samples (we don't want to overflow the buffer) amount_to_copy = amount_needed; @@ -111,8 +113,9 @@ void AudioReaderSource::GetMoreSamplesFromReader() } // Load all of its samples into the buffer - for (int channel = 0; channel < new_buffer->getNumChannels(); channel++) - new_buffer->addFrom(channel, position, *frame->GetAudioSampleBuffer(), channel, frame_position, amount_to_copy); + if (frame) + for (int channel = 0; channel < new_buffer->getNumChannels(); channel++) + new_buffer->addFrom(channel, position, *frame->GetAudioSampleBuffer(), channel, frame_position, amount_to_copy); // Adjust remaining samples position += amount_to_copy; diff --git a/src/RendererBase.cpp b/src/RendererBase.cpp index 3027a498..50fb1572 100644 --- a/src/RendererBase.cpp +++ b/src/RendererBase.cpp @@ -38,5 +38,6 @@ RendererBase::~RendererBase() void RendererBase::paint(const std::tr1::shared_ptr & frame) { - this->render(frame->GetImage()); + if (frame) + this->render(frame->GetImage()); }