Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix std::bad_alloc() in WaveformRenderBeat::draw() #4789

Merged
merged 3 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/engine/controls/enginecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ EngineControl::EngineControl(const QString& group,
m_pConfig(pConfig),
m_pEngineMaster(nullptr),
m_pEngineBuffer(nullptr) {
setCurrentSample(EngineBuffer::kInitalSamplePosition, 0.0, 0.0);
setCurrentSample(EngineBuffer::kInitialSamplePosition, 0.0, 0.0);
}

EngineControl::~EngineControl() {
Expand Down
15 changes: 10 additions & 5 deletions src/engine/enginebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ EngineBuffer::EngineBuffer(const QString& group,
m_pKeyControl(nullptr),
m_pReadAheadManager(nullptr),
m_pReader(nullptr),
m_filepos_play(kInitalSamplePosition),
m_filepos_play(kInitialSamplePosition),
m_speed_old(0),
m_tempo_ratio_old(1.),
m_scratching_old(false),
Expand Down Expand Up @@ -513,7 +513,7 @@ void EngineBuffer::slotTrackLoaded(TrackPointer pTrack,

m_pause.lock();
m_visualPlayPos->setInvalid();
m_filepos_play = kInitalSamplePosition; // for execute seeks to 0.0
m_filepos_play = kInitialSamplePosition; // for execute seeks to 0.0
m_pCurrentTrack = pTrack;
m_pTrackSamples->set(iTrackNumSamples);
m_pTrackSampleRate->set(iTrackSampleRate);
Expand Down Expand Up @@ -1242,11 +1242,16 @@ void EngineBuffer::postProcess(const int iBufferSize) {
}

void EngineBuffer::updateIndicators(double speed, int iBufferSize) {
if (m_trackSampleRateOld == 0) {
// This happens if Deck Passthrough is active but no track is loaded.
// We skip indicator updates.
if (m_filepos_play == kInitialSamplePosition || m_trackSampleRateOld == 0) {
uklotzde marked this conversation as resolved.
Show resolved Hide resolved
// Skip indicator updates with invalid values to prevent undefined behavior,
// e.g. in WaveformRenderBeat::draw().
//
// This is known to happen if Deck Passthrough is active, when either no
// track is loaded or a track was loaded but processSeek() has not been
// called yet.
return;
}
DEBUG_ASSERT(m_tempo_ratio_old != 0);

// Increase samplesCalculated by the buffer size
m_iSamplesSinceLastIndicatorUpdate += iBufferSize;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/enginebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class EngineBuffer : public EngineObject {
// This value is used to make sure the initial seek after loading a track is
// not omitted. Therefore this value must be different for 0.0 or any likely
// value for the main cue
static constexpr double kInitalSamplePosition = -DBL_MAX;
static constexpr double kInitialSamplePosition = -DBL_MAX;

EngineBuffer(const QString& group, UserSettingsPointer pConfig,
EngineChannel* pChannel, EngineMaster* pMixingEngine);
Expand Down