From 80c996a48c7b35cb459379ef7183e8cd96a484bb Mon Sep 17 00:00:00 2001 From: Benjamin Kraft Date: Mon, 16 Jan 2023 20:40:56 +0100 Subject: [PATCH] fix memory leak --- src/Game.cpp | 8 ++++---- src/Game.h | 2 +- src/Window.cpp | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Game.cpp b/src/Game.cpp index af2c773..78a717f 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -1,10 +1,10 @@ #include #include "Game.h" -void Game::draw(QPixmap *output) { - QPainter p(output); - double w = output->size().width(); - double h = output->size().height(); +void Game::draw(QPixmap &output) { + QPainter p(&output); + double w = output.size().width(); + double h = output.size().height(); p.fillRect(w / 2 - 10, h / 2 - 10, 20, 20, Qt::red); p.drawEllipse(0, 0, 20, 20); } diff --git a/src/Game.h b/src/Game.h index 03db710..28b3d99 100644 --- a/src/Game.h +++ b/src/Game.h @@ -6,5 +6,5 @@ class Game { GameQueue * eventQueue = new GameQueue; public: - void draw(QPixmap * output); + void draw(QPixmap & output); }; diff --git a/src/Window.cpp b/src/Window.cpp index 9e77cac..0e03a56 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -12,10 +12,10 @@ Window::Window() { } void Window::paintEvent(QPaintEvent *event) { - auto output = new QPixmap(label->size()); - output->fill(Qt::white); + QPixmap output(label->size()); + output.fill(Qt::white); game.draw(output); - label->setPixmap(*output); + label->setPixmap(output); } void Window::resizeEvent(QResizeEvent *e) {