From fd321588613472dfb31659f56961ffb0cbf9eb27 Mon Sep 17 00:00:00 2001 From: cyberrumor <46626673+cyberrumor@users.noreply.github.com> Date: Wed, 19 Mar 2025 10:23:53 -0700 Subject: [PATCH] Fix crash when switching opened projects (#7797) * Fix crash when switching opened projects #7793 When the DAW is already running with an open project and you attempt to open another project via File > Open, a segfault used to occur. The crash seems to have been caused by model()->value(), which was called in Fader::getModelValueAsDbString(). The model() function looked like it should return a pointer to an AutomatableModel. I suspect that when a model was dropped in favor of loading models for a new project, the AutomatableModel pointer became a null pointer. Add a check to the AutomatableModel pointer so getModelValueAsDbString returns early (before accessing member functions) if the pointer is null. This fixes the crash. --- src/gui/widgets/Fader.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gui/widgets/Fader.cpp b/src/gui/widgets/Fader.cpp index 153d8ca1a..61e6e753d 100644 --- a/src/gui/widgets/Fader.cpp +++ b/src/gui/widgets/Fader.cpp @@ -512,9 +512,16 @@ void Fader::modelValueChanged() QString Fader::getModelValueAsDbString() const { - const auto value = model()->value(); - QString label(tr("Volume: %1 dB")); + // Check that the pointer isn't dangling, which can happen if the + // model was dropped in order to load a new project from an existing one. + auto* newModel = model(); + if (!newModel) + { + // model() was a dangling pointer, so return a sane default value. + return label.arg(tr("-inf")); + } + const auto value = newModel->value(); if (modelIsLinear()) {