fix null reference exception when LuaSandbox attempts to use the Logger
This commit is contained in:
parent
70baf9d306
commit
4c48542b98
|
@ -7,22 +7,16 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public unsafe class LuaSandbox
|
||||
{
|
||||
protected static Action<string> Logger;
|
||||
private static readonly System.Runtime.CompilerServices.ConditionalWeakTable<Lua, LuaSandbox> SandboxForThread = new System.Runtime.CompilerServices.ConditionalWeakTable<Lua, LuaSandbox>();
|
||||
|
||||
static System.Runtime.CompilerServices.ConditionalWeakTable<Lua, LuaSandbox> SandboxForThread = new System.Runtime.CompilerServices.ConditionalWeakTable<Lua, LuaSandbox>();
|
||||
public static Action<string> DefaultLogger;
|
||||
|
||||
public void SetLogger(Action<string> logger)
|
||||
{
|
||||
Logger = logger;
|
||||
}
|
||||
public static Action<string> DefaultLogger { get; set; }
|
||||
|
||||
public void SetSandboxCurrentDirectory(string dir)
|
||||
{
|
||||
CurrentDirectory = dir;
|
||||
_currentDirectory = dir;
|
||||
}
|
||||
|
||||
private string CurrentDirectory;
|
||||
private string _currentDirectory;
|
||||
|
||||
#if WINDOWS
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
|
@ -31,9 +25,9 @@ namespace BizHawk.Client.Common
|
|||
static extern uint GetCurrentDirectoryW(uint nBufferLength, byte* pBuffer);
|
||||
#endif
|
||||
|
||||
bool CoolSetCurrentDirectory(string path, string currDirSpeedHack = null)
|
||||
private bool CoolSetCurrentDirectory(string path, string currDirSpeedHack = null)
|
||||
{
|
||||
string target = CurrentDirectory + "\\";
|
||||
string target = _currentDirectory + "\\";
|
||||
|
||||
// first we'll bypass it with a general hack: dont do any setting if the value's already there (even at the OS level, setting the directory can be slow)
|
||||
// yeah I know, not the smoothest move to compare strings here, in case path normalization is happening at some point
|
||||
|
@ -91,9 +85,9 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
savedEnvironmentCurrDir = Environment.CurrentDirectory;
|
||||
|
||||
if (CurrentDirectory != null)
|
||||
if (_currentDirectory != null)
|
||||
{
|
||||
CoolSetCurrentDirectory(CurrentDirectory, savedEnvironmentCurrDir);
|
||||
CoolSetCurrentDirectory(_currentDirectory, savedEnvironmentCurrDir);
|
||||
}
|
||||
|
||||
EnvironmentSandbox.Sandbox(callback);
|
||||
|
@ -101,12 +95,12 @@ namespace BizHawk.Client.Common
|
|||
catch (LuaException ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
Logger(ex.ToString());
|
||||
DefaultLogger(ex.ToString());
|
||||
exceptionCallback?.Invoke();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (CurrentDirectory != null)
|
||||
if (_currentDirectory != null)
|
||||
{
|
||||
CoolSetCurrentDirectory(savedEnvironmentCurrDir);
|
||||
}
|
||||
|
@ -118,7 +112,6 @@ namespace BizHawk.Client.Common
|
|||
var sandbox = new LuaSandbox();
|
||||
SandboxForThread.Add(thread, sandbox);
|
||||
sandbox.SetSandboxCurrentDirectory(initialDirectory);
|
||||
sandbox.SetLogger(DefaultLogger);
|
||||
return sandbox;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
private bool _sortReverse;
|
||||
private string _lastColumnSorted;
|
||||
|
||||
private List<string> _consoleCommandHistory = new List<string>();
|
||||
private readonly List<string> _consoleCommandHistory = new List<string>();
|
||||
private int _consoleCommandHistoryIndex = -1;
|
||||
|
||||
public bool IsRebootingCore;
|
||||
|
@ -82,7 +82,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
LuaListView.QueryItemIndent += LuaListView_QueryItemIndent;
|
||||
LuaListView.VirtualMode = true;
|
||||
|
||||
//this is bad, in case we ever have more than one gui part running lua.. not sure how much other badness there is like that
|
||||
// this is bad, in case we ever have more than one gui part running lua.. not sure how much other badness there is like that
|
||||
LuaSandbox.DefaultLogger = ConsoleLog;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1202/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1210/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnusedMemberInSuper_002ELocal/@EntryIndexedValue">HINT</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnusedMethodReturnValue_002EGlobal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AF/@EntryIndexedValue">AF</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ARGB/@EntryIndexedValue">ARGB</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AV/@EntryIndexedValue">AV</s:String>
|
||||
|
|
Loading…
Reference in New Issue