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
3 changes: 2 additions & 1 deletion src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,13 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE, _In_ PSTR, _In_
Clock clock;
double frametime = 1.0;
MSG msg = { 0 };
while(msg.message!=WM_QUIT) {
while(msg.message!=WM_QUIT && running) {
while(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
if(msg.message==WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if(!running) break;
// main loop ################################################################
camera.rendring_frame.lock(); // block rendering for other threads until finished
camera.update_state(fmax(1.0/(double)camera.fps_limit, frametime));
Expand Down
2 changes: 1 addition & 1 deletion src/graphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Camera {
case '+': input_scroll_down(); break;
case '-': input_scroll_up(); break;
case 'F': input_F(); break;
case 27: running=false; println(); exit(0);
case 27: running=false; break; // signal threads to exit cleanly (don't call exit() - causes heap corruption)
}
#ifdef INTERACTIVE_GRAPHICS_ASCII
if(free) { // move free camera
Expand Down
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ void main_physics() {
info.print_logo();
main_setup(); // execute setup
running = false;
exit(0); // make sure that the program stops
// Don't call exit(0) here - let main thread join and exit cleanly
// exit(0) causes heap corruption due to race conditions with other threads
}

#ifndef GRAPHICS
Expand Down