From dc41f091898b39144110d99feb227d8bbab15b2c Mon Sep 17 00:00:00 2001 From: SuuperW Date: Mon, 9 Jul 2018 11:41:46 -0500 Subject: [PATCH] some code cleanup; fix crash on changing to 15 bpp from a higher bpp --- desmume/src/frontend/windows/main.cpp | 20 ++++++++++++++------ desmume/src/frontend/windows/video.h | 2 -- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/desmume/src/frontend/windows/main.cpp b/desmume/src/frontend/windows/main.cpp index 286e3d7f4..0dfca94d3 100755 --- a/desmume/src/frontend/windows/main.cpp +++ b/desmume/src/frontend/windows/main.cpp @@ -6540,11 +6540,12 @@ LRESULT CALLBACK GFX3DSettingsDlgProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp) } if(IsDlgCheckboxChecked(hw,IDC_TEXSCALE_1)) CommonSettings.GFX3D_Renderer_TextureScalingFactor = 1; - if(IsDlgCheckboxChecked(hw,IDC_TEXSCALE_2)) CommonSettings.GFX3D_Renderer_TextureScalingFactor = 2; - if(IsDlgCheckboxChecked(hw,IDC_TEXSCALE_4)) CommonSettings.GFX3D_Renderer_TextureScalingFactor = 4; + else if(IsDlgCheckboxChecked(hw,IDC_TEXSCALE_2)) CommonSettings.GFX3D_Renderer_TextureScalingFactor = 2; + else if(IsDlgCheckboxChecked(hw,IDC_TEXSCALE_4)) CommonSettings.GFX3D_Renderer_TextureScalingFactor = 4; if(IsDlgCheckboxChecked(hw, IDC_GPU_15BPP)) gpu_bpp = 15; - if(IsDlgCheckboxChecked(hw, IDC_GPU_18BPP)) gpu_bpp = 18; - if(IsDlgCheckboxChecked(hw, IDC_GPU_24BPP)) gpu_bpp = 24; + else if(IsDlgCheckboxChecked(hw, IDC_GPU_18BPP)) gpu_bpp = 18; + else if(IsDlgCheckboxChecked(hw, IDC_GPU_24BPP)) gpu_bpp = 24; + CommonSettings.GFX3D_Renderer_TextureDeposterize = IsDlgCheckboxChecked(hw,IDC_TEX_DEPOSTERIZE); CommonSettings.GFX3D_Renderer_TextureSmoothing = IsDlgCheckboxChecked(hw,IDC_TEX_SMOOTH); @@ -6552,11 +6553,18 @@ LRESULT CALLBACK GFX3DSettingsDlgProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp) Lock lock(win_backbuffer_sync); if(display_mutex) slock_lock(display_mutex); Change3DCoreWithFallbackAndSave(ComboBox_GetCurSel(GetDlgItem(hw, IDC_3DCORE))); - video.SetPrescale(newPrescaleHD, 1); - GPU->SetCustomFramebufferSize(GPU_FRAMEBUFFER_NATIVE_WIDTH*video.prescaleHD, GPU_FRAMEBUFFER_NATIVE_HEIGHT*video.prescaleHD); + if (newPrescaleHD != video.prescaleHD) + { + video.SetPrescale(newPrescaleHD, 1); + GPU->SetCustomFramebufferSize(GPU_FRAMEBUFFER_NATIVE_WIDTH*video.prescaleHD, GPU_FRAMEBUFFER_NATIVE_HEIGHT*video.prescaleHD); + } SyncGpuBpp(); UpdateScreenRects(); if(display_mutex) slock_unlock(display_mutex); + // shrink buffer size if necessary + const NDSDisplayInfo &displayInfo = GPU->GetDisplayInfo(); + size_t newBufferSize = displayInfo.customWidth * displayInfo.customHeight * 2 * displayInfo.pixelBytes; + if (newBufferSize < video.srcBufferSize) video.srcBufferSize = newBufferSize; } WritePrivateProfileBool("3D", "HighResolutionInterpolateColor", CommonSettings.GFX3D_HighResolutionInterpolateColor, IniName); diff --git a/desmume/src/frontend/windows/video.h b/desmume/src/frontend/windows/video.h index 26f122afb..66938f33b 100644 --- a/desmume/src/frontend/windows/video.h +++ b/desmume/src/frontend/windows/video.h @@ -94,8 +94,6 @@ public: // clean the new buffers clear(); - // prevent crashing when reducing the scaling - srcBufferSize = 0; } enum {