Skip to content

Commit

Permalink
Merge pull request #876 from 32blit/patch-sdl-thread-exit
Browse files Browse the repository at this point in the history
sdl: fix exiting while waiting for a render to be presented
  • Loading branch information
Daft-Freak authored Nov 26, 2024
2 parents b489112 + 953e153 commit db20fc7
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions 32blit-sdl/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,16 +445,19 @@ void System::set_button(int button, bool state) {
}

void System::stop() {
int returnValue;
running = false;
int returnValue;
running = false;

if(SDL_SemWaitTimeout(s_loop_ended, 500)) {
std::cerr << "User code appears to have frozen. Detaching thread." << std::endl;
SDL_DetachThread(t_system_loop);
} else {
SDL_WaitThread(t_system_loop, &returnValue);
}
// make sure the update thread is not waiting for a render to complete
SDL_SemPost(s_loop_redraw);

if(SDL_SemWaitTimeout(s_loop_ended, 500)) {
std::cerr << "User code appears to have frozen. Detaching thread." << std::endl;
SDL_DetachThread(t_system_loop);
} else {
SDL_WaitThread(t_system_loop, &returnValue);
}

SDL_SemPost(s_timer_stop);
SDL_WaitThread(t_system_timer, &returnValue);
SDL_SemPost(s_timer_stop);
SDL_WaitThread(t_system_timer, &returnValue);
}

0 comments on commit db20fc7

Please sign in to comment.