"vscode:/vscode.git/clone" did not exist on "10f4d0ce78a2a3cb9b727ac55c8705385f0ded7e"
Commit 25c51407 authored by Vinicius Jarina's avatar Vinicius Jarina
Browse files

Merge pull request #203 from MaxVain/master

  Remove translator from the global pool before Lua state is closed
parents 5555f5a4 a9698525
...@@ -99,6 +99,11 @@ namespace NLua ...@@ -99,6 +99,11 @@ namespace NLua
private LuaNativeFunction panicCallback; private LuaNativeFunction panicCallback;
private ObjectTranslator translator; private ObjectTranslator translator;
/// <summary>
/// Used to protect the (global) object translator pool during add/remove
/// </summary>
private static readonly object translatorPoolLock = new object();
/// <summary> /// <summary>
/// Used to ensure multiple .net threads all get serialized by this single lock for access to the lua stack/objects /// Used to ensure multiple .net threads all get serialized by this single lock for access to the lua stack/objects
/// </summary> /// </summary>
...@@ -318,7 +323,10 @@ end ...@@ -318,7 +323,10 @@ end
LuaLib.LuaSetTable (luaState, -3); LuaLib.LuaSetTable (luaState, -3);
LuaLib.LuaNetPopGlobalTable (luaState); LuaLib.LuaNetPopGlobalTable (luaState);
translator = new ObjectTranslator (this, luaState); translator = new ObjectTranslator (this, luaState);
lock (translatorPoolLock)
{
ObjectTranslatorPool.Instance.Add (luaState, translator); ObjectTranslatorPool.Instance.Add (luaState, translator);
}
LuaLib.LuaNetPopGlobalTable (luaState); LuaLib.LuaNetPopGlobalTable (luaState);
LuaLib.LuaLDoString (luaState, Lua.initLuanet); LuaLib.LuaLDoString (luaState, Lua.initLuanet);
} }
...@@ -329,10 +337,13 @@ end ...@@ -329,10 +337,13 @@ end
return; return;
if (! CheckNull.IsNull(luaState)) { if (! CheckNull.IsNull(luaState)) {
lock (translatorPoolLock)
{
LuaCore.LuaClose (luaState); LuaCore.LuaClose (luaState);
ObjectTranslatorPool.Instance.Remove (luaState); ObjectTranslatorPool.Instance.Remove (luaState);
} }
} }
}
#if MONOTOUCH #if MONOTOUCH
[MonoPInvokeCallback (typeof (LuaNativeFunction))] [MonoPInvokeCallback (typeof (LuaNativeFunction))]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment