diff --git a/examples/common/bgfx_utils.cpp b/examples/common/bgfx_utils.cpp index a9516af16..0035076d8 100644 --- a/examples/common/bgfx_utils.cpp +++ b/examples/common/bgfx_utils.cpp @@ -5,6 +5,8 @@ #include // strlen +#include "common.h" + #include #include #include diff --git a/examples/common/common.h b/examples/common/common.h index fbcea73cc..3e80ee67f 100644 --- a/examples/common/common.h +++ b/examples/common/common.h @@ -3,7 +3,12 @@ * License: http://www.opensource.org/licenses/BSD-2-Clause */ +#ifndef COMMON_H_HEADER_GUARD +#define COMMON_H_HEADER_GUARD + #include #include #include "entry/entry.h" + +#endif // COMMON_H_HEADER_GUARD diff --git a/examples/common/entry/cmd.cpp b/examples/common/entry/cmd.cpp index 6dfcb37d8..bbe5a9a64 100644 --- a/examples/common/entry/cmd.cpp +++ b/examples/common/entry/cmd.cpp @@ -12,6 +12,7 @@ #include "dbg.h" #include "cmd.h" +#include "entry.h" //TinyStlCustomAllocator #include #include diff --git a/examples/common/entry/entry.h b/examples/common/entry/entry.h index 7f6524b8a..0c92440d4 100644 --- a/examples/common/entry/entry.h +++ b/examples/common/entry/entry.h @@ -18,6 +18,20 @@ extern "C" int _main_(int _argc, char** _argv); #define ENTRY_WINDOW_FLAG_ASPECT_RATIO UINT32_C(0x00000001) #define ENTRY_WINDOW_FLAG_FRAME UINT32_C(0x00000002) +// For a custom tinystl allocator, define this and implement TinyStlCustomAllocator somewhere in the project. +#ifndef ENTRY_CONFIG_USE_TINYSTL_CUSTOM_ALLOCATOR +# define ENTRY_CONFIG_USE_TINYSTL_CUSTOM_ALLOCATOR 0 +#endif // ENTRY_CONFIG_USE_TINYSTL + +#if ENTRY_CONFIG_USE_TINYSTL_CUSTOM_ALLOCATOR + struct TinyStlCustomAllocator + { + static void* static_allocate(size_t _bytes); + static void static_deallocate(void* _ptr, size_t /*_bytes*/); + }; +# define TINYSTL_ALLOCATOR TinyStlCustomAllocator +#endif //ENTRY_CONFIG_USE_TINYSTL_CUSTOM_ALLOCATOR + namespace entry { struct WindowHandle { uint16_t idx; }; diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index 163f18a81..9df31fdcc 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -65,15 +65,25 @@ static const int32_t SCROLL_AREA_PADDING = 6; static const int32_t AREA_HEADER = 20; static const float s_tabStops[4] = {150, 210, 270, 330}; -static void* imguiMalloc(size_t size, void* /*_userptr*/) -{ - return malloc(size); -} +// For a custom allocator, define this and implement imguiMalloc and imguiFree somewhere in the project. +#ifndef IMGUI_CONFIG_CUSTOM_ALLOCATOR +# define IMGUI_CONFIG_CUSTOM_ALLOCATOR 0 +#endif // ENTRY_CONFIG_USE_TINYSTL -static void imguiFree(void* _ptr, void* /*_userptr*/) -{ - free(_ptr); -} +#if IMGUI_CONFIG_CUSTOM_ALLOCATOR + void* imguiMalloc(size_t size, void* /*_userptr*/); + void imguiFree(void* _ptr, void* /*_userptr*/); +#else + static void* imguiMalloc(size_t _size, void* /*_userptr*/) + { + return malloc(_size); + } + + static void imguiFree(void* _ptr, void* /*_userptr*/) + { + free(_ptr); + } +#endif //IMGUI_CONFIG_CUSTOM_ALLOCATOR #define IMGUI_MIN(_a, _b) (_a)<(_b)?(_a):(_b) #define IMGUI_MAX(_a, _b) (_a)>(_b)?(_a):(_b)