From 0055de4245af5518ad9f66d7a919fcd349bdd86a Mon Sep 17 00:00:00 2001 From: Andrei Alexeyev Date: Sat, 2 Oct 2021 01:55:29 +0300 Subject: [PATCH] camcontrol: add cleanup This is mostly to fix an annoying assertion failure that pops up when quitting the game or restarting the stage. --- src/camcontrol.c | 10 ++++++++++ src/camcontrol.h | 3 +-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/camcontrol.c b/src/camcontrol.c index 2bd24d14..0973af94 100644 --- a/src/camcontrol.c +++ b/src/camcontrol.c @@ -89,9 +89,19 @@ static void predraw(EntityInterface *ent, void *a) { } } +TASK(cleanup) { + ent_unhook_pre_draw(predraw); + events_unregister_handler(mouse_event); + events_unregister_handler(wheel_event); + events_unregister_handler(focus_gained_event); + events_unregister_handler(focus_lost_event); +} + TASK(camera_control, { Camera3D *cam; }) { Camera3D *cam = ARGS.cam; + INVOKE_TASK_AFTER(&TASK_EVENTS(THIS_TASK)->finished, cleanup); + SDL_Window *w = NOT_NULL(video_get_window()); SDL_SetWindowGrab(w, true); SDL_CaptureMouse(true); diff --git a/src/camcontrol.h b/src/camcontrol.h index 69dcdddb..8402353c 100644 --- a/src/camcontrol.h +++ b/src/camcontrol.h @@ -14,8 +14,7 @@ /* * NOTE: This is a stage background debugging facility that provides FPS-like keyboard-and-mouse * fly-mode camera control. This code is not linked into non-developer builds, and usually is not - * referenced anywhere — it is expected to be used transiently while working on backgrounds. Which - * is why it doesn't bother with cleaning up after itself, by the way. + * referenced anywhere — it is expected to be used transiently while working on backgrounds. * * To use it, simply call `camcontrol_init` in your background animation setup code instead of * invoking normal animation code. For best results, disable anything that can alter the camera