From 51975fb00dd1e8012c03e8e1ede191977f71a053 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 18 Jul 2015 13:12:40 -0400 Subject: [PATCH] unbiased the algorithm from just checking if only 4 or 8 MB --- .../N64 System/Mips/Memory Virtual Mem.cpp | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Source/Project64/N64 System/Mips/Memory Virtual Mem.cpp b/Source/Project64/N64 System/Mips/Memory Virtual Mem.cpp index afabe3497..58156b8a4 100644 --- a/Source/Project64/N64 System/Mips/Memory Virtual Mem.cpp +++ b/Source/Project64/N64 System/Mips/Memory Virtual Mem.cpp @@ -5379,15 +5379,27 @@ void CMipsMemoryVM::RdramChanged ( CMipsMemoryVM * _this ) { return; } - if (old_size == 0x800000) + if (old_size > new_size) { - VirtualFree(_this->m_RDRAM + 0x400000, 0x400000, MEM_DECOMMIT); + VirtualFree( + _this->m_RDRAM + new_size, + old_size - new_size, + MEM_DECOMMIT + ); } else - { - if (VirtualAlloc(_this->m_RDRAM + 0x400000, 0x400000, MEM_COMMIT, PAGE_READWRITE)==NULL) + { + void * result; + + result = VirtualAlloc( + _this->m_RDRAM + old_size, + new_size - old_size, + MEM_COMMIT, + PAGE_READWRITE + ); + if (result == NULL) { - WriteTrace(TraceError,__FUNCTION__ ": failed to allocate extended memory"); + WriteTrace(TraceError, __FUNCTION__": failed to allocate extended memory"); g_Notify -> FatalError(GS(MSG_MEM_ALLOC_ERROR)); } }