Debugger: Fixed crashes when switching between games from different consoles (in AOT build)

Caused by what looks like slight differences between how AOT treats an empty array (vs JIT builds) when it marshals the array (AOT sends a null pointer, JIT sends a pointer to an empty array)
This was causing issues in both builds (AOT crashed immediately because of the null pointer, JIT read from out-of-bounds memory)
This commit is contained in:
Sour 2025-03-28 18:03:30 +09:00
parent acbe931ba0
commit 1975ab958c
6 changed files with 20 additions and 7 deletions

View file

@ -588,7 +588,9 @@ void Debugger::ProcessEvent(EventType type, std::optional<CpuType> cpuTypeOpt)
break;
case EventType::StartFrame: {
_emu->GetNotificationManager()->SendNotification(ConsoleNotificationType::EventViewerRefresh, (void*)evtCpuType);
if(!_emu->IsDebuggerBlocked()) {
_emu->GetNotificationManager()->SendNotification(ConsoleNotificationType::EventViewerRefresh, (void*)evtCpuType);
}
BaseEventManager* evtMgr = GetEventManager(evtCpuType);
if(evtMgr) {
evtMgr->ClearFrameEvents();

View file

@ -403,7 +403,9 @@ void PpuTools::UpdateViewers(uint16_t scanline, uint16_t cycle)
for(auto updateTiming : _updateTimings) {
ViewerRefreshConfig cfg = updateTiming.second;
if(cfg.Cycle == cycle && cfg.Scanline == scanline) {
_emu->GetNotificationManager()->SendNotification(ConsoleNotificationType::ViewerRefresh, (void*)(uint64_t)updateTiming.first);
if(!_emu->IsDebuggerBlocked()) {
_emu->GetNotificationManager()->SendNotification(ConsoleNotificationType::ViewerRefresh, (void*)(uint64_t)updateTiming.first);
}
}
}
}

View file

@ -180,6 +180,7 @@ public:
void Unlock();
bool IsThreadPaused();
bool IsDebuggerBlocked() { return _blockDebuggerRequestCount > 0; }
void SuspendDebugger(bool release);
void Serialize(ostream& out, bool includeSettings, int compressionLevel = 1);

View file

@ -528,7 +528,8 @@ namespace Mesen.Debugger.ViewModels
});
}
_coreData.Palette = DebugApi.GetPaletteInfo(CpuType);
DebugPaletteInfo palette = DebugApi.GetPaletteInfo(CpuType);
_coreData.Palette = palette.ColorCount > 0 ? palette : null;
}
RefreshTab();
}

View file

@ -72,6 +72,7 @@ namespace Mesen.Debugger.ViewModels
private byte[] _coreSourceData = Array.Empty<byte>();
private byte[] _sourceData = Array.Empty<byte>();
private bool _refreshPending;
private bool _inGameLoaded;
[Obsolete("For designer only")]
public TileViewerViewModel() : this(CpuType.Snes, new PictureViewer(), null) { }
@ -409,7 +410,9 @@ namespace Mesen.Debugger.ViewModels
private void Config_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
RefreshTab();
if(!_inGameLoaded) {
RefreshTab();
}
}
public void RefreshData()
@ -460,7 +463,7 @@ namespace Mesen.Debugger.ViewModels
private void InternalRefreshTab()
{
if(Disposed) {
if(Disposed || PaletteColors.Length == 0) {
return;
}
@ -650,8 +653,10 @@ namespace Mesen.Debugger.ViewModels
public void OnGameLoaded()
{
Dispatcher.UIThread.Post(() => {
_inGameLoaded = true;
InitForCpuType();
RefreshData();
_inGameLoaded = false;
});
}

View file

@ -415,7 +415,9 @@ namespace Mesen.Debugger.ViewModels
private void Config_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
RefreshTab();
if(!_inGameLoaded) {
RefreshTab();
}
}
[MemberNotNull(nameof(ViewerBitmap))]
@ -487,7 +489,7 @@ namespace Mesen.Debugger.ViewModels
_coreData.CopyTo(_data);
}
if(_data.PpuState == null || _data.PpuToolsState == null) {
if(_data.PpuState == null || _data.PpuToolsState == null || _data.RgbPalette.Length == 0) {
_refreshPending = false;
return;
}