Merge remote-tracking branch 'origin/1.11' into sdl_platform_1.11
# Conflicts: # Source/Engine/Platform/Windows/WindowsPlatform.cpp # Source/Tools/Flax.Build/Build/ProjectTarget.cs # Source/Tools/Flax.Build/Configuration.cs
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "Engine/Core/Utilities.h"
|
||||
#if COMPILE_WITH_PROFILER
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
#include "Engine/Profiler/ProfilerMemory.h"
|
||||
#endif
|
||||
#include "Engine/Threading/Threading.h"
|
||||
#include "Engine/Engine/CommandLine.h"
|
||||
@@ -206,6 +207,16 @@ void PlatformBase::Exit()
|
||||
|
||||
#if COMPILE_WITH_PROFILER
|
||||
|
||||
#define TEST_MALLOC 0
|
||||
#if TEST_MALLOC
|
||||
#include "Engine/Utilities/MallocTester.h"
|
||||
MallocTester& GetMallocTester()
|
||||
{
|
||||
static MallocTester MallocTest;
|
||||
return MallocTest;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define TRACY_ENABLE_MEMORY (TRACY_ENABLE)
|
||||
|
||||
void PlatformBase::OnMemoryAlloc(void* ptr, uint64 size)
|
||||
@@ -213,12 +224,21 @@ void PlatformBase::OnMemoryAlloc(void* ptr, uint64 size)
|
||||
if (!ptr)
|
||||
return;
|
||||
|
||||
#if TEST_MALLOC
|
||||
if (GetMallocTester().OnMalloc(ptr, size))
|
||||
LOG(Fatal, "Invalid mallloc detected for pointer 0x{0:x} ({1} bytes)!\n{2}", (uintptr)ptr, size, Platform::GetStackTrace(3));
|
||||
#endif
|
||||
|
||||
#if TRACY_ENABLE_MEMORY
|
||||
// Track memory allocation in Tracy
|
||||
//tracy::Profiler::MemAlloc(ptr, (size_t)size, false);
|
||||
tracy::Profiler::MemAllocCallstack(ptr, (size_t)size, 12, false);
|
||||
#endif
|
||||
|
||||
// Register in memory profiler
|
||||
if (ProfilerMemory::Enabled)
|
||||
ProfilerMemory::OnMemoryAlloc(ptr, size);
|
||||
|
||||
// Register allocation during the current CPU event
|
||||
auto thread = ProfilerCPU::GetCurrentThread();
|
||||
if (thread != nullptr && thread->Buffer.GetCount() != 0)
|
||||
@@ -236,10 +256,19 @@ void PlatformBase::OnMemoryFree(void* ptr)
|
||||
if (!ptr)
|
||||
return;
|
||||
|
||||
// Register in memory profiler
|
||||
if (ProfilerMemory::Enabled)
|
||||
ProfilerMemory::OnMemoryFree(ptr);
|
||||
|
||||
#if TRACY_ENABLE_MEMORY
|
||||
// Track memory allocation in Tracy
|
||||
tracy::Profiler::MemFree(ptr, false);
|
||||
#endif
|
||||
|
||||
#if TEST_MALLOC
|
||||
if (GetMallocTester().OnFree(ptr))
|
||||
LOG(Fatal, "Invalid free detected for pointer 0x{0:x}!\n{1}", (uintptr)ptr, Platform::GetStackTrace(3));
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -325,10 +354,11 @@ void PlatformBase::Fatal(const StringView& msg, void* context, FatalErrorType er
|
||||
Engine::RequestingExit();
|
||||
|
||||
// Collect crash info (platform-dependant implementation that might collect stack trace and/or create memory dump)
|
||||
#if LOG_ENABLE
|
||||
{
|
||||
// Log separation for crash info
|
||||
LOG_FLUSH();
|
||||
Log::Logger::WriteFloor();
|
||||
LOG_FLOOR();
|
||||
LOG(Error, "");
|
||||
LOG(Error, "Critical error! Reason: {0}", msg);
|
||||
LOG(Error, "");
|
||||
@@ -396,6 +426,12 @@ void PlatformBase::Fatal(const StringView& msg, void* context, FatalErrorType er
|
||||
LOG(Error, "External Used Physical Memory: {0} ({1}%)", Utilities::BytesToText(externalUsedPhysical), (int32)(100 * externalUsedPhysical / memoryStats.TotalPhysicalMemory));
|
||||
LOG(Error, "External Used Virtual Memory: {0} ({1}%)", Utilities::BytesToText(externalUsedVirtual), (int32)(100 * externalUsedVirtual / memoryStats.TotalVirtualMemory));
|
||||
}
|
||||
#if COMPILE_WITH_PROFILER
|
||||
if (error == FatalErrorType::OutOfMemory || error == FatalErrorType::GPUOutOfMemory)
|
||||
{
|
||||
ProfilerMemory::Dump();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (Log::Logger::LogFilePath.HasChars())
|
||||
{
|
||||
@@ -408,13 +444,14 @@ void PlatformBase::Fatal(const StringView& msg, void* context, FatalErrorType er
|
||||
|
||||
// Capture the original log file
|
||||
LOG(Error, "");
|
||||
Log::Logger::WriteFloor();
|
||||
LOG_FLOOR();
|
||||
LOG_FLUSH();
|
||||
FileSystem::CopyFile(crashDataFolder / TEXT("Log.txt"), Log::Logger::LogFilePath);
|
||||
|
||||
LOG(Error, "Crash info collected.");
|
||||
Log::Logger::WriteFloor();
|
||||
LOG_FLOOR();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Show error message
|
||||
if (Engine::ReportCrash.IsBinded())
|
||||
|
||||
Reference in New Issue
Block a user