From 92f417dadebc3279ad3c96a14c4e0d6c5f533322 Mon Sep 17 00:00:00 2001 From: zeromus Date: Mon, 9 Jun 2014 19:19:12 +0000 Subject: [PATCH] fix crashing bugs in yabause+software --- BizHawk.Client.Common/GLManager.cs | 4 --- .../Consoles/Sega/Saturn/Yabause.cs | 30 ++++++++++++++----- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/BizHawk.Client.Common/GLManager.cs b/BizHawk.Client.Common/GLManager.cs index 5401c7c665..636228286d 100644 --- a/BizHawk.Client.Common/GLManager.cs +++ b/BizHawk.Client.Common/GLManager.cs @@ -76,10 +76,6 @@ namespace BizHawk.Client.Common { //this is here for future use and tracking purposes.. however.. instead of relying on this, we should just make sure we always activate what we need before we use it } - - // ret.RequestGLContext = () => new BizHawk.Bizware.BizwareGL.Drivers.OpenTK.IGL_TK(); - //ret.ActivateGLContext = (gl) => ((BizHawk.Bizware.BizwareGL.Drivers.OpenTK.IGL_TK)gl).MakeDefaultCurrent(); - //ret.DeactivateGLContext = () => GlobalWin.DisplayManager.. public class ContextRef { diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/Yabause.cs b/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/Yabause.cs index 96f8f7cd89..e7540af37a 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/Yabause.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/Yabause.cs @@ -69,18 +69,32 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn ResetCounters(); - CoreComm.ActivateGLContext(glContext); + ActivateGL(); Init(bios); InputCallbackH = new LibYabause.InputCallback(() => CoreComm.InputCallback.Call()); LibYabause.libyabause_setinputcallback(InputCallbackH); CoreComm.UsesDriveLed = true; - CoreComm.DeactivateGLContext(); + DeactivateGL(); } static object glContext; + void ActivateGL() + { + //if (!SyncSettings.UseGL) return; //not safe + if (glContext == null) return; + CoreComm.ActivateGLContext(glContext); + } + + void DeactivateGL() + { + //if (!SyncSettings.UseGL) return; //not safe + if (glContext == null) return; + CoreComm.DeactivateGLContext(); + } + void Init(byte[] bios) { bool GL = SyncSettings.UseGL; @@ -197,7 +211,7 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn { int w, h, nsamp; - CoreComm.ActivateGLContext(glContext); + ActivateGL(); LibYabause.Buttons1 p11 = (LibYabause.Buttons1)0xff; LibYabause.Buttons2 p12 = (LibYabause.Buttons2)0xff; @@ -279,7 +293,7 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn //CheckStates(); - CoreComm.DeactivateGLContext(); + DeactivateGL(); } public int Frame { get; private set; } @@ -373,11 +387,11 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn fp.Offer(data); //loadstate can trigger GL work - CoreComm.ActivateGLContext(glContext); + ActivateGL(); bool succeed = LibYabause.libyabause_loadstate(fp.GetPipeNameNative()); - CoreComm.DeactivateGLContext(); + DeactivateGL(); fp.Finish(); if (!succeed) @@ -537,7 +551,7 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn { if (!Disposed) { - CoreComm.ActivateGLContext(glContext); + ActivateGL(); if (SaveRamModified) DisposedSaveRam = ReadSaveRam(); LibYabause.libyabause_setvidbuff(IntPtr.Zero); @@ -546,7 +560,7 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn VideoHandle.Free(); SoundHandle.Free(); Disposed = true; - CoreComm.DeactivateGLContext(); + DeactivateGL(); } }