Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/desktop/noo_canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ NooCanvas::NooCanvas(NooFrame *frame): CANVAS_CLASS(frame, wxID_ANY, CANVAS_PARA
}

NooCanvas::~NooCanvas() {
#ifdef USE_GL_CANVAS
// Clean up OpenGL context to prevent crashes
if (context) {
SetCurrent(*context);
glFinish();
delete context;
}
#endif
// Free the framebuffer if it was allocated
if (frame->mainFrame)
delete[] framebuffer;
Expand Down
23 changes: 21 additions & 2 deletions src/desktop/noo_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,19 @@ NooFrame::NooFrame(NooApp *app, int id, std::string path, NooFrame *partner):
loadRomPath(path);
}

NooFrame::~NooFrame() {
// Clean up joystick and timer if they exist
if (timer) {
timer->Stop();
delete timer;
timer = nullptr;
}
if (joystick) {
delete joystick;
joystick = nullptr;
}
}

void NooFrame::Refresh() {
// Override the refresh function to also update the FPS counter
wxFrame::Refresh();
Expand Down Expand Up @@ -800,10 +813,16 @@ void NooFrame::dropFiles(wxDropFilesEvent &event) {
}

void NooFrame::close(wxCloseEvent &event) {
// Properly shut down the emulator
// Properly shut down the emulator and cleanup
(mainFrame ? this : partner)->stopCore(true);
app->removeFrame(id);
canvas->finish();
if (partner) delete partner;

// Clean up partner frame if it exists
if (partner) {
delete partner;
partner = nullptr;
}

event.Skip(true);
}
1 change: 1 addition & 0 deletions src/desktop/noo_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class NooFrame: public wxFrame {
bool running = false;

NooFrame(NooApp *app, int id = 0, std::string path = "", NooFrame *partner = nullptr);
~NooFrame();
void Refresh();

void startCore(bool full);
Expand Down