Destroy Lua objects before destroying lovr;
This fixes a bug where physics Worlds are destroyed after
ODE is deinitialized, which can cause a segfault.  Instead we
collect Lua objects first and then destroy each module.  This
makes more sense and doesn't seem to have any consequences...
@@ -33,9 +33,8 @@ static void emscriptenLoop(void* arg) {
int status = lua_tonumber(L, -1);
bool isRestart = lua_type(L, -1) == LUA_TSTRING && !strcmp(lua_tostring(L, -1), "restart");
- lovrDestroy();
-
lua_close(L);
+ lovrDestroy();
emscripten_cancel_main_loop();
if (isRestart) {
@@ -98,8 +97,8 @@ bool lovrRun(int argc, char** argv, int* status) {
lua_pushcfunction(L, luax_getstack);
if (luaL_loadbuffer(L, (const char*) boot_lua, boot_lua_len, "boot.lua") || lua_pcall(L, 0, 1, -2)) {
fprintf(stderr, "%s\n", lua_tostring(L, -1));
- lovrDestroy();
lua_close(L);
+ lovrDestroy();
*status = 1;
return false;
}
@@ -119,8 +118,8 @@ bool lovrRun(int argc, char** argv, int* status) {
*status = lua_tonumber(L, -1);
bool restart = lua_type(L, -1) == LUA_TSTRING && !strcmp(lua_tostring(L, -1), "restart");
- lovrDestroy();
lua_close(L);
+ lovrDestroy();
if (!restart) {
glfwTerminate();
