Skip to content

Commit

Permalink
fix error on setting looping for stream sources, add catchexception t…
Browse files Browse the repository at this point in the history
…o setLooping
  • Loading branch information
TurtleP committed Jul 21, 2024
1 parent 29241ff commit ca153c5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/modules/audio/Source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion source/modules/audio/wrap_Source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
18 changes: 18 additions & 0 deletions source/modules/love/love.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit ca153c5

Please sign in to comment.