From 436881beafebd14ebbce78f8fd8ee5e03e1ac69b Mon Sep 17 00:00:00 2001 From: zeromus Date: Mon, 30 Dec 2013 16:36:15 +0000 Subject: [PATCH] lua: better typecasting for LuaInt and LuaUInt that doesnt throw overflow exceptions; and, render to a null image when the lua script manager Resume process hasnt begun (setting up a render target) but lua scripts run (due to loadstate, for example) --- BizHawk.Client.Common/lua/LuaLibraryBase.cs | 4 ++-- .../tools/Lua/Libraries/EmuLuaLibrary.Gui.cs | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/BizHawk.Client.Common/lua/LuaLibraryBase.cs b/BizHawk.Client.Common/lua/LuaLibraryBase.cs index 38b488ed2e..e1be7fbded 100644 --- a/BizHawk.Client.Common/lua/LuaLibraryBase.cs +++ b/BizHawk.Client.Common/lua/LuaLibraryBase.cs @@ -27,12 +27,12 @@ namespace BizHawk.Client.Common protected static int LuaInt(object luaArg) { - return Convert.ToInt32((double)luaArg); + return (int)(double)luaArg; } protected static uint LuaUInt(object luaArg) { - return Convert.ToUInt32((double)luaArg); + return (uint)(double)luaArg; } /// diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs index 0b34c592ba..650d8b8aa7 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs @@ -132,9 +132,13 @@ namespace BizHawk.Client.EmuHawk return p; } + Bitmap nullGraphicsBitmap = new Bitmap(1, 1); private Graphics GetGraphics() { - var g = luaSurface.GetGraphics(); + Graphics g; + if (luaSurface == null) + g = Graphics.FromImage(nullGraphicsBitmap); + else g = luaSurface.GetGraphics(); int tx = Global.Emulator.CoreComm.ScreenLogicalOffsetX; int ty = Global.Emulator.CoreComm.ScreenLogicalOffsetY; if (tx != 0 || ty != 0)