diff --git a/desmume/src/GPU.cpp b/desmume/src/GPU.cpp index 18a2883f2..1b9224f1c 100644 --- a/desmume/src/GPU.cpp +++ b/desmume/src/GPU.cpp @@ -4142,7 +4142,8 @@ GPUSubsystem::GPUSubsystem() _customVRAM = NULL; _customVRAMBlank = NULL; _customFramebuffer = (u16 *)malloc_alignedCacheLine(GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT * sizeof(u16) * 2); - _nativeFramebuffer = (u16 *)malloc_alignedCacheLine(GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT * sizeof(u16) * 2); + + ClearWithColor(0x8000); _displayInfo.isCustomSizeRequested = false; _displayInfo.customWidth = GPU_FRAMEBUFFER_NATIVE_WIDTH; @@ -4162,8 +4163,6 @@ GPUSubsystem::GPUSubsystem() _displayInfo.renderedHeight[1] = GPU_FRAMEBUFFER_NATIVE_HEIGHT; _displayInfo.renderedBuffer[0] = _displayInfo.nativeBuffer[0]; _displayInfo.renderedBuffer[1] = _displayInfo.nativeBuffer[1]; - - ClearWithColor(0x8000); } GPUSubsystem::~GPUSubsystem() @@ -4171,7 +4170,6 @@ GPUSubsystem::~GPUSubsystem() delete osd; osd = NULL; - free_aligned(this->_nativeFramebuffer); free_aligned(this->_customFramebuffer); free_aligned(this->_customVRAM); @@ -4186,6 +4184,17 @@ GPUSubsystem::~GPUSubsystem() gfx3d_deinit(); } +GPUSubsystem* GPUSubsystem::Allocate() +{ + return new(malloc_aligned64(sizeof(GPUSubsystem))) GPUSubsystem(); +} + +void GPUSubsystem::FinalizeAndDeallocate() +{ + this->~GPUSubsystem(); + free_aligned(this); +} + void GPUSubsystem::Reset() { if (this->_customVRAM == NULL || this->_customVRAM == NULL || this->_customFramebuffer == NULL) diff --git a/desmume/src/GPU.h b/desmume/src/GPU.h index 8f36eb99a..6acf974ef 100644 --- a/desmume/src/GPU.h +++ b/desmume/src/GPU.h @@ -1324,16 +1324,17 @@ private: u16 *_customVRAM; u16 *_customVRAMBlank; - //zero 13-sep-2015 - had to change this to a pointer instead of an array. as an array, we need the whole GPUSubsystem aligned, and that gets annoying. - //If having the array instead of the pointer is faster, we can change it back and just deal with this type being allocated specially - u16 *_nativeFramebuffer; + CACHE_ALIGN u16 _nativeFramebuffer[GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT * 2]; u16 *_customFramebuffer; NDSDisplayInfo _displayInfo; -public: GPUSubsystem(); ~GPUSubsystem(); + +public: + static GPUSubsystem* Allocate(); + void FinalizeAndDeallocate(); void Reset(); VRAM3DUsageProperties& GetVRAM3DUsageProperties(); diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index 1501c5bb9..9822a5af9 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -170,10 +170,10 @@ int NDS_Init() if (GPU != NULL) { - delete GPU; + GPU->FinalizeAndDeallocate(); } - GPU = new GPUSubsystem; + GPU = GPUSubsystem::Allocate(); if (SPU_Init(SNDCORE_DUMMY, 740) != 0) return -1; @@ -191,7 +191,7 @@ void NDS_DeInit(void) gameInfo.closeROM(); SPU_DeInit(); - delete GPU; + GPU->FinalizeAndDeallocate(); GPU = NULL; MMU_DeInit();