diff options
author | Lukas Pioch <lukas@zgow.de> | 2017-05-29 21:33:30 +0200 |
---|---|---|
committer | Lukas Pioch <lukas@zgow.de> | 2017-06-05 15:14:23 +0200 |
commit | 7922e6addb06de89cc73c64d30321aa6710e30ce (patch) | |
tree | 8b35b17e08f41bf535ec25844bc7648697b083ec /src/Bindings | |
parent | Avoid pickups to sink into blocks and disappear (#3739) (diff) | |
download | cuberite-7922e6addb06de89cc73c64d30321aa6710e30ce.tar cuberite-7922e6addb06de89cc73c64d30321aa6710e30ce.tar.gz cuberite-7922e6addb06de89cc73c64d30321aa6710e30ce.tar.bz2 cuberite-7922e6addb06de89cc73c64d30321aa6710e30ce.tar.lz cuberite-7922e6addb06de89cc73c64d30321aa6710e30ce.tar.xz cuberite-7922e6addb06de89cc73c64d30321aa6710e30ce.tar.zst cuberite-7922e6addb06de89cc73c64d30321aa6710e30ce.zip |
Diffstat (limited to 'src/Bindings')
-rw-r--r-- | src/Bindings/LuaWindow.cpp | 20 | ||||
-rw-r--r-- | src/Bindings/LuaWindow.h | 3 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/Bindings/LuaWindow.cpp b/src/Bindings/LuaWindow.cpp index 83463520c..fd714390e 100644 --- a/src/Bindings/LuaWindow.cpp +++ b/src/Bindings/LuaWindow.cpp @@ -4,8 +4,10 @@ #include "Globals.h" #include "LuaWindow.h" +#include "../Entities/Player.h" #include "../UI/SlotArea.h" #include "PluginLua.h" +#include "Root.h" #include "lua/src/lauxlib.h" // Needed for LUA_REFNIL @@ -51,6 +53,24 @@ cLuaWindow::~cLuaWindow() { m_Contents.RemoveListener(*this); + // Close open lua window from players, to avoid dangling pointers + class cPlayerCallback : public cPlayerListCallback + { + virtual bool Item(cPlayer * a_Player) + { + if (a_Player->GetWindow() == m_LuaWindow) + { + a_Player->CloseWindow(false); + } + return false; + } + cLuaWindow * m_LuaWindow; + public: + cPlayerCallback(cLuaWindow & a_LuaWindow) { m_LuaWindow = &a_LuaWindow; } + } PlayerCallback(*this); + + cRoot::Get()->ForEachPlayer(PlayerCallback); + // Must delete slot areas now, because they are referencing this->m_Contents and would try to access it in cWindow's // destructor, when the member is already gone. for (cSlotAreas::iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end(); itr != end; ++itr) diff --git a/src/Bindings/LuaWindow.h b/src/Bindings/LuaWindow.h index 66efb2a32..f9db525fa 100644 --- a/src/Bindings/LuaWindow.h +++ b/src/Bindings/LuaWindow.h @@ -15,7 +15,8 @@ #include "../ItemGrid.h" - +class cPlayer; +typedef cItemCallback<cPlayer> cPlayerListCallback; /** A window that has been created by a Lua plugin and is handled entirely by that plugin |