瀏覽代碼

Fix to allow compiling in unity builds where stb_rectpack/stb_truetype may be already included in the same compilation unit.

omar 7 年之前
父節點
當前提交
280c05e4f8
共有 3 個文件被更改,包括 7 次插入2 次删除
  1. 1 0
      CHANGELOG.txt
  2. 2 2
      imgui.cpp
  3. 4 0
      imgui_draw.cpp

+ 1 - 0
CHANGELOG.txt

@@ -69,6 +69,7 @@ Other Changes:
 - Fonts: When building font atlas, glyphs that are missing in the fonts are not using the glyph slot to render a dummy/default glyph. Saves space and allow merging fonts with 
   overlapping font ranges such as FontAwesome5 which split out the Brands separately from the Solid fonts. (#1703, #1671)
 - Misc: Added IMGUI_CHECKVERSION() macro to compare version string and data structure sizes in order to catch issues with mismatching compilation unit settings. (#1695, #1769)
+- Misc: Fix to allow compiling in unity builds where stb_rectpack/stb_truetype may be already included in the same compilation unit.
 - Demo: Fixed Overlay: Added a context menu item to enable freely moving the window. 
 - Examples: Calling IMGUI_CHECKVERSION() in the main.cpp of every example application.
 - Examples: Allegro 5: Added support for 32-bit indices setup via defining ImDrawIdx, to avoid an unnecessary conversion (Allegro 5 doesn't support 16-bit indices).

+ 2 - 2
imgui.cpp

@@ -2594,10 +2594,10 @@ float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
 
 //-----------------------------------------------------------------------------
 
-void* ImGui::MemAlloc(size_t sz)
+void* ImGui::MemAlloc(size_t size)
 {
     GImAllocatorActiveAllocationsCount++;
-    return GImAllocatorAllocFunc(sz, GImAllocatorUserData);
+    return GImAllocatorAllocFunc(size, GImAllocatorUserData);
 }
 
 void ImGui::MemFree(void* ptr)

+ 4 - 0
imgui_draw.cpp

@@ -91,6 +91,7 @@ namespace IMGUI_STB_NAMESPACE
 #pragma GCC diagnostic ignored "-Wcast-qual"                // warning: cast from type 'const xxxx *' to type 'xxxx *' casts away qualifiers
 #endif
 
+#ifndef STB_RECT_PACK_IMPLEMENTATION                        // in case the user already have an implementation in the _same_ compilation unit (e.g. unity builds)
 #ifndef IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
 #define STBRP_STATIC
 #define STBRP_ASSERT(x)    IM_ASSERT(x)
@@ -101,7 +102,9 @@ namespace IMGUI_STB_NAMESPACE
 #else
 #include "stb_rect_pack.h"
 #endif
+#endif
 
+#ifndef STB_TRUETYPE_IMPLEMENTATION                         // in case the user already have an implementation in the _same_ compilation unit (e.g. unity builds)
 #ifndef IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
 #define STBTT_malloc(x,u)  ((void)(u), ImGui::MemAlloc(x))
 #define STBTT_free(x,u)    ((void)(u), ImGui::MemFree(x))
@@ -116,6 +119,7 @@ namespace IMGUI_STB_NAMESPACE
 #else
 #include "stb_truetype.h"
 #endif
+#endif
 
 #ifdef __GNUC__
 #pragma GCC diagnostic pop