Started the work to settle lifetime issues on the Windows backend.

This commit is contained in:
Pietro Gagliardi 2015-04-18 14:06:12 -04:00
parent 0a1e9b5f13
commit 8dcdbd0878
3 changed files with 16 additions and 0 deletions

View File

@ -8,3 +8,5 @@ extern void *uiAlloc(size_t, const char *);
#define uiNew(T) ((T *) uiAlloc(sizeof (T), #T )) #define uiNew(T) ((T *) uiAlloc(sizeof (T), #T ))
extern void *uiRealloc(void *, size_t, const char *); extern void *uiRealloc(void *, size_t, const char *);
extern void uiFree(void *); extern void uiFree(void *);
extern void complain(const char *, ...);

View File

@ -13,12 +13,14 @@ struct singleHWND {
BOOL containerHid; BOOL containerHid;
BOOL userDisabled; BOOL userDisabled;
BOOL containerDisabled; BOOL containerDisabled;
BOOL canDestroy;
}; };
static void singleDestroy(uiControl *c) static void singleDestroy(uiControl *c)
{ {
singleHWND *s = (singleHWND *) (c->Internal); singleHWND *s = (singleHWND *) (c->Internal);
s->canDestroy = TRUE;
if (DestroyWindow(s->hwnd) == 0) if (DestroyWindow(s->hwnd) == 0)
logLastError("error destroying control in singleDestroy()"); logLastError("error destroying control in singleDestroy()");
// the data structures are destroyed in the subclass procedure // the data structures are destroyed in the subclass procedure
@ -161,6 +163,8 @@ static LRESULT CALLBACK singleSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
return lResult; return lResult;
break; break;
case WM_DESTROY: case WM_DESTROY:
if (!s->canDestroy)
complain("trying to destroy control with singleWidget at %p before uiControlDestroy()", s);
(*(s->onWM_DESTROY))(c); (*(s->onWM_DESTROY))(c);
uiFree(s); uiFree(s);
break; break;

View File

@ -71,3 +71,13 @@ int windowClassOf(HWND hwnd, ...)
va_end(ap); va_end(ap);
return -1; return -1;
} }
void complain(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
abort();
}