I'm trying to use lua scripts on my C# application, but I'm having problems to run different scripts, when I run 3~4 scripts I keep getting this exception:
As you can see I'm "catching" the AccessViolationException exception, just in case:
[HandleProcessCorruptedStateExceptions]
public void ExecuteAsync(MyLuaThread thread)
{
Task.Factory.StartNew(() =>
{
if (Monitor.TryEnter(ObjLocker, new TimeSpan(0, 0, 5)))
{
try
{
Thread.Sleep(10);
if (ScriptRunning[thread.name])
{
var result = lua.DoString(thread.code);
}
Thread.Sleep(10);
}
catch (AccessViolationException e4)
{
thread.errors.Add(time() + " - Access Error - " + e4.Message);
print("(" + thread.name + ") Access Error - " + e4.Message);
}
catch (NLua.Exceptions.LuaScriptException e)
{
thread.errors.Add(time() + " - Script Error - Line: " + e.Message.Substring(e.Message.IndexOf(":")));
print("(" + thread.name + ")Line: " + e.Message.Substring(e.Message.IndexOf(":")));
}
catch (Exception otherEx)
{
thread.errors.Add(time() + " - Other Error - " + otherEx.Message);
print("(" + thread.name + ") Access Error - " + otherEx.Message);
}
finally
{
Thread.Sleep(10);
Monitor.Exit(ObjLocker);
}
}
});
}
I created this small project to show you guys the error happening. Just add 3~5 threads and start them, it shouldn't take more than 5 seconds to the crash happen.
Small Project link: https://www.dropbox.com/s/4fyk8tblff7v5wa/SmallLuaTest.rar