Skip to content

Potential fixes for 4 code quality findings#3702

Draft
ann0see wants to merge 4 commits into
mainfrom
ai-findings-autofix/src-clientdlg.cpp
Draft

Potential fixes for 4 code quality findings#3702
ann0see wants to merge 4 commits into
mainfrom
ai-findings-autofix/src-clientdlg.cpp

Conversation

@ann0see
Copy link
Copy Markdown
Member

@ann0see ann0see commented May 20, 2026

This PR applies 4/4 suggestions from code quality AI findings.

Only for review. We should then decide if we actually have a memory leak here.

ann0see and others added 4 commits May 20, 2026 20:24
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@ann0see
Copy link
Copy Markdown
Member Author

ann0see commented May 20, 2026

I don't think everything here is valid.

Comment thread src/clientdlg.cpp
Comment on lines +859 to +861
QSoundEffect sf;
sf.setSource ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_message.wav" ) );
sf.play();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This may be valid. Stack vs heap allocation?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

-> memory leak

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No this won't work. The original does indeed have a memory leak, as the pointer returned from new QSoundEffect() is only local, and disappears at the end of the block. But I think changing it so that the QSoundEffect sf is allocated locally on the stack may cause a crash, or at least truncate the playback, as the object will be destroyed immediately at the end of the block while the sound is still playing.

The correct solution is actually the one shown below around line 910: connect a lambda to the playingChanged signal and call deleteLater() when it is finished with.

Comment thread src/clientdlg.cpp
Comment on lines 1449 to 1458
case MT_BAR_NARROW:
lbrInputLevelL->SetLevelMeterType ( CLevelMeter::MT_BAR_WIDE );
lbrInputLevelR->SetLevelMeterType ( CLevelMeter::MT_BAR_WIDE );
lbrInputLevelL->SetLevelMeterType ( CLevelMeter::MT_BAR_NARROW );
lbrInputLevelR->SetLevelMeterType ( CLevelMeter::MT_BAR_NARROW );
break;

case MT_LED_ROUND_SMALL:
lbrInputLevelL->SetLevelMeterType ( CLevelMeter::MT_LED_ROUND_BIG );
lbrInputLevelR->SetLevelMeterType ( CLevelMeter::MT_LED_ROUND_BIG );
lbrInputLevelL->SetLevelMeterType ( CLevelMeter::MT_LED_ROUND_SMALL );
lbrInputLevelR->SetLevelMeterType ( CLevelMeter::MT_LED_ROUND_SMALL );
break;
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Unsure about those.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See 3117acd in #2356 from @henkdegroot

I think the point is that when narrow/small is selected, it should only apply to the mixer channel meters. The above lines refer to the input meters, which need to remain wide with big LEDs, even in narrow mixer mode.

It would be worth adding explanatory comments to that effect, to forestall future confusion.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suggest the following for the whole function:

void CClientDlg::SetMeterStyle ( const EMeterStyle eNewMeterStyle )
{
    // apply MeterStyle to current window
    // Note: input meter uses big LED and wide bar even in narrow mode
    switch ( eNewMeterStyle )
    {
    case MT_LED_STRIPE:
        lbrInputLevelL->SetLevelMeterType ( CLevelMeter::MT_LED_STRIPE );
        lbrInputLevelR->SetLevelMeterType ( CLevelMeter::MT_LED_STRIPE );
        break;

    case MT_LED_ROUND_BIG:
    case MT_LED_ROUND_SMALL:
        lbrInputLevelL->SetLevelMeterType ( CLevelMeter::MT_LED_ROUND_BIG );
        lbrInputLevelR->SetLevelMeterType ( CLevelMeter::MT_LED_ROUND_BIG );
        break;

    case MT_BAR_WIDE:
    case MT_BAR_NARROW:
        lbrInputLevelL->SetLevelMeterType ( CLevelMeter::MT_BAR_WIDE );
        lbrInputLevelR->SetLevelMeterType ( CLevelMeter::MT_BAR_WIDE );
        break;

    }

    // also apply MeterStyle to child GUI controls
    MainMixerBoard->SetMeterStyle ( eNewMeterStyle );
}

@ann0see ann0see requested review from pljones and softins May 20, 2026 18:56
Comment thread src/clientdlg.cpp
Comment on lines +859 to +861
QSoundEffect sf;
sf.setSource ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_message.wav" ) );
sf.play();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No this won't work. The original does indeed have a memory leak, as the pointer returned from new QSoundEffect() is only local, and disappears at the end of the block. But I think changing it so that the QSoundEffect sf is allocated locally on the stack may cause a crash, or at least truncate the playback, as the object will be destroyed immediately at the end of the block while the sound is still playing.

The correct solution is actually the one shown below around line 910: connect a lambda to the playingChanged signal and call deleteLater() when it is finished with.

Comment thread src/clientdlg.cpp
Comment on lines +910 to +917
QSoundEffect* sf = new QSoundEffect ( this );
connect ( sf, &QSoundEffect::playingChanged, this, [sf]()
{
if ( !sf->isPlaying() )
{
sf->deleteLater();
}
} );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks ok and is the correct way to avoid the memory leak.

Comment thread src/clientdlg.cpp
Comment on lines 1449 to 1458
case MT_BAR_NARROW:
lbrInputLevelL->SetLevelMeterType ( CLevelMeter::MT_BAR_WIDE );
lbrInputLevelR->SetLevelMeterType ( CLevelMeter::MT_BAR_WIDE );
lbrInputLevelL->SetLevelMeterType ( CLevelMeter::MT_BAR_NARROW );
lbrInputLevelR->SetLevelMeterType ( CLevelMeter::MT_BAR_NARROW );
break;

case MT_LED_ROUND_SMALL:
lbrInputLevelL->SetLevelMeterType ( CLevelMeter::MT_LED_ROUND_BIG );
lbrInputLevelR->SetLevelMeterType ( CLevelMeter::MT_LED_ROUND_BIG );
lbrInputLevelL->SetLevelMeterType ( CLevelMeter::MT_LED_ROUND_SMALL );
lbrInputLevelR->SetLevelMeterType ( CLevelMeter::MT_LED_ROUND_SMALL );
break;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See 3117acd in #2356 from @henkdegroot

I think the point is that when narrow/small is selected, it should only apply to the mixer channel meters. The above lines refer to the input meters, which need to remain wide with big LEDs, even in narrow mixer mode.

It would be worth adding explanatory comments to that effect, to forestall future confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants