Skip to content

Commit

Permalink
fix #5084
Browse files Browse the repository at this point in the history
  • Loading branch information
rtri committed Mar 3, 2016
1 parent 773db8a commit c3c4e37
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 41 deletions.
19 changes: 2 additions & 17 deletions rts/Game/Game.cpp
Expand Up @@ -1081,25 +1081,10 @@ bool CGame::UpdateUnsynced(const spring_time currentTime)

SetDrawMode(gameNormalDraw); //TODO move to ::Draw()?

if (luaUI != nullptr) { luaUI->CheckStack(); luaUI->CheckReload(); }
if (luaGaia != nullptr) { luaGaia->CheckStack(); }
if (luaUI != nullptr) { luaUI->CheckStack(); luaUI->CheckAction(); }
if (luaGaia != nullptr) { luaGaia->CheckStack(); }
if (luaRules != nullptr) { luaRules->CheckStack(); }

#if 0
// XXX ugly hack to minimize luaUI errors
// has not been necessary for a long time
if (luaUI && luaUI->GetCallInErrors() >= 5) {
for (int annoy = 0; annoy < 8; annoy++) {
LOG_L(L_ERROR, "5 errors deep in LuaUI, disabling...");
}

CLuaUI::FreeHandler();
guihandler->LoadDefaultConfig();
LOG_L(L_ERROR, "Type '/luaui reload' in the chat to re-enable LuaUI.");
LOG_L(L_ERROR, "===>>> Please report this error to the forum or mantis with your infolog.txt");
}
#endif

if (chatting && !userWriting) {
consoleHistory->AddLine(userInput);

Expand Down
7 changes: 3 additions & 4 deletions rts/Game/UI/GuiHandler.cpp
Expand Up @@ -189,7 +189,7 @@ bool CGuiHandler::EnableLuaUI(bool enableCommand)
// (LuaRules can reload itself inside callins because the action
// SendCommands("luarules reload") goes over the network, and is
// not when received)
luaUI->QueueReload();
luaUI->QueueAction(CLuaUI::ACTION_RELOAD);
return true;
}
}
Expand All @@ -215,9 +215,8 @@ bool CGuiHandler::DisableLuaUI()
}

if (luaUI->IsRunning()) {
// NOTE: might cause a SEGV through RunCallIn()
LOG_L(L_WARNING, "[GUIHandler] can not disable from within LuaUI, yet");
return false;
luaUI->QueueAction(CLuaUI::ACTION_DISABLE);
return true;
}

CLuaUI::FreeHandler();
Expand Down
1 change: 0 additions & 1 deletion rts/Lua/LuaHandle.cpp
Expand Up @@ -83,7 +83,6 @@ static int handlepanic(lua_State* L)
CLuaHandle::CLuaHandle(const string& _name, int _order, bool _userMode, bool _synced)
: CEventClient(_name, _order, _synced)
, userMode(_userMode)
, reloadMe(false)
, killMe(false)
, callinErrors(0)
{
Expand Down
3 changes: 1 addition & 2 deletions rts/Lua/LuaHandle.h
Expand Up @@ -284,8 +284,7 @@ class CLuaHandle : public CEventClient

protected:
bool userMode;
bool reloadMe;
bool killMe;
bool killMe; // set for handles to fail to RunCallIn

lua_State* L;
lua_State* L_GC;
Expand Down
2 changes: 2 additions & 0 deletions rts/Lua/LuaUI.cpp
Expand Up @@ -105,6 +105,8 @@ CLuaUI::CLuaUI()

UpdateTeams();

queuedAction = ACTION_NOVALUE;

haveShockFront = false;
shockFrontMinArea = 0.0f;
shockFrontMinPower = 0.0f;
Expand Down
43 changes: 26 additions & 17 deletions rts/Lua/LuaUI.h
Expand Up @@ -22,24 +22,13 @@ class CLuaUI : public CLuaHandle
{
friend class LuaLobby;

public:
void QueueReload() { reloadMe = true; }
void CheckReload() {
if (!reloadMe)
return;

ReloadHandler();
}

static bool ReloadHandler() { return (FreeHandler(), LoadFreeHandler()); } // NOTE the ','
static bool LoadFreeHandler() { return (LoadHandler() || FreeHandler()); }

static bool LoadHandler();
static bool FreeHandler();

static void UpdateTeams();

public: // structs
enum QueuedAction {
ACTION_RELOAD = 0,
ACTION_DISABLE = 1,
ACTION_NOVALUE = -1,
};

struct ReStringPair {
int cmdIndex;
string texture;
Expand All @@ -50,6 +39,24 @@ class CLuaUI : public CLuaHandle
map<int, string> params;
};

public:
void QueueAction(const QueuedAction action) { queuedAction = action; }
void CheckAction() {
switch (queuedAction) {
case ACTION_RELOAD: { ReloadHandler(); } break;
case ACTION_DISABLE: { FreeHandler(); } break;
default: { } break;
}
}

static bool ReloadHandler() { return (FreeHandler(), LoadFreeHandler()); } // NOTE the ','
static bool LoadFreeHandler() { return (LoadHandler() || FreeHandler()); }

static bool LoadHandler();
static bool FreeHandler();

static void UpdateTeams();

public: // call-ins
bool HasCallIn(lua_State* L, const string& name);

Expand Down Expand Up @@ -86,6 +93,8 @@ class CLuaUI : public CLuaHandle
bool GetLuaCmdDescList(lua_State* L, int index, vector<CommandDescription>& customCmds);

protected:
QueuedAction queuedAction;

bool haveShockFront;
float shockFrontMinArea;
float shockFrontMinPower;
Expand Down

0 comments on commit c3c4e37

Please sign in to comment.