diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs index 2e44ba11246..bea94805a03 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs @@ -443,6 +443,7 @@ public void Clear(long componentHandle, [LuaColorParam] object color) return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -474,6 +475,7 @@ public void Refresh(long componentHandle) return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -506,6 +508,7 @@ public void SetDefaultForegroundColor(long componentHandle, [LuaColorParam] obje return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -538,6 +541,7 @@ public void SetDefaultBackgroundColor(long componentHandle, [LuaColorParam] obje return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -570,6 +574,7 @@ public void SetDefaultTextBackground(long componentHandle, [LuaColorParam] objec return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -602,6 +607,7 @@ public void DrawBezier(long componentHandle, LuaTable points, [LuaColorParam] ob return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -642,6 +648,7 @@ public void DrawBox( return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -682,6 +689,7 @@ public void DrawEllipse( return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -724,6 +732,7 @@ public void DrawIcon( return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -767,6 +776,7 @@ public void DrawImage( return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -798,6 +808,7 @@ public void ClearImageCache(long componentHandle) return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -844,6 +855,7 @@ public void DrawImageRegion( return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -876,6 +888,7 @@ public void DrawLine(long componentHandle, int x1, int y1, int x2, int y2, [LuaC return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -908,6 +921,7 @@ public void DrawAxis(long componentHandle, int x, int y, int size, [LuaColorPara return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -949,6 +963,7 @@ public void DrawArc( return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -991,6 +1006,7 @@ public void DrawPie( return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -1023,6 +1039,7 @@ public void DrawPixel(long componentHandle, int x, int y, [LuaColorParam] object return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -1062,6 +1079,7 @@ public void DrawPolygon( return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -1103,6 +1121,7 @@ public void DrawRectangle( return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -1147,6 +1166,7 @@ public void DrawString( return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -1191,6 +1211,7 @@ public void DrawText( return; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -1223,6 +1244,7 @@ public int GetMouseX(long componentHandle) return 0; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB); @@ -1256,6 +1278,7 @@ public int GetMouseY(long componentHandle) return 0; } var match = form.Controls().FirstOrDefault(c => c.Handle == ptr); + if (match is null) return; if (match is not LuaPictureBox control) { LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB);