--- a/ui/common/object.c Tue May 19 18:10:13 2026 +0200 +++ b/ui/common/object.c Tue May 19 18:25:53 2026 +0200 @@ -103,6 +103,7 @@ // it is possible to have 0 references, in case // a window was created but ui_show was never called if(obj->ref == 0 || --obj->ref == 0) { + uic_context_prepare_close(obj->ctx); if(obj->destroy) { obj->destroy(obj); } else { @@ -114,7 +115,6 @@ } void uic_object_destroy(UiObject *obj) { - uic_context_prepare_close(obj->ctx); uic_object_destroyed(obj); uic_context_destroy(obj->ctx, obj->ctx->document); }