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