Skip to content

Commit

Permalink
Fix memory leaks (LMMS#6879)
Browse files Browse the repository at this point in the history
* Replace knobFModel with std::vector

* Create QPixmap's on the stack

* Assign parent for QGraphicsScene
A call to QGraphicsView::setScene does not make
the view take ownership of the scene.

* Do not allocate QList on the heap

* Use static QPixmap's
The QPixmap's need to be created within the constructor, and not outside
where they are defined, since it can't find them otherwise.
I'm not too sure why.

* Clear m_vi2->knobFModel in destructor

* Use local static QPixmap's

* Do not allocate QPixmap with new in AudioFileProcessor

* Do not allocate QPixmap with new in Nes

* Do not allocate QPixmap with new in Organic

* Do not allocate QPixmap with new in SaControlsDialog

* Do not allocate QPixmap with new in Vestige

* Do not allocate QPixmap with new for FileBrowser

* Do not allocate QPixmap with new in MixerLine

* Do not allocate QPixmap with new in SendButtonIndicator

* Do not allocate QPixmap with new in AutomationClipView

* Do not allocate QPixmap with new in MidiClipView

* Do not allocate QPixmap with new in AutomationEditor

* Do not allocate QPixmap with new in PianoRoll

* Do not allocate QPixmap with new in TimeLineWidget

* Do not allocate QPixmap with new in EnvelopeAndLfoView

* Do not allocate QPixmap with new in PianoView

* Do not allocate QPixmap with new in ComboBox

* Do not allocate QPixmap with new in Fader

* Do not allocate QPixmap with new for LcdWidget

* Do not allocate QPixmap with new for LedCheckbox

* Use m_ as prefix for members

* Use uniform initialization
I already started using uniform initialization for the QPixmap changes
for some reason, so I'm finishing that up.

* Uniform initiaization

* And then he realized he was making copies...

* Do not call QPixmap copy constructor

* Do not call QPixmap copy constructor in SaControlsDialog

* Do not make pixmap's static for Lcd's and Led's

* Initialize pixmaps in-class

* Fix few mistakes and formatting
  • Loading branch information
sakertooth authored Nov 19, 2023
1 parent fad0011 commit aa050ae
Show file tree
Hide file tree
Showing 43 changed files with 289 additions and 729 deletions.
3 changes: 0 additions & 3 deletions include/AutomationClipView.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ protected slots:
QPixmap m_paintPixmap;

QStaticText m_staticTextName;

static QPixmap * s_clip_rec;

void scaleTimemapToFit( float oldMin, float oldMax );
} ;

Expand Down
14 changes: 7 additions & 7 deletions include/AutomationEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ protected slots:
AutomationEditor( const AutomationEditor & );
~AutomationEditor() override;

static QPixmap * s_toolDraw;
static QPixmap * s_toolErase;
static QPixmap * s_toolDrawOut;
static QPixmap * s_toolEditTangents;
static QPixmap * s_toolMove;
static QPixmap * s_toolYFlip;
static QPixmap * s_toolXFlip;
QPixmap m_toolDraw = embed::getIconPixmap("edit_draw");
QPixmap m_toolErase = embed::getIconPixmap("edit_erase");
QPixmap m_toolDrawOut = embed::getIconPixmap("edit_draw_outvalue");
QPixmap m_toolEditTangents = embed::getIconPixmap("edit_tangent");
QPixmap m_toolMove = embed::getIconPixmap("edit_move");
QPixmap m_toolYFlip = embed::getIconPixmap("flip_y");
QPixmap m_toolXFlip = embed::getIconPixmap("flip_x");

ComboBoxModel m_zoomingXModel;
ComboBoxModel m_zoomingYModel;
Expand Down
6 changes: 3 additions & 3 deletions include/ComboBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public slots:


private:
static QPixmap* s_background;
static QPixmap* s_arrow;
static QPixmap* s_arrowSelected;
QPixmap m_background = embed::getIconPixmap("combobox_bg");
QPixmap m_arrow = embed::getIconPixmap("combobox_arrow");
QPixmap m_arrowSelected = embed::getIconPixmap("combobox_arrow_selected");

QMenu m_menu;

Expand Down
5 changes: 3 additions & 2 deletions include/EnvelopeAndLfoView.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <QWidget>

#include "ModelView.h"
#include "embed.h"

class QPaintEvent;
class QPixmap;
Expand Down Expand Up @@ -71,8 +72,8 @@ protected slots:


private:
static QPixmap * s_envGraph;
static QPixmap * s_lfoGraph;
QPixmap m_envGraph = embed::getIconPixmap("envelope_graph");
QPixmap m_lfoGraph = embed::getIconPixmap("lfo_graph");

EnvelopeAndLfoParameters * m_params;

Expand Down
13 changes: 5 additions & 8 deletions include/Fader.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@


#include "AutomatableModelView.h"
#include "embed.h"


namespace lmms::gui
Expand Down Expand Up @@ -131,7 +132,7 @@ class LMMS_EXPORT Fader : public QWidget, public FloatModelView
float fRange = model()->maxValue() - model()->minValue();
float realVal = model()->value() - model()->minValue();

return height() - ( ( height() - m_knob->height() ) * ( realVal / fRange ) );
return height() - ((height() - m_knob.height()) * (realVal / fRange));
}

void setPeak( float fPeak, float &targetPeak, float &persistentPeak, QElapsedTimer &lastPeakTimer );
Expand All @@ -151,13 +152,9 @@ class LMMS_EXPORT Fader : public QWidget, public FloatModelView
QElapsedTimer m_lastPeakTimer_L;
QElapsedTimer m_lastPeakTimer_R;

static QPixmap * s_back;
static QPixmap * s_leds;
static QPixmap * s_knob;

QPixmap * m_back;
QPixmap * m_leds;
QPixmap * m_knob;
QPixmap m_back = embed::getIconPixmap("fader_background");
QPixmap m_leds = embed::getIconPixmap("fader_leds");
QPixmap m_knob = embed::getIconPixmap("fader_knob");

bool m_levelsDisplayedInDBFS;

Expand Down
17 changes: 4 additions & 13 deletions include/FileBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QCheckBox>
#include <QDir>
#include <QMutex>
#include "embed.h"

#include "FileBrowserSearcher.h"
#include <QProgressBar>
Expand Down Expand Up @@ -221,14 +222,12 @@ class Directory : public QTreeWidgetItem


private:
void initPixmaps();

bool addItems( const QString & path );


static QPixmap * s_folderPixmap;
static QPixmap * s_folderOpenedPixmap;
static QPixmap * s_folderLockedPixmap;
QPixmap m_folderPixmap = embed::getIconPixmap("folder");
QPixmap m_folderOpenedPixmap = embed::getIconPixmap("folder_opened");
QPixmap m_folderLockedPixmap = embed::getIconPixmap("folder_locked");

//! Directories that lead here
//! Initially, this is just set to the current path of a directory
Expand Down Expand Up @@ -305,14 +304,6 @@ class FileItem : public QTreeWidgetItem
void initPixmaps();
void determineFileType();

static QPixmap * s_projectFilePixmap;
static QPixmap * s_presetFilePixmap;
static QPixmap * s_sampleFilePixmap;
static QPixmap * s_soundfontFilePixmap;
static QPixmap * s_vstPluginFilePixmap;
static QPixmap * s_midiFilePixmap;
static QPixmap * s_unknownFilePixmap;

QString m_path;
FileType m_type;
FileHandling m_handling;
Expand Down
4 changes: 1 addition & 3 deletions include/LcdWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class LMMS_EXPORT LcdWidget : public QWidget
LcdWidget(int numDigits, const QString& style, QWidget* parent, const QString& name = QString(),
bool leadingZero = false);

~LcdWidget() override;

void setValue(int value);
void setValue(float value);
void setLabel(const QString& label);
Expand Down Expand Up @@ -98,7 +96,7 @@ public slots:
QString m_display;

QString m_label;
QPixmap* m_lcdPixmap;
QPixmap m_lcdPixmap;

QColor m_textColor;
QColor m_textShadowColor;
Expand Down
7 changes: 2 additions & 5 deletions include/LedCheckBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ class LMMS_EXPORT LedCheckBox : public AutomatableButton
LedColor _color = LedColor::Yellow,
bool legacyMode = true);

~LedCheckBox() override;


inline const QString & text()
{
return( m_text );
Expand All @@ -71,8 +68,8 @@ class LMMS_EXPORT LedCheckBox : public AutomatableButton


private:
QPixmap * m_ledOnPixmap;
QPixmap * m_ledOffPixmap;
QPixmap m_ledOnPixmap;
QPixmap m_ledOffPixmap;

QString m_text;

Expand Down
9 changes: 5 additions & 4 deletions include/MidiClipView.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <QStaticText>
#include "ClipView.h"
#include "embed.h"

namespace lmms
{
Expand Down Expand Up @@ -85,10 +86,10 @@ protected slots:


private:
static QPixmap * s_stepBtnOn0;
static QPixmap * s_stepBtnOn200;
static QPixmap * s_stepBtnOff;
static QPixmap * s_stepBtnOffLight;
QPixmap m_stepBtnOn0 = embed::getIconPixmap("step_btn_on_0");
QPixmap m_stepBtnOn200 = embed::getIconPixmap("step_btn_on_200");
QPixmap m_stepBtnOff = embed::getIconPixmap("step_btn_off");
QPixmap m_stepBtnOffLight = embed::getIconPixmap("step_btn_off_light");

MidiClip* m_clip;
QPixmap m_paintPixmap;
Expand Down
2 changes: 0 additions & 2 deletions include/MixerLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ class MixerLine : public QWidget
QColor m_strokeOuterInactive;
QColor m_strokeInnerActive;
QColor m_strokeInnerInactive;
static QPixmap * s_sendBgArrow;
static QPixmap * s_receiveBgArrow;
bool m_inRename;
QLineEdit * m_renameLineEdit;
QGraphicsView * m_view;
Expand Down
12 changes: 6 additions & 6 deletions include/PianoRoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,12 @@ protected slots:
static const int cm_scrollAmtHoriz = 10;
static const int cm_scrollAmtVert = 1;

static QPixmap * s_toolDraw;
static QPixmap * s_toolErase;
static QPixmap * s_toolSelect;
static QPixmap * s_toolMove;
static QPixmap * s_toolOpen;
static QPixmap* s_toolKnife;
QPixmap m_toolDraw = embed::getIconPixmap("edit_draw");
QPixmap m_toolErase = embed::getIconPixmap("edit_erase");
QPixmap m_toolSelect = embed::getIconPixmap("edit_select");
QPixmap m_toolMove = embed::getIconPixmap("edit_move");
QPixmap m_toolOpen = embed::getIconPixmap("automation");
QPixmap m_toolKnife = embed::getIconPixmap("edit_knife");

static std::array<KeyType, 12> prKeyOrder;

Expand Down
13 changes: 7 additions & 6 deletions include/PianoView.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "AutomatableModel.h"
#include "ModelView.h"
#include "embed.h"

namespace lmms
{
Expand Down Expand Up @@ -73,12 +74,12 @@ class PianoView : public QWidget, public ModelView
int getKeyHeight(int key_num) const;
IntModel *getNearestMarker(int key, QString* title = nullptr);

static QPixmap * s_whiteKeyPm;
static QPixmap * s_blackKeyPm;
static QPixmap * s_whiteKeyPressedPm;
static QPixmap * s_blackKeyPressedPm;
static QPixmap * s_whiteKeyDisabledPm;
static QPixmap * s_blackKeyDisabledPm;
QPixmap m_whiteKeyPm = embed::getIconPixmap("white_key");
QPixmap m_blackKeyPm = embed::getIconPixmap("black_key");
QPixmap m_whiteKeyPressedPm = embed::getIconPixmap("white_key_pressed");
QPixmap m_blackKeyPressedPm = embed::getIconPixmap("black_key_pressed");
QPixmap m_whiteKeyDisabledPm = embed::getIconPixmap("white_key_disabled");
QPixmap m_blackKeyDisabledPm = embed::getIconPixmap("black_key_disabled");

Piano * m_piano;

Expand Down
5 changes: 3 additions & 2 deletions include/SendButtonIndicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define LMMS_GUI_SEND_BUTTON_INDICATOR_H

#include <QLabel>
#include "embed.h"


namespace lmms
Expand Down Expand Up @@ -53,8 +54,8 @@ class SendButtonIndicator : public QLabel

MixerLine * m_parent;
MixerView * m_mv;
static QPixmap * s_qpmOn;
static QPixmap * s_qpmOff;
QPixmap m_qpmOff = embed::getIconPixmap("mixer_send_off", 29, 20);
QPixmap m_qpmOn = embed::getIconPixmap("mixer_send_on", 29, 20);

FloatModel * getSendModel();
};
Expand Down
3 changes: 2 additions & 1 deletion include/TimeLineWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QWidget>

#include "Song.h"
#include "embed.h"


class QPixmap;
Expand Down Expand Up @@ -205,7 +206,7 @@ public slots:


private:
static QPixmap * s_posMarkerPixmap;
QPixmap m_posMarkerPixmap = embed::getIconPixmap("playpos_marker");

QColor m_inactiveLoopColor;
QBrush m_inactiveLoopBrush;
Expand Down
10 changes: 2 additions & 8 deletions plugins/AudioFileProcessor/AudioFileProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,19 +451,12 @@ namespace gui
{


QPixmap * AudioFileProcessorView::s_artwork = nullptr;


AudioFileProcessorView::AudioFileProcessorView( Instrument * _instrument,
QWidget * _parent ) :
InstrumentViewFixedSize( _instrument, _parent )
{
if( s_artwork == nullptr )
{
s_artwork = new QPixmap( PLUGIN_NAME::getIconPixmap(
"artwork" ) );
}

m_openAudioFileButton = new PixmapButton( this );
m_openAudioFileButton->setCursor( QCursor( Qt::PointingHandCursor ) );
m_openAudioFileButton->move( 227, 72 );
Expand Down Expand Up @@ -649,7 +642,8 @@ void AudioFileProcessorView::paintEvent( QPaintEvent * )
{
QPainter p( this );

p.drawPixmap( 0, 0, *s_artwork );
static auto s_artwork = PLUGIN_NAME::getIconPixmap("artwork");
p.drawPixmap(0, 0, s_artwork);

auto a = castModel<AudioFileProcessor>();

Expand Down
1 change: 0 additions & 1 deletion plugins/AudioFileProcessor/AudioFileProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ protected slots:
private:
virtual void modelChanged();

static QPixmap * s_artwork;

AudioFileProcessorWaveView * m_waveView;
Knob * m_ampKnob;
Expand Down
16 changes: 8 additions & 8 deletions plugins/Eq/EqControlsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ EqControlsDialog::EqControlsDialog( EqControls *controls ) :
setBand( 6, &controls->m_highShelfActiveModel, &controls->m_highShelfFreqModel, &controls->m_highShelfResModel, &controls->m_highShelfGainModel, QColor(255 ,255, 255), tr( "High-shelf" ), &controls->m_highShelfPeakL, &controls->m_highShelfPeakR,0,0,0,0,0,0 );
setBand( 7, &controls->m_lpActiveModel, &controls->m_lpFreqModel, &controls->m_lpResModel, 0, QColor(255 ,255, 255), tr( "LP" ) ,0,0,0,0,0, &controls->m_lp12Model, &controls->m_lp24Model, &controls->m_lp48Model);

auto faderBg = new QPixmap(PLUGIN_NAME::getIconPixmap("faderback"));
auto faderLeds = new QPixmap(PLUGIN_NAME::getIconPixmap("faderleds"));
auto faderKnob = new QPixmap(PLUGIN_NAME::getIconPixmap("faderknob"));
static auto s_faderBg = PLUGIN_NAME::getIconPixmap("faderback");
static auto s_faderLeds = PLUGIN_NAME::getIconPixmap("faderleds");
static auto s_faderKnob = PLUGIN_NAME::getIconPixmap("faderknob");

auto GainFaderIn = new EqFader(&controls->m_inGainModel, tr("Input gain"), this, faderBg, faderLeds, faderKnob,
auto GainFaderIn = new EqFader(&controls->m_inGainModel, tr("Input gain"), this, &s_faderBg, &s_faderLeds, &s_faderKnob,
&controls->m_inPeakL, &controls->m_inPeakR);
GainFaderIn->move( 23, 295 );
GainFaderIn->setDisplayConversion( false );
GainFaderIn->setHintText( tr( "Gain" ), "dBv");

auto GainFaderOut = new EqFader(&controls->m_outGainModel, tr("Output gain"), this, faderBg, faderLeds, faderKnob,
auto GainFaderOut = new EqFader(&controls->m_outGainModel, tr("Output gain"), this, &s_faderBg, &s_faderLeds, &s_faderKnob,
&controls->m_outPeakL, &controls->m_outPeakR);
GainFaderOut->move( 453, 295);
GainFaderOut->setDisplayConversion( false );
Expand All @@ -92,8 +92,8 @@ EqControlsDialog::EqControlsDialog( EqControls *controls ) :
int distance = 126;
for( int i = 1; i < m_parameterWidget->bandCount() - 1; i++ )
{
auto gainFader = new EqFader(m_parameterWidget->getBandModels(i)->gain, tr(""), this, faderBg, faderLeds,
faderKnob, m_parameterWidget->getBandModels(i)->peakL, m_parameterWidget->getBandModels(i)->peakR);
auto gainFader = new EqFader(m_parameterWidget->getBandModels(i)->gain, tr(""), this, &s_faderBg, &s_faderLeds,
&s_faderKnob, m_parameterWidget->getBandModels(i)->peakL, m_parameterWidget->getBandModels(i)->peakR);
gainFader->move( distance, 295 );
distance += 44;
gainFader->setMinimumHeight(80);
Expand Down Expand Up @@ -242,4 +242,4 @@ EqBand* EqControlsDialog::setBand(int index, BoolModel* active, FloatModel* freq
}


} // namespace lmms::gui
} // namespace lmms::gui
Loading

0 comments on commit aa050ae

Please sign in to comment.