Skip to content

Commit

Permalink
Removed asserts for errors on non-critical lua calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Drewol committed Nov 16, 2018
1 parent 6a40141 commit 4ebc3be
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 54 deletions.
61 changes: 35 additions & 26 deletions Main/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,36 +722,49 @@ class Game_Impl : public Game
{
// Render Lua Intro
lua_getglobal(m_lua, "render_intro");
lua_pushnumber(m_lua, deltaTime);
if (lua_pcall(m_lua, 1, 1, 0) != 0)
if (lua_isfunction(m_lua, -1))
{
Logf("Lua error: %s", Logger::Error, lua_tostring(m_lua, -1));
g_gameWindow->ShowMessageBox("Lua Error", lua_tostring(m_lua, -1), 0);
assert(false);
lua_pushnumber(m_lua, deltaTime);
if (lua_pcall(m_lua, 1, 1, 0) != 0)
{
Logf("Lua error: %s", Logger::Error, lua_tostring(m_lua, -1));
g_gameWindow->ShowMessageBox("Lua Error", lua_tostring(m_lua, -1), 0);
}
m_introCompleted = lua_toboolean(m_lua, lua_gettop(m_lua));
}
m_introCompleted = lua_toboolean(m_lua, lua_gettop(m_lua));
else
{
m_introCompleted = true;
}

lua_settop(m_lua, 0);
}
if (m_ended)
{
// Render Lua Outro
lua_getglobal(m_lua, "render_outro");
lua_pushnumber(m_lua, deltaTime);
lua_pushnumber(m_lua, m_getClearState());
if (lua_pcall(m_lua, 2, 2, 0) != 0)
if (lua_isfunction(m_lua, -1))
{
Logf("Lua error: %s", Logger::Error, lua_tostring(m_lua, -1));
g_gameWindow->ShowMessageBox("Lua Error", lua_tostring(m_lua, -1), 0);
assert(false);
lua_pushnumber(m_lua, deltaTime);
lua_pushnumber(m_lua, m_getClearState());
if (lua_pcall(m_lua, 2, 2, 0) != 0)
{
Logf("Lua error: %s", Logger::Error, lua_tostring(m_lua, -1));
g_gameWindow->ShowMessageBox("Lua Error", lua_tostring(m_lua, -1), 0);
}
if (lua_isnumber(m_lua, lua_gettop(m_lua)))
{
float speed = Math::Clamp((float)lua_tonumber(m_lua, lua_gettop(m_lua)), 0.0f, 1.0f);
m_audioPlayback.SetPlaybackSpeed(speed);
m_audioPlayback.SetVolume(Math::Clamp(speed * 10.0f, 0.0f, 1.0f));
}
lua_pop(m_lua, 1);
m_outroCompleted = lua_toboolean(m_lua, lua_gettop(m_lua));
}
if (lua_isnumber(m_lua, lua_gettop(m_lua)))
else
{
float speed = Math::Clamp((float)lua_tonumber(m_lua, lua_gettop(m_lua)), 0.0f, 1.0f);
m_audioPlayback.SetPlaybackSpeed(speed);
m_audioPlayback.SetVolume(Math::Clamp(speed * 10.0f, 0.0f, 1.0f));
m_outroCompleted = true;
}
lua_pop(m_lua, 1);
m_outroCompleted = lua_toboolean(m_lua, lua_gettop(m_lua));
lua_settop(m_lua, 0);
}

Expand Down Expand Up @@ -1282,8 +1295,7 @@ class Game_Impl : public Game
lua_pushboolean(m_lua, late);
if (lua_pcall(m_lua, 1, 0, 0) != 0)
{
Logf("Lua error: %s", Logger::Error, lua_tostring(m_lua, -1));
assert(false);
Logf("Lua error on calling near_hit: %s", Logger::Error, lua_tostring(m_lua, -1));
}
}

Expand Down Expand Up @@ -1315,8 +1327,7 @@ class Game_Impl : public Game
lua_pushinteger(m_lua, newCombo);
if (lua_pcall(m_lua, 1, 0, 0) != 0)
{
Logf("Lua error: %s", Logger::Error, lua_tostring(m_lua, -1));
assert(false);
Logf("Lua error on calling update_combo: %s", Logger::Error, lua_tostring(m_lua, -1));
}
}
void OnScoreChanged(uint32 newScore)
Expand All @@ -1325,8 +1336,7 @@ class Game_Impl : public Game
lua_pushinteger(m_lua, newScore);
if (lua_pcall(m_lua, 1, 0, 0) != 0)
{
Logf("Lua error: %s", Logger::Error, lua_tostring(m_lua, -1));
assert(false);
Logf("Lua error on calling update_score: %s", Logger::Error, lua_tostring(m_lua, -1));
}
}

Expand Down Expand Up @@ -1421,8 +1431,7 @@ class Game_Impl : public Game
lua_pushboolean(m_lua, object->index == 1);
if (lua_pcall(m_lua, 1, 0, 0) != 0)
{
Logf("Lua error: %s", Logger::Error, lua_tostring(m_lua, -1));
assert(false);
Logf("Lua error on calling laser_alert: %s", Logger::Error, lua_tostring(m_lua, -1));
}
}
}
Expand Down
33 changes: 22 additions & 11 deletions Main/ScoreScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,26 +261,37 @@ class ScoreScreen_Impl : public ScoreScreen
};
int x, y, w, h;
lua_getglobal(m_lua, "get_capture_rect");
if (lua_pcall(m_lua, 0, 4, 0) != 0)
if (lua_isfunction(m_lua, -1))
{
Logf("Lua error: %s", Logger::Error, lua_tostring(m_lua, -1));
g_gameWindow->ShowMessageBox("Lua Error", lua_tostring(m_lua, -1), 0);
assert(false);
if (lua_pcall(m_lua, 0, 4, 0) != 0)
{
Logf("Lua error: %s", Logger::Error, lua_tostring(m_lua, -1));
g_gameWindow->ShowMessageBox("Lua Error", lua_tostring(m_lua, -1), 0);
}
h = luaPopInt();
w = luaPopInt();
y = luaPopInt();
x = luaPopInt();
}
else
{
x = 0;
y = 0;
w = g_resolution.x;
h = g_resolution.y;
}
h = luaPopInt();
w = luaPopInt();
y = luaPopInt();
x = luaPopInt();
Vector2i size(w, h);

Image screenshot = ImageRes::Screenshot(g_gl, size, { x,y });
String screenshotPath = "screenshots/" + Shared::Time::Now().ToString() + ".png";
screenshot->SavePNG(screenshotPath);
screenshot.Release();

lua_getglobal(m_lua, "screenshot_captured");
lua_pushstring(m_lua, *screenshotPath);
lua_call(m_lua, 1, 0);
if (lua_isfunction(m_lua, -1))
{
lua_pushstring(m_lua, *screenshotPath);
lua_call(m_lua, 1, 0);
}
}
if (key == SDLK_F9)
{
Expand Down
36 changes: 21 additions & 15 deletions Main/SongSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,21 @@ class SelectionWheel
void AdvancePage(int32 direction)
{
lua_getglobal(m_lua, "get_page_size");
if (lua_pcall(m_lua, 0, 1, 0) != 0)
if (lua_isfunction(m_lua, -1))
{
Logf("Lua error: %s", Logger::Error, lua_tostring(m_lua, -1));
g_gameWindow->ShowMessageBox("Lua Error", lua_tostring(m_lua, -1), 0);
assert(false);
if (lua_pcall(m_lua, 0, 1, 0) != 0)
{
Logf("Lua error: %s", Logger::Error, lua_tostring(m_lua, -1));
g_gameWindow->ShowMessageBox("Lua Error", lua_tostring(m_lua, -1), 0);
}
int ret = luaL_checkinteger(m_lua, 0);
lua_settop(m_lua, 0);
AdvanceSelection(ret * direction);
}
else
{
AdvanceSelection(5 * direction);
}
int ret = luaL_checkinteger(m_lua, 0);
lua_settop(m_lua, 0);
AdvanceSelection(ret * direction);
}
void SelectDifficulty(int32 newDiff)
{
Expand Down Expand Up @@ -495,8 +501,8 @@ class SelectionWheel
lua_pushinteger(m_lua, m_currentlySelectedDiff + 1);
if (lua_pcall(m_lua, 1, 0, 0) != 0)
{
Logf("Lua error: %s", Logger::Error, lua_tostring(m_lua, -1));
g_gameWindow->ShowMessageBox("Lua Error", lua_tostring(m_lua, -1), 0);
Logf("Lua error on set_diff: %s", Logger::Error, lua_tostring(m_lua, -1));
g_gameWindow->ShowMessageBox("Lua Error on set_diff", lua_tostring(m_lua, -1), 0);
assert(false);
}
}
Expand All @@ -506,8 +512,8 @@ class SelectionWheel
lua_pushinteger(m_lua, m_currentlySelectedLuaMapIndex + 1);
if (lua_pcall(m_lua, 1, 0, 0) != 0)
{
Logf("Lua error: %s", Logger::Error, lua_tostring(m_lua, -1));
g_gameWindow->ShowMessageBox("Lua Error", lua_tostring(m_lua, -1), 0);
Logf("Lua error on set_index: %s", Logger::Error, lua_tostring(m_lua, -1));
g_gameWindow->ShowMessageBox("Lua Error on set_index", lua_tostring(m_lua, -1), 0);
assert(false);
}
}
Expand Down Expand Up @@ -676,8 +682,8 @@ class FilterSelection
lua_pushboolean(m_lua, type == FilterType::Folder);
if (lua_pcall(m_lua, 2, 0, 0) != 0)
{
Logf("Lua error: %s", Logger::Error, lua_tostring(m_lua, -1));
g_gameWindow->ShowMessageBox("Lua Error", lua_tostring(m_lua, -1), 0);
Logf("Lua error on set_selection: %s", Logger::Error, lua_tostring(m_lua, -1));
g_gameWindow->ShowMessageBox("Lua Error on set_selection", lua_tostring(m_lua, -1), 0);
assert(false);
}
m_currentFilters[t] = filter;
Expand Down Expand Up @@ -744,8 +750,8 @@ class FilterSelection
lua_pushboolean(m_lua, m_selectingFolders);
if (lua_pcall(m_lua, 1, 0, 0) != 0)
{
Logf("Lua error: %s", Logger::Error, lua_tostring(m_lua, -1));
g_gameWindow->ShowMessageBox("Lua Error", lua_tostring(m_lua, -1), 0);
Logf("Lua error on set_mode: %s", Logger::Error, lua_tostring(m_lua, -1));
g_gameWindow->ShowMessageBox("Lua Error on set_mode", lua_tostring(m_lua, -1), 0);
assert(false);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Main/TitleScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class TitleScreen_Impl : public TitleScreen
lua_pushnumber(m_lua, (int32)button);
if (lua_pcall(m_lua, 1, 1, 0) != 0)
{
Logf("Lua error: %s", Logger::Error, lua_tostring(m_lua, -1));
g_gameWindow->ShowMessageBox("Lua Error", lua_tostring(m_lua, -1), 0);
Logf("Lua error on mouse_pressed: %s", Logger::Error, lua_tostring(m_lua, -1));
g_gameWindow->ShowMessageBox("Lua Error on mouse_pressed", lua_tostring(m_lua, -1), 0);
assert(false);
}
int ret = luaL_checkinteger(m_lua, 1);
Expand Down

0 comments on commit 4ebc3be

Please sign in to comment.