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: prevent null CO access when cloning sampler or preview #13740

Merged
merged 1 commit into from
Oct 10, 2024
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/channels/enginechannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class EngineChannel : public EngineObject {
void setTalkover(bool enabled);
virtual bool isTalkoverEnabled() const;
inline bool isTalkoverChannel() { return m_bIsTalkoverChannel; };
inline bool isPrimaryDeck() {
inline bool isPrimaryDeck() const {
return m_bIsPrimaryDeck;
};
int getChannelIndex() {
Expand Down
11 changes: 11 additions & 0 deletions src/engine/channels/enginedeck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "engine/enginevumeter.h"
#include "moc_enginedeck.cpp"
#include "track/track.h"
#include "util/assert.h"
#include "util/sample.h"

#ifdef __STEM__
Expand Down Expand Up @@ -206,6 +207,16 @@ void EngineDeck::cloneStemState(const EngineDeck* deckToClone) {
VERIFY_OR_DEBUG_ASSERT(deckToClone) {
return;
}
// Sampler and preview decks don't have stem controls
if (!isPrimaryDeck() || !deckToClone->isPrimaryDeck()) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The verify blow includes this check and sticks around at release time. So this check can be removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does but it's not equivalent.

Having the two vector empty is an expected case, for which we do an early return. The assert condition adds extra usecase that would crash the for-loop but are not expected usecase on which we should assert.

I agree that this would technically add couple of extra instructions at release time, but since this function is not time critical, I would suggest we keep the clear distinction between the early return on excepted usecase, and protective return on unexpected case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. How about replacing the first loop by
If (isPrimaryDeck())?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds much cleaner indeed. Updated.

VERIFY_OR_DEBUG_ASSERT(m_stemGain.size() == kMaxSupportedStems &&
m_stemMute.size() == kMaxSupportedStems &&
deckToClone->m_stemGain.size() == kMaxSupportedStems &&
deckToClone->m_stemMute.size() == kMaxSupportedStems) {
return;
}
for (int stemIdx = 0; stemIdx < kMaxSupportedStems; stemIdx++) {
m_stemGain[stemIdx]->set(deckToClone->m_stemGain[stemIdx]->get());
m_stemMute[stemIdx]->set(deckToClone->m_stemMute[stemIdx]->get());
Expand Down
Loading