event_callback.c: Check for event being destroyed during callback

Mon, 16 Jan 2012 04:21:17 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Mon, 16 Jan 2012 04:21:17 +0000
changeset 108
f123677dd748
parent 107
f937d449075d
child 109
df22d2e85fb0

event_callback.c: Check for event being destroyed during callback

src/event_callback.c file | annotate | diff | comparison | revisions
--- a/src/event_callback.c	Mon Jan 16 01:53:45 2012 +0000
+++ b/src/event_callback.c	Mon Jan 16 04:21:17 2012 +0000
@@ -24,16 +24,15 @@
 	int ret;
 	double newTimeout = -1;
 	assert(cb);
-	if(!cb->base) {
-		/* Callback has been collected... die */
-		/* TODO: What should really be done here... */
-		return;
-	}
+	if(!cb->base)
+		return; /* Event has already been collected + destroyed */
 	assert(cb->base->loop_L);
 	L = cb->base->loop_L;
 	lua_rawgeti(L, LUA_REGISTRYINDEX, cb->callbackRef);
 	lua_pushinteger(L, event);
 	lua_call(L, 1, 2);
+	if(!cb->base)
+		return; /* event was destroyed during callback */
 	ret = lua_tointeger(L, -2);
 	if(lua_isnumber(L, -1)) {
 		newTimeout = lua_tonumber(L, -1);

mercurial