mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-08 10:23:27 +00:00
safety
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@393 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -58,7 +58,9 @@ int main() {
|
|||||||
reshape(400, 400);
|
reshape(400, 400);
|
||||||
|
|
||||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||||
MwAddUserHandler(window, MwNtickHandler, tick, NULL);
|
MwAddUserHandler(opengl, MwNtickHandler, tick, NULL);
|
||||||
|
|
||||||
|
MwAddTickList(opengl);
|
||||||
|
|
||||||
MwAddUserHandler(opengl, MwNkeyHandler, key_pressed, NULL);
|
MwAddUserHandler(opengl, MwNkeyHandler, key_pressed, NULL);
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* %param y Handler name
|
* %param y Handler name
|
||||||
*/
|
*/
|
||||||
#define MwDispatch(x, y) \
|
#define MwDispatch(x, y) \
|
||||||
if(x->widget_class != NULL && x->widget_class->y != NULL) x->widget_class->y(x)
|
if(!x->destroyed && x->widget_class != NULL && x->widget_class->y != NULL) x->widget_class->y(x)
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* %warning Used internally
|
* %warning Used internally
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
* %return `0` for success, otherwise failed
|
* %return `0` for success, otherwise failed
|
||||||
*/
|
*/
|
||||||
#define MwDispatch2(x, y) \
|
#define MwDispatch2(x, y) \
|
||||||
((x->widget_class != NULL && x->widget_class->y != NULL) ? x->widget_class->y(x) : 0)
|
((!x->destroyed && x->widget_class != NULL && x->widget_class->y != NULL) ? x->widget_class->y(x) : 0)
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* %warning Used internally
|
* %warning Used internally
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
* %param z Argument
|
* %param z Argument
|
||||||
*/
|
*/
|
||||||
#define MwDispatch3(x, y, z) \
|
#define MwDispatch3(x, y, z) \
|
||||||
if(x->widget_class != NULL && x->widget_class->y != NULL) x->widget_class->y(x, z)
|
if(!x->destroyed && x->widget_class != NULL && x->widget_class->y != NULL) x->widget_class->y(x, z)
|
||||||
|
|
||||||
#define MwWaitMS 10
|
#define MwWaitMS 10
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,8 @@ struct _MwWidget {
|
|||||||
|
|
||||||
MwWidget* destroy_queue;
|
MwWidget* destroy_queue;
|
||||||
MwWidget* tick_list;
|
MwWidget* tick_list;
|
||||||
|
|
||||||
|
int destroyed;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -132,14 +132,15 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) {
|
|||||||
void MwLLDestroy(MwLL handle) {
|
void MwLLDestroy(MwLL handle) {
|
||||||
MwLLDestroyCommon(handle);
|
MwLLDestroyCommon(handle);
|
||||||
|
|
||||||
XDestroyIC(handle->xic);
|
if(handle->xic) XDestroyIC(handle->xic);
|
||||||
XCloseIM(handle->xim);
|
if(handle->xim) XCloseIM(handle->xim);
|
||||||
|
|
||||||
destroy_pixmap(handle);
|
destroy_pixmap(handle);
|
||||||
XFree(handle->visual);
|
XFree(handle->visual);
|
||||||
XFreeGC(handle->display, handle->gc);
|
XFreeGC(handle->display, handle->gc);
|
||||||
XUnmapWindow(handle->display, handle->window);
|
XUnmapWindow(handle->display, handle->window);
|
||||||
XDestroyWindow(handle->display, handle->window);
|
XDestroyWindow(handle->display, handle->window);
|
||||||
|
|
||||||
XFlush(handle->display);
|
XFlush(handle->display);
|
||||||
free(handle);
|
free(handle);
|
||||||
}
|
}
|
||||||
|
|||||||
27
src/core.c
27
src/core.c
@@ -113,6 +113,7 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
|
|||||||
h->prop_event = 1;
|
h->prop_event = 1;
|
||||||
h->draw_inject = NULL;
|
h->draw_inject = NULL;
|
||||||
h->tick_list = NULL;
|
h->tick_list = NULL;
|
||||||
|
h->destroyed = 0;
|
||||||
|
|
||||||
if(parent == NULL) arrput(h->tick_list, h);
|
if(parent == NULL) arrput(h->tick_list, h);
|
||||||
|
|
||||||
@@ -211,17 +212,11 @@ void MwDestroyWidget(MwWidget handle) {
|
|||||||
if(handle->parent != NULL) {
|
if(handle->parent != NULL) {
|
||||||
arrput(handle->parent->destroy_queue, handle);
|
arrput(handle->parent->destroy_queue, handle);
|
||||||
}
|
}
|
||||||
|
handle->destroyed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MwStep(MwWidget handle) {
|
static void clean_destroy_queue(MwWidget handle) {
|
||||||
int i, j;
|
int i, j;
|
||||||
if(setjmp(handle->before_step)) return;
|
|
||||||
for(i = 0; i < arrlen(handle->children); i++) MwStep(handle->children[i]);
|
|
||||||
|
|
||||||
handle->prop_event = 0;
|
|
||||||
if(handle->lowlevel != NULL) MwLLNextEvent(handle->lowlevel);
|
|
||||||
handle->prop_event = 1;
|
|
||||||
|
|
||||||
for(i = 0; i < arrlen(handle->destroy_queue); i++) {
|
for(i = 0; i < arrlen(handle->destroy_queue); i++) {
|
||||||
MwWidget w = handle->destroy_queue[i];
|
MwWidget w = handle->destroy_queue[i];
|
||||||
|
|
||||||
@@ -238,12 +233,24 @@ void MwStep(MwWidget handle) {
|
|||||||
arrfree(handle->destroy_queue);
|
arrfree(handle->destroy_queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MwStep(MwWidget handle) {
|
||||||
|
int i;
|
||||||
|
if(setjmp(handle->before_step)) return;
|
||||||
|
for(i = 0; i < arrlen(handle->children); i++) MwStep(handle->children[i]);
|
||||||
|
|
||||||
|
handle->prop_event = 0;
|
||||||
|
if(handle->lowlevel != NULL && MwLLPending(handle->lowlevel)) MwLLNextEvent(handle->lowlevel);
|
||||||
|
handle->prop_event = 1;
|
||||||
|
|
||||||
|
clean_destroy_queue(handle);
|
||||||
|
}
|
||||||
|
|
||||||
int MwPending(MwWidget handle) {
|
int MwPending(MwWidget handle) {
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < arrlen(handle->children); i++) {
|
for(i = 0; i < arrlen(handle->children); i++) {
|
||||||
if(MwPending(handle->children[i])) return 1;
|
if(MwPending(handle->children[i])) return 1;
|
||||||
}
|
}
|
||||||
return MwLLPending(handle->lowlevel);
|
return (arrlen(handle->destroy_queue) > 0 ? 1 : 0) || MwLLPending(handle->lowlevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MwLoop(MwWidget handle) {
|
void MwLoop(MwWidget handle) {
|
||||||
@@ -255,6 +262,7 @@ void MwLoop(MwWidget handle) {
|
|||||||
for(i = 0; i < arrlen(handle->tick_list); i++) {
|
for(i = 0; i < arrlen(handle->tick_list); i++) {
|
||||||
MwDispatchUserHandler(handle->tick_list[i], MwNtickHandler, NULL);
|
MwDispatchUserHandler(handle->tick_list[i], MwNtickHandler, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
tick = MwWaitMS - (MwLLGetTick() - tick);
|
tick = MwWaitMS - (MwLLGetTick() - tick);
|
||||||
if(tick > 0) MwLLSleep(tick);
|
if(tick > 0) MwLLSleep(tick);
|
||||||
tick = MwLLGetTick();
|
tick = MwLLGetTick();
|
||||||
@@ -394,6 +402,7 @@ void MwSetDefault(MwWidget handle) {
|
|||||||
void MwDispatchUserHandler(MwWidget handle, const char* key, void* handler_data) {
|
void MwDispatchUserHandler(MwWidget handle, const char* key, void* handler_data) {
|
||||||
int ind = shgeti(handle->handler, key);
|
int ind = shgeti(handle->handler, key);
|
||||||
if(ind == -1) return;
|
if(ind == -1) return;
|
||||||
|
if(handle->destroyed) return;
|
||||||
|
|
||||||
handle->handler[ind].value(handle, handle->handler[ind].user_data, handler_data);
|
handle->handler[ind].value(handle, handle->handler[ind].user_data, handler_data);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user