From 21a29a54683e222afdc3de97b209e4ff896f23d3 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 19 Apr 2015 22:59:06 -0400 Subject: [PATCH] More destruction rules following code. --- TODO.md | 2 +- darwin/parent.m | 2 ++ stack.c | 2 ++ unix/parent.c | 2 ++ windows/parent.c | 2 ++ 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 37d241d1..6ca9e9f8 100644 --- a/TODO.md +++ b/TODO.md @@ -22,7 +22,7 @@ - settle onDestroy/destroy naming - clean up Windows lifetiming code - forbid free(NULL) to check for bugs -- figure out how to do the parent on destroy check for uiStack +- figure out how to do the parent on destroy check for children of a uiStack without a parent in and of itself ultimately: - make everything vtable-based diff --git a/darwin/parent.m b/darwin/parent.m index e9bae315..629c8f0b 100644 --- a/darwin/parent.m +++ b/darwin/parent.m @@ -27,6 +27,8 @@ uiLogObjCClassAllocations - (void)uipDestroyMainControl { if (self->mainControl != NULL) { + // we have to do this before we can destroy controls + uiControlSetParent(p->mainControl, NULL); uiControlDestroy(self->mainControl); self->mainControl = NULL; } diff --git a/stack.c b/stack.c index 8a3906f2..8983b6c5 100644 --- a/stack.c +++ b/stack.c @@ -33,6 +33,8 @@ static void stackDestroy(uiControl *c) stack *s = (stack *) c; uintmax_t i; + if (s->parent != NULL) + complain("attempt to destroy a uiControl at %p while it still has a parent %p", c, s->parent); for (i = 0; i < s->len; i++) uiControlDestroy(s->controls[i].c); uiFree(s->controls); diff --git a/unix/parent.c b/unix/parent.c index 2decb979..6a8b8424 100644 --- a/unix/parent.c +++ b/unix/parent.c @@ -146,6 +146,8 @@ static void parentDestroy(uiParent *pp) // first, destroy the main control if (p->mainControl != NULL) { + // we have to do this before we can destroy controls + uiControlSetParent(p->mainControl, NULL); uiControlDestroy(p->mainControl); p->mainControl = NULL; } diff --git a/windows/parent.c b/windows/parent.c index 0d9a3a44..1f81777d 100644 --- a/windows/parent.c +++ b/windows/parent.c @@ -235,6 +235,8 @@ static void parentDestroy(uiParent *pp) // first destroy the main control, if any if (p->mainControl != NULL) { + // we have to do this before we can destroy controls + uiControlSetParent(p->mainControl, NULL); uiControlDestroy(p->mainControl); p->mainControl = NULL; }