From d28d5e5a9baeddc771c2e54fbfae4c78e45a16e2 Mon Sep 17 00:00:00 2001 From: goyuken Date: Sun, 21 Dec 2014 17:40:06 +0000 Subject: [PATCH] quciknes: enforce objectdisposedexception so as to avoid accessviolations --- .../Consoles/Nintendo/QuickNES/QuickNES.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs index 4749c8eff4..b811e3a9a0 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs @@ -179,6 +179,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES public void FrameAdvance(bool render, bool rendersound = true) { + CheckDisposed(); using (FP.Save()) { if (Controller["Power"]) @@ -273,6 +274,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES public void SaveStateText(System.IO.TextWriter writer) { + CheckDisposed(); var temp = SaveStateBinary(); temp.SaveAsHexFast(writer); // write extra copy of stuff we don't use @@ -281,6 +283,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES public void LoadStateText(System.IO.TextReader reader) { + CheckDisposed(); string hex = reader.ReadLine(); byte[] state = new byte[hex.Length / 2]; state.ReadFromHexFast(hex); @@ -289,6 +292,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES public void SaveStateBinary(System.IO.BinaryWriter writer) { + CheckDisposed(); LibQuickNES.ThrowStringError(LibQuickNES.qn_state_save(Context, SaveStateBuff, SaveStateBuff.Length)); writer.Write(SaveStateBuff.Length); writer.Write(SaveStateBuff); @@ -300,6 +304,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES public void LoadStateBinary(System.IO.BinaryReader reader) { + CheckDisposed(); int len = reader.ReadInt32(); if (len != SaveStateBuff.Length) throw new InvalidOperationException("Unexpected savestate buffer length!"); @@ -313,6 +318,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES public byte[] SaveStateBinary() { + CheckDisposed(); var ms = new System.IO.MemoryStream(SaveStateBuff2, true); var bw = new System.IO.BinaryWriter(ms); SaveStateBinary(bw); @@ -632,6 +638,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES } } + void CheckDisposed() + { + if (Context == IntPtr.Zero) + throw new ObjectDisposedException(GetType().Name); + } + #region VideoProvider int[] VideoOutput = new int[256 * 240];