From 0b72fabadec642dcecfe861c56dfeddb0c82a898 Mon Sep 17 00:00:00 2001 From: scratko Date: Thu, 21 Nov 2024 00:42:10 +0300 Subject: Fixed memory leak The image widget is responsible for deleting the loaded part of the image Check for correct type of selected file Error checking after image upload --- puzzle.hpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'puzzle.hpp') diff --git a/puzzle.hpp b/puzzle.hpp index e44efd4..9b01cc6 100644 --- a/puzzle.hpp +++ b/puzzle.hpp @@ -4,12 +4,13 @@ #include #include #include +#include #include #include #include enum { - puzzle_pieces = 9, + puzzle_pieces = 9, // including empty puzzle puzzles_per_side = 3, puzzle_size = 100, spacing = 5 @@ -19,8 +20,12 @@ class Puzzle : public Fl_Button{ public: unsigned char sequence_number; std::string path; + Fl_PNG_Image *stored_img_pointer; Puzzle(int x, int y) - : Fl_Button(x, y, puzzle_size, puzzle_size) {} + : Fl_Button(x, y, puzzle_size, puzzle_size), + stored_img_pointer(nullptr) { + } + ~Puzzle() { delete stored_img_pointer; } }; class GameParams { @@ -40,7 +45,9 @@ private: Fl_Window *win; std::string cur_directory; - GameParams(Fl_Window *a_win = nullptr) : win(a_win) {} + GameParams(Fl_Window *a_win = nullptr) + : win(a_win) + {} void CalculateStandardPuzzlePos(); void ResetFreePuzzles(); void NextUntestedPuzzles(); -- cgit v1.2.3