diff --git a/source/modules/audio/Source.cpp b/source/modules/audio/Source.cpp index a5c46fcc..516d27a2 100644 --- a/source/modules/audio/Source.cpp +++ b/source/modules/audio/Source.cpp @@ -533,7 +533,7 @@ namespace love void Source::setLooping(bool looping) { - if (this->sourceType == TYPE_STREAM) + if (this->sourceType == TYPE_QUEUE) throw QueueLoopingException(); if (this->valid && this->sourceType == TYPE_STATIC) diff --git a/source/modules/audio/wrap_Source.cpp b/source/modules/audio/wrap_Source.cpp index 62d372eb..03be269b 100644 --- a/source/modules/audio/wrap_Source.cpp +++ b/source/modules/audio/wrap_Source.cpp @@ -140,7 +140,7 @@ int Wrap_Source::setLooping(lua_State* L) auto* self = luax_checksource(L, 1); bool looping = luax_checkboolean(L, 2); - self->setLooping(looping); + luax_catchexcept(L, [&]() { self->setLooping(looping) }); return 0; } diff --git a/source/modules/love/love.cpp b/source/modules/love/love.cpp index 494b5385..82d0539c 100644 --- a/source/modules/love/love.cpp +++ b/source/modules/love/love.cpp @@ -145,6 +145,22 @@ static int love_setDeprecationOutput(lua_State* L) return 0; } +static constexpr const char* ERROR_PANIC = "PANIC: unprotected error in call to Lua API (%s)"; + +/* + * If an error happens outside any protected environment, Lua calls a panic function and then calls + * exit(EXIT_FAILURE), thus exiting the host application. We want to inform the user of the error. + * However, this will only be informative via the console. + */ +static int love_atpanic(lua_State* L) +{ + char message[0x80] {}; + snprintf(message, sizeof(message), ERROR_PANIC, lua_tostring(L, -1)); + + printf("%s\n", message); + return 0; +} + static void luax_addcompatibilityalias(lua_State* L, const char* module, const char* name, const char* alias) { lua_getglobal(L, module); @@ -229,6 +245,8 @@ int love_initialize(lua_State* L) love::luax_preload(L, luaopen_luautf8, "utf8"); love::luax_preload(L, luaopen_https, "https"); + lua_atpanic(L, love_atpanic); + return 1; }