diff --git a/Common/MemoryUtil.cpp b/Common/MemoryUtil.cpp index 246d6e11cd..297290844a 100644 --- a/Common/MemoryUtil.cpp +++ b/Common/MemoryUtil.cpp @@ -258,9 +258,6 @@ void *AllocateAlignedMemory(size_t size, size_t alignment) { } #endif #endif - char temp[32]; - NiceSizeFormat(size, temp, sizeof(temp)); - _assert_msg_(ptr != nullptr, "Failed to allocate aligned memory of size %s (%llu)", temp, (unsigned long long)size); return ptr; } diff --git a/Common/MemoryUtil.h b/Common/MemoryUtil.h index aa7cfd5dff..2aaf0ddd89 100644 --- a/Common/MemoryUtil.h +++ b/Common/MemoryUtil.h @@ -46,6 +46,7 @@ bool ProtectMemoryPages(const void* ptr, size_t size, uint32_t memProtFlags); void FreeMemoryPages(void* ptr, size_t size); // Regular aligned memory. Don't try to apply memory protection willy-nilly to memory allocated this way as in-page alignment is unknown (though could be checked). +// No longer asserts, will return nullptr on failure. void* AllocateAlignedMemory(size_t size, size_t alignment); void FreeAlignedMemory(void* ptr); diff --git a/Common/UI/Root.cpp b/Common/UI/Root.cpp index db8abe99cb..20eb0b4807 100644 --- a/Common/UI/Root.cpp +++ b/Common/UI/Root.cpp @@ -97,10 +97,8 @@ bool IsFocusMovementEnabled() { } void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root, bool ignoreInsets) { - if (!root) { - ERROR_LOG(Log::System, "Tried to layout a view hierarchy from a zero pointer root"); - return; - } + _assert_(root); + _assert_(&dc); Bounds rootBounds = ignoreInsets ? dc.GetBounds() : dc.GetLayoutBounds(); diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 43a8b33537..15e5fdfeda 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -108,6 +108,8 @@ TextureCacheCommon::TextureCacheCommon(Draw::DrawContext *draw, Draw2D *draw2D) // Here we need 2KB to expand a 1KB CLUT. expandClut_ = (u32 *)AllocateAlignedMemory(2048, 16); + _assert_(clutBufRaw_ && clutBufConverted_ && expandClut_); + // Zap so we get consistent behavior if the game fails to load some of the CLUT. memset(clutBufRaw_, 0, 2048); memset(clutBufConverted_, 0, 2048); diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 62b2ca3765..a91918b362 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -319,6 +319,7 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) { } data = (u8 *)AllocateAlignedMemory(dataSize, 16); + _assert_msg_(data != nullptr, "Failed to allocate aligned memory for texture level %d: %d bytes (%dx%d)", i, (int)dataSize, mipWidth, mipHeight); if (!data) { ERROR_LOG(Log::G3D, "Ran out of RAM trying to allocate a temporary texture upload buffer (%dx%d)", mipWidth, mipHeight); @@ -341,6 +342,7 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) { size_t dataSize = levelStride * plan.depth; u8 *data = (u8 *)AllocateAlignedMemory(dataSize, 16); + _assert_msg_(data != nullptr, "Failed to allocate aligned memory for 3d texture: %d bytes", (int)dataSize); memset(data, 0, levelStride * plan.depth); u8 *p = data; diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index eac7c21f85..b92cb7c1be 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -42,8 +42,7 @@ TransformUnit::TransformUnit() { decoded_ = (u8 *)AllocateAlignedMemory(TRANSFORM_BUF_SIZE, 16); - if (!decoded_) - return; + _assert_(decoded_); binner_ = new BinManager(); } diff --git a/GPU/Vulkan/ShaderManagerVulkan.cpp b/GPU/Vulkan/ShaderManagerVulkan.cpp index 9fbd98b895..5a2ea9e750 100644 --- a/GPU/Vulkan/ShaderManagerVulkan.cpp +++ b/GPU/Vulkan/ShaderManagerVulkan.cpp @@ -216,6 +216,7 @@ ShaderManagerVulkan::ShaderManagerVulkan(Draw::DrawContext *draw) uboAlignment_ = vulkan->GetPhysicalDeviceProperties().properties.limits.minUniformBufferOffsetAlignment; uniforms_ = (Uniforms *)AllocateAlignedMemory(sizeof(Uniforms), 16); + _assert_(uniforms_); static_assert(sizeof(uniforms_->ub_base) <= 512, "ub_base grew too big"); static_assert(sizeof(uniforms_->ub_lights) <= 512, "ub_lights grew too big"); diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index 6eb7826bdc..96d397315c 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -768,8 +768,11 @@ void TextureCacheVulkan::LoadVulkanTextureLevel(TexCacheEntry &entry, uint8_t *w if (scaleFactor > 1) { u32 fmt = dstFmt; // CPU scaling reads from the destination buffer so we want cached RAM. - uint8_t *rearrange = (uint8_t *)AllocateAlignedMemory(w * scaleFactor * h * scaleFactor * 4, 16); - scaler_.ScaleAlways((u32 *)rearrange, pixelData, w, h, &w, &h, scaleFactor); + size_t allocBytes = w * scaleFactor * h * scaleFactor * 4; + uint8_t *scaleBuf = (uint8_t *)AllocateAlignedMemory(allocBytes, 16); + _assert_msg_(scaleBuf, "Failed to allocate %d aligned bytes for texture scaler", (int)allocBytes); + + scaler_.ScaleAlways((u32 *)scaleBuf, pixelData, w, h, &w, &h, scaleFactor); pixelData = (u32 *)writePtr; // We always end up at 8888. Other parts assume this. @@ -779,13 +782,13 @@ void TextureCacheVulkan::LoadVulkanTextureLevel(TexCacheEntry &entry, uint8_t *w if (decPitch != rowPitch) { for (int y = 0; y < h; ++y) { - memcpy(writePtr + rowPitch * y, rearrange + decPitch * y, w * bpp); + memcpy(writePtr + rowPitch * y, scaleBuf + decPitch * y, w * bpp); } decPitch = rowPitch; } else { - memcpy(writePtr, rearrange, w * h * 4); + memcpy(writePtr, scaleBuf, w * h * 4); } - FreeAlignedMemory(rearrange); + FreeAlignedMemory(scaleBuf); } } diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 676fb3b2ab..1f92af05e3 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -774,6 +774,7 @@ void GameBrowser::Refresh() { auto mm = GetI18NCategory(I18NCat::MAINMENU); // No topbar on recent screen + gameList_ = nullptr; if (DisplayTopBar()) { LinearLayout *topBar = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); if (browseFlags_ & BrowseFlags::NAVIGATE) { @@ -828,12 +829,10 @@ void GameBrowser::Refresh() { if (*gridStyle_) { gameList_ = new UI::GridLayoutList(UI::GridLayoutSettings(150*g_Config.fGameGridScale, 85*g_Config.fGameGridScale), new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); - Add(gameList_); } else { UI::LinearLayout *gl = new UI::LinearLayoutList(UI::ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); gl->SetSpacing(4.0f); gameList_ = gl; - Add(gameList_); } } else { if (*gridStyle_) { @@ -854,8 +853,8 @@ void GameBrowser::Refresh() { // grid->Add(gameList_); // grid->Add(gridOptionColumn); // Add(grid); - Add(gameList_); } + Add(gameList_); // Find games in the current directory and create new ones. std::vector dirButtons; diff --git a/Windows/GEDebugger/VertexPreview.cpp b/Windows/GEDebugger/VertexPreview.cpp index bc2a69b4ee..054c038f99 100644 --- a/Windows/GEDebugger/VertexPreview.cpp +++ b/Windows/GEDebugger/VertexPreview.cpp @@ -200,18 +200,18 @@ static void ExpandBezier(int &count, int op, const std::vector &si output.count = 0; ControlPoints cpoints; - cpoints.pos = (Vec3f *)AllocateAlignedMemory(sizeof(Vec3f) * num_points, 16); - cpoints.tex = (Vec2f *)AllocateAlignedMemory(sizeof(Vec2f) * num_points, 16); - cpoints.col = (Vec4f *)AllocateAlignedMemory(sizeof(Vec4f) * num_points, 16); + cpoints.pos = new Vec3f[num_points]; + cpoints.tex = new Vec2f[num_points]; + cpoints.col = new Vec4f[num_points]; cpoints.Convert(points.data(), num_points); surface.Init((int)generatedVerts.size()); SoftwareTessellation(output, surface, gstate.vertType, cpoints); count = output.count; - FreeAlignedMemory(cpoints.pos); - FreeAlignedMemory(cpoints.tex); - FreeAlignedMemory(cpoints.col); + delete [] cpoints.pos; + delete [] cpoints.tex; + delete [] cpoints.col; } static void ExpandSpline(int &count, int op, const std::vector &simpleVerts, const std::vector &indices, std::vector &generatedVerts, std::vector &generatedInds) {