21#include "MainWindow.h"
22#include "WorldEditor.h"
23#include "aeongames/AeonEngine.hpp"
28#pragma comment(lib, "Dbghelp.lib")
30FILE* gAllocationLog = NULL;
31int AllocHook (
int allocType,
void *userData,
size_t size,
int
32 blockType,
long requestNumber,
const unsigned char *filename,
int
37 if ( ( blockType == _CRT_BLOCK ) )
41 if ( gAllocationLog && allocType != _HOOK_FREE )
43 STACKFRAME stack_frame{};
45 uint8_t symbol_buffer[
sizeof ( IMAGEHLP_SYMBOL64 ) + MAX_PATH] {};
46 PIMAGEHLP_SYMBOL64 symbol =
reinterpret_cast<PIMAGEHLP_SYMBOL64
> ( symbol_buffer );
47 DWORD64 displacement{};
49 std::lock_guard<std::mutex> hold ( m );
51 RtlCaptureContext ( &context );
52 stack_frame.AddrPC.Offset = context.Rip;
53 stack_frame.AddrPC.Mode = AddrModeFlat;
54 stack_frame.AddrStack.Offset = context.Rsp;
55 stack_frame.AddrStack.Mode = AddrModeFlat;
56 stack_frame.AddrFrame.Offset = context.Rbp;
57 stack_frame.AddrFrame.Mode = AddrModeFlat;
59 symbol->SizeOfStruct =
sizeof ( IMAGEHLP_SYMBOL64 );
60 symbol->MaxNameLength = MAX_PATH;
62 fprintf ( gAllocationLog,
"%s %ld Size %llu File %s Line %d\n",
63 ( allocType == _HOOK_ALLOC ) ?
"ALLOCATION" :
64 ( allocType == _HOOK_REALLOC ) ?
"REALLOCATION" :
"DEALLOCATION",
66 size, ( filename != NULL ) ?
reinterpret_cast<const char*
> ( filename ) :
static_cast<const char*
> (
"Unknown" ), lineNumber );
68 while ( StackWalk64 ( IMAGE_FILE_MACHINE_AMD64, GetCurrentProcess(), GetCurrentThread(), &stack_frame, &context, NULL, SymFunctionTableAccess64, SymGetModuleBase64, NULL ) )
70 SymGetSymFromAddr64 ( GetCurrentProcess(), ( ULONG64 ) stack_frame.AddrPC.Offset, &displacement, symbol );
71 UnDecorateSymbolName ( symbol->Name, ( PSTR ) name, 1024, UNDNAME_COMPLETE );
72 fprintf ( gAllocationLog,
"%s\n", name );
75 fflush ( gAllocationLog );
81int ENTRYPOINT main (
int argc,
char *argv[] )
87 SymInitialize ( GetCurrentProcess(),
nullptr, TRUE );
88 gAllocationLog = fopen (
"allocation.log",
"wt" );
89 _CrtSetAllocHook ( AllocHook );
94 _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
113 mainWindow.showNormal();
114 retval = worldeditor.exec();
120 if ( gAllocationLog )
122 _CrtSetAllocHook (
nullptr );
123 FinalizeModuleTable();
124 fclose ( gAllocationLog );
125 gAllocationLog = NULL;
Main window of the world editor application.
Main application class for the world editor.
DLL bool InitializeGlobalEnvironment(int argc=0, char *argv[]=nullptr)
Initialize the global engine environment.
DLL void FinalizeGlobalEnvironment()
Shut down the global engine environment and release resources.