From d44da4f9b601cdadf477b73ce2e89878a615d625 Mon Sep 17 00:00:00 2001 From: Sour Date: Fri, 24 Jan 2020 22:37:34 -0500 Subject: [PATCH] Debugger: Event Viewer - Fixed rare crash when opening window (esp. on Linux) --- Core/EventManager.h | 4 ++-- GUI.NET/Debugger/Controls/ctrlEventViewerPpuView.cs | 2 +- GUI.NET/Debugger/frmEventViewer.cs | 13 +++++++------ GUI.NET/InteropEmu.cs | 6 +++--- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Core/EventManager.h b/Core/EventManager.h index d7248108..b5dbe172 100644 --- a/Core/EventManager.h +++ b/Core/EventManager.h @@ -23,11 +23,11 @@ private: vector _sentEvents; vector _snapshot; - uint16_t _snapshotScanline; + uint16_t _snapshotScanline = 0; SimpleLock _lock; uint32_t _scanlineCount = 262; - uint16_t *_ppuBuffer; + uint16_t *_ppuBuffer = nullptr; void DrawEvent(DebugEventInfo &evt, bool drawBackground, uint32_t *buffer, EventViewerDisplayOptions &options); void DrawNtscBorders(uint32_t *buffer); diff --git a/GUI.NET/Debugger/Controls/ctrlEventViewerPpuView.cs b/GUI.NET/Debugger/Controls/ctrlEventViewerPpuView.cs index b3e5ea98..ad7c8ddb 100644 --- a/GUI.NET/Debugger/Controls/ctrlEventViewerPpuView.cs +++ b/GUI.NET/Debugger/Controls/ctrlEventViewerPpuView.cs @@ -26,7 +26,7 @@ namespace Mesen.GUI.Debugger.Controls private Bitmap _screenBitmap = null; private Bitmap _overlayBitmap = null; private Bitmap _displayBitmap = null; - private byte[] _pictureData = null; + private UInt32[] _pictureData = null; private Font _overlayFont; public ctrlEventViewerPpuView() diff --git a/GUI.NET/Debugger/frmEventViewer.cs b/GUI.NET/Debugger/frmEventViewer.cs index 02c9c60b..ec33a010 100644 --- a/GUI.NET/Debugger/frmEventViewer.cs +++ b/GUI.NET/Debugger/frmEventViewer.cs @@ -85,12 +85,6 @@ namespace Mesen.GUI.Debugger RestoreLocation(_config.EventViewerLocation, _config.EventViewerSize); - this._notifListener = new InteropEmu.NotificationListener(_config.DebugConsoleId); - this._notifListener.OnNotification += this._notifListener_OnNotification; - - _refreshManager = new WindowRefreshManager(this); - _refreshManager.AutoRefresh = _config.EventViewerAutoRefresh; - _refreshManager.AutoRefreshSpeed = _config.EventViewerAutoRefreshSpeed; mnuAutoRefresh.Checked = _config.EventViewerAutoRefresh; mnuAutoRefreshLow.Click += (s, evt) => _refreshManager.AutoRefreshSpeed = RefreshSpeed.Low; mnuAutoRefreshNormal.Click += (s, evt) => _refreshManager.AutoRefreshSpeed = RefreshSpeed.Normal; @@ -101,6 +95,13 @@ namespace Mesen.GUI.Debugger _binder.UpdateUI(); this.RefreshViewer(); + _refreshManager = new WindowRefreshManager(this); + _refreshManager.AutoRefresh = _config.EventViewerAutoRefresh; + _refreshManager.AutoRefreshSpeed = _config.EventViewerAutoRefreshSpeed; + + this._notifListener = new InteropEmu.NotificationListener(_config.DebugConsoleId); + this._notifListener.OnNotification += this._notifListener_OnNotification; + InitShortcuts(); } } diff --git a/GUI.NET/InteropEmu.cs b/GUI.NET/InteropEmu.cs index fe3f1713..00a83dc3 100644 --- a/GUI.NET/InteropEmu.cs +++ b/GUI.NET/InteropEmu.cs @@ -511,10 +511,10 @@ namespace Mesen.GUI [DllImport(DLLPath)] public static extern void GetEventViewerEvent(ref DebugEventInfo evtInfo, Int16 scanline, UInt16 cycle, EventViewerDisplayOptions options); [DllImport(DLLPath)] public static extern UInt32 TakeEventSnapshot(EventViewerDisplayOptions options); - [DllImport(DLLPath, EntryPoint = "GetEventViewerOutput")] private static extern void GetEventViewerOutputWrapper([In, Out]byte[] buffer, EventViewerDisplayOptions options); - public static byte[] GetEventViewerOutput(UInt32 scanlineCount, EventViewerDisplayOptions options) + [DllImport(DLLPath, EntryPoint = "GetEventViewerOutput")] private static extern void GetEventViewerOutputWrapper([In, Out]UInt32[] buffer, EventViewerDisplayOptions options); + public static UInt32[] GetEventViewerOutput(UInt32 scanlineCount, EventViewerDisplayOptions options) { - byte[] buffer = new byte[341 * 2 * scanlineCount * 2 * 4]; + UInt32[] buffer = new UInt32[341 * 2 * scanlineCount * 2]; InteropEmu.GetEventViewerOutputWrapper(buffer, options); return buffer; }