diff --git a/src/ai.c b/src/ai.c index 6d882ce..aae8f2f 100644 --- a/src/ai.c +++ b/src/ai.c @@ -457,8 +457,13 @@ static int ai_pushtask(lua_State* L) { static int ai_poptask(lua_State* L) { (void)L; /* Just a hack to avoid -W -Wall warnings. */ Task* t = cur_pilot->task; - cur_pilot->task = t->next; - t->next = NULL; + if(t != NULL) { + cur_pilot->task = t->next; + t->next = NULL; + } else { + LLUA_DEBUG("Trying to pop task when there are no tasks in stack"); + return 0; + } ai_freetask(t); return 0; }