Skip to content

Commit 28edf8b

Browse files
committed
refactor(macos): pivot to upstream PR PathOfBuildingCommunity#102 LuaJIT-fix approach
Replace the custom-allocator + module-bisecting workaround stack with the upstream macOS approach from PathOfBuildingCommunity/PathOfBuilding-SimpleGraphic PR PathOfBuildingCommunity#102, which fixes the arm64/GC64 allocation problem at the source by pinning a patched LuaJIT (port 2026-03-30_1, ref 18b087cd) rather than working around it in the engine. Removed (no longer needed once LuaJIT is fixed correctly): - mac_gc64_alloc custom allocator + magic sentinel (ui_main.cpp) - mac_pload_* / bisect / coroutine module-loading machinery (~1050 lines across ui_api.cpp and ui_main.cpp) that worked around Data.lua load failures, themselves a symptom of the same GC64 bug - sys_IMain::launchCwd and the host argv handling in sys_main.cpp - mac/entry.cpp (win/entry.cpp already compiles on macOS via its visibility macros and _WIN32 guards, matching upstream) Adopted from PR PathOfBuildingCommunity#102: - Patched LuaJIT vcpkg port (2026-03-30_1) + arm64-osx triplet + version files; baseline bumped to 2026-05-22 - AppendLocalLuaSubdir() replacing inline package.path logic - Retina/HiDPI cursor scaling + GLFW_ANGLE_PLATFORM_TYPE_METAL (sys_video.cpp) - .app bundle base-path detection (sys_main.cpp) - Portable std::this_thread::sleep_for and size_t casts (r_main/r_texture) - VirtualScreenHeight() in r_font; base64/common include + guard fixes - Lua-cURLv3 luaL_setfuncs patch + CMake patch-application; WIN32-guarded lua-utf8/luasocket; ZSTD target selection Retained (our only divergence, additive and APPLE-guarded): - pob-host launcher executable (mac/host.cpp -> "Path of Building-PoE2") that links the dylib for a runnable dev binary; upstream defers this to a separate launcher repo. The host shifts argv itself so the engine stays identical to upstream. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E69xvgJuYgUaR1eHY3Qf3o
1 parent 7035e52 commit 28edf8b

35 files changed

Lines changed: 3948 additions & 6682 deletions

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
patches/* -text

CMakeLists.txt

Lines changed: 60 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ set(SIMPLEGRAPHIC_SOURCES
6262
"engine/system/sys_main.h"
6363
"engine/system/sys_opengl.h"
6464
"engine/system/sys_video.h"
65+
"win/entry.cpp"
6566
"ui.h"
6667
"ui_api.cpp"
6768
"ui_console.cpp"
@@ -75,14 +76,6 @@ set(SIMPLEGRAPHIC_SOURCES
7576
"ui_subscript.h"
7677
)
7778

78-
if (APPLE)
79-
list(APPEND SIMPLEGRAPHIC_SOURCES "mac/entry.cpp")
80-
elseif (WIN32)
81-
list(APPEND SIMPLEGRAPHIC_SOURCES "win/entry.cpp")
82-
else ()
83-
list(APPEND SIMPLEGRAPHIC_SOURCES "win/entry.cpp")
84-
endif ()
85-
8679
set (SIMPLEGRAPHIC_PLATFORM_SOURCES)
8780
if (APPLE)
8881
list (APPEND SIMPLEGRAPHIC_PLATFORM_SOURCES
@@ -135,14 +128,15 @@ find_package(re2 CONFIG REQUIRED)
135128
find_package(sol2 CONFIG REQUIRED)
136129
find_package(Threads REQUIRED)
137130
find_package(zstd REQUIRED)
138-
if(TARGET zstd::libzstd_shared)
139-
set(ZSTD_TARGET zstd::libzstd_shared)
140-
else()
141-
set(ZSTD_TARGET zstd::libzstd_static)
142-
endif()
143131
find_package(ZLIB REQUIRED)
144132
find_package(WebP)
145133

134+
if (TARGET zstd::libzstd_shared)
135+
set(ZSTD_LIBRARY zstd::libzstd_shared)
136+
else ()
137+
set(ZSTD_LIBRARY zstd::libzstd_static)
138+
endif ()
139+
146140
add_library(cmp_core STATIC
147141
dep/compressonator/cmp_core/source/cmp_core.cpp
148142
dep/compressonator/cmp_core/source/cmp_core.h
@@ -229,12 +223,10 @@ endif ()
229223
if (APPLE)
230224
find_library(CORE_FOUNDATION_LIBRARY CoreFoundation)
231225
find_library(APPLICATION_SERVICES_LIBRARY ApplicationServices)
232-
find_library(FOUNDATION_FRAMEWORK Foundation)
233226
target_link_libraries(SimpleGraphic
234227
PRIVATE
235228
${CORE_FOUNDATION_LIBRARY}
236229
${APPLICATION_SERVICES_LIBRARY}
237-
${FOUNDATION_FRAMEWORK}
238230
)
239231
endif ()
240232

@@ -254,10 +246,13 @@ target_link_libraries(SimpleGraphic
254246
Threads::Threads
255247
WebP::webpdecoder
256248
ZLIB::ZLIB
257-
${ZSTD_TARGET}
249+
${ZSTD_LIBRARY}
258250
)
259251

260252
if (APPLE)
253+
# Native launcher executable. Upstream defers packaging to a separate
254+
# launcher repo; this gives us a runnable binary alongside the dylib,
255+
# mirroring "Path of Building-PoE2.exe" + "SimpleGraphic.dll" on Windows.
261256
set(PoB_HOST_TARGET pob-host)
262257
add_executable(${PoB_HOST_TARGET} mac/host.cpp)
263258
set_target_properties(${PoB_HOST_TARGET} PROPERTIES
@@ -309,6 +304,35 @@ if (WIN32)
309304
endif ()
310305

311306

307+
find_package(Git QUIET)
308+
if (NOT GIT_EXECUTABLE)
309+
set(GIT_EXECUTABLE git)
310+
endif ()
311+
312+
function(apply_submodule_patch SUBMODULE_DIR PATCH_FILE)
313+
execute_process(
314+
COMMAND ${GIT_EXECUTABLE} -C ${SUBMODULE_DIR} apply --ignore-whitespace --reverse --check ${PATCH_FILE}
315+
RESULT_VARIABLE _patch_in_place
316+
OUTPUT_QUIET ERROR_QUIET
317+
)
318+
if (NOT _patch_in_place EQUAL 0)
319+
execute_process(
320+
COMMAND ${GIT_EXECUTABLE} -C ${SUBMODULE_DIR} apply --ignore-whitespace ${PATCH_FILE}
321+
RESULT_VARIABLE _patch_result
322+
)
323+
if (NOT _patch_result EQUAL 0)
324+
message(FATAL_ERROR "Failed to apply ${PATCH_FILE}")
325+
endif ()
326+
message(STATUS "Applied patch: ${PATCH_FILE}")
327+
endif ()
328+
endfunction()
329+
330+
apply_submodule_patch(
331+
${CMAKE_CURRENT_SOURCE_DIR}/libs/Lua-cURLv3
332+
${CMAKE_CURRENT_SOURCE_DIR}/patches/Lua-cURLv3-skip-luaL_setfuncs-on-luajit.patch
333+
)
334+
335+
312336
# lcurl module
313337

314338
set(LCURL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libs/Lua-cURLv3)
@@ -323,57 +347,37 @@ target_include_directories(lcurl
323347
target_link_libraries(lcurl
324348
PRIVATE
325349
CURL::libcurl
326-
$<$<NOT:$<BOOL:${APPLE}>>:LuaJIT::LuaJIT>
350+
LuaJIT::LuaJIT
327351
)
328352

329-
if(APPLE)
330-
target_include_directories(lcurl PRIVATE $<TARGET_PROPERTY:LuaJIT::LuaJIT,INTERFACE_INCLUDE_DIRECTORIES>)
331-
target_link_options(lcurl PRIVATE -undefined dynamic_lookup)
332-
endif()
333-
334353
install(TARGETS lcurl RUNTIME DESTINATION ".")
335354
install(FILES $<TARGET_RUNTIME_DLLS:lcurl> DESTINATION ".")
336355

337356
# luautf8 module
338357

339358
add_library(lua-utf8 SHARED libs/luautf8/lutf8lib.c)
340359

341-
target_compile_definitions(lua-utf8
342-
PRIVATE
343-
$<$<BOOL:${WIN32}>:LUA_BUILD_AS_DLL>
344-
)
345-
346-
if(NOT WIN32)
347-
target_compile_options(lua-utf8 PRIVATE -include limits.h)
348-
endif()
360+
if (WIN32)
361+
target_compile_definitions(lua-utf8
362+
PRIVATE
363+
LUA_BUILD_AS_DLL
364+
)
365+
endif ()
349366

350367
target_include_directories(lua-utf8
351368
PRIVATE
352369
)
353370

354371
target_link_libraries(lua-utf8
355372
PRIVATE
356-
$<$<NOT:$<BOOL:${APPLE}>>:LuaJIT::LuaJIT>
373+
LuaJIT::LuaJIT
357374
)
358375

359-
if(APPLE)
360-
target_include_directories(lua-utf8 PRIVATE $<TARGET_PROPERTY:LuaJIT::LuaJIT,INTERFACE_INCLUDE_DIRECTORIES>)
361-
target_link_options(lua-utf8 PRIVATE -undefined dynamic_lookup)
362-
endif()
363-
364376
install(TARGETS lua-utf8 RUNTIME DESTINATION ".")
365377
install(FILES $<TARGET_RUNTIME_DLLS:lua-utf8> DESTINATION ".")
366378

367379
# luasocket module
368380

369-
if(WIN32)
370-
set(LUASOCKET_PLATFORM_SRC "libs/luasocket/src/wsocket.c")
371-
set(LUASOCKET_PLATFORM_LIBS wsock32 ws2_32)
372-
else()
373-
set(LUASOCKET_PLATFORM_SRC "libs/luasocket/src/usocket.c")
374-
set(LUASOCKET_PLATFORM_LIBS "")
375-
endif()
376-
377381
add_library(luasocket SHARED
378382
"libs/luasocket/src/auxiliar.c"
379383
"libs/luasocket/src/buffer.c"
@@ -387,26 +391,29 @@ add_library(luasocket SHARED
387391
"libs/luasocket/src/tcp.c"
388392
"libs/luasocket/src/timeout.c"
389393
"libs/luasocket/src/udp.c"
390-
${LUASOCKET_PLATFORM_SRC}
391394
)
392395

396+
if (WIN32)
397+
target_sources(luasocket PRIVATE "libs/luasocket/src/wsocket.c")
398+
else ()
399+
target_sources(luasocket PRIVATE "libs/luasocket/src/usocket.c")
400+
endif ()
401+
393402
target_include_directories(luasocket
394403
PRIVATE
395404
${LSOCKET_SOURCE_DIR}/src
396405
)
397406

398407
target_link_libraries(luasocket
399408
PRIVATE
400-
$<$<NOT:$<BOOL:${APPLE}>>:LuaJIT::LuaJIT>
401-
${LUASOCKET_PLATFORM_LIBS}
409+
LuaJIT::LuaJIT
402410
)
403411

404-
if(APPLE)
405-
target_include_directories(luasocket PRIVATE $<TARGET_PROPERTY:LuaJIT::LuaJIT,INTERFACE_INCLUDE_DIRECTORIES>)
406-
target_link_options(luasocket PRIVATE -undefined dynamic_lookup)
407-
endif()
412+
if (WIN32)
413+
target_link_libraries(luasocket PRIVATE wsock32 ws2_32)
414+
endif ()
408415

409-
set_target_properties( luasocket PROPERTIES OUTPUT_NAME "socket" )
416+
set_target_properties( luasocket PROPERTIES OUTPUT_NAME "socket" )
410417
install(TARGETS luasocket RUNTIME DESTINATION ".")
411418
install(FILES $<TARGET_RUNTIME_DLLS:luasocket> DESTINATION ".")
412419

@@ -420,14 +427,9 @@ target_include_directories(lzip
420427

421428
target_link_libraries(lzip
422429
PRIVATE
423-
$<$<NOT:$<BOOL:${APPLE}>>:LuaJIT::LuaJIT>
430+
LuaJIT::LuaJIT
424431
ZLIB::ZLIB
425432
)
426433

427-
if(APPLE)
428-
target_include_directories(lzip PRIVATE $<TARGET_PROPERTY:LuaJIT::LuaJIT,INTERFACE_INCLUDE_DIRECTORIES>)
429-
target_link_options(lzip PRIVATE -undefined dynamic_lookup)
430-
endif()
431-
432434
install(TARGETS lzip RUNTIME DESTINATION ".")
433435
install(FILES $<TARGET_RUNTIME_DLLS:lzip> DESTINATION ".")

cmake/FindLuaJIT.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if (DEFINED VCPKG_INSTALLED_DIR AND DEFINED VCPKG_TARGET_TRIPLET)
99

1010
find_path(LuaJIT_INCLUDE_DIR luajit.h
1111
PATHS ${LuaJIT_SEARCH_ROOT}/include
12-
PATH_SUFFIXES luajit luajit-2.1 luajit-2.0
12+
PATH_SUFFIXES luajit luajit-2.0 luajit-2.1
1313
NO_DEFAULT_PATH)
1414

1515
find_library(LuaJIT_LIBRARY_RELEASE NAMES lua51 luajit-5.1

engine/common/base64.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@
2626

2727
/* Base64 encoding/decoding */
2828

29-
#include <stddef.h>
29+
#include "base64.h"
30+
3031
#include <stdlib.h>
3132
#include <string.h>
3233

33-
#include "base64.h"
34-
3534
/* ---- Base64 Encoding/Decoding Table --- */
3635
/* Padding character string starts at offset 64. */
3736
static const char base64encdec[] =
@@ -49,7 +48,7 @@ static const unsigned char decodetable[] =
4948
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
5049
48, 49, 50, 51 };
5150
/*
52-
* Base64Decode() n�e Curl_base64_decode()
51+
* Base64Decode() née Curl_base64_decode()
5352
*
5453
* Given a base64 NUL-terminated string at src, decode it and return a
5554
* pointer in *outptr to a newly allocated memory area holding decoded
@@ -237,7 +236,7 @@ static bool base64_encode(const char* table64,
237236
}
238237

239238
/*
240-
* Base64Encode() n�e Curl_base64_encode()
239+
* Base64Encode() née Curl_base64_encode()
241240
*
242241
* Given a pointer to an input buffer and an input size, encode it and
243242
* return a pointer in *outptr to a newly allocated memory area holding
@@ -258,7 +257,7 @@ bool Base64Encode(const char* inputbuff, size_t insize,
258257
}
259258

260259
/*
261-
* Base64UrlEncode() n�e Curl_base64url_encode()
260+
* Base64UrlEncode() née Curl_base64url_encode()
262261
*
263262
* Given a pointer to an input buffer and an input size, encode it and
264263
* return a pointer in *outptr to a newly allocated memory area holding

engine/render/r_font.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ r_font_c::FontHeightEntry r_font_c::FindFontHeight(int height) {
321321
void r_font_c::DrawTextLine(scp_t pos, int align, int height, col4_t col, std::u32string_view str)
322322
{
323323
// Check if the line is visible
324-
if (pos[Y] >= renderer->sys->video->vid.size[1] || pos[Y] <= -height) {
324+
if (pos[Y] >= renderer->VirtualScreenHeight() || pos[Y] <= -height) {
325325
// Just process the colour codes
326326
while (!str.empty()) {
327327
// Check for escape character

engine/render/r_main.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
#include <algorithm>
1414
#include <array>
1515
#include <chrono>
16+
#include <thread>
1617
#include <filesystem>
1718
#include <fmt/chrono.h>
1819
#include <future>
1920
#include <map>
2021
#include <numeric>
2122
#include <random>
2223
#include <sstream>
23-
#include <thread>
2424
#include <vector>
2525

2626
#include <imgui_impl_glfw.h>
@@ -1642,11 +1642,7 @@ void r_renderer_c::GetShaderImageSize(r_shaderHnd_c* hnd, int& width, int& heigh
16421642
if (hnd)
16431643
{
16441644
while (hnd->sh->tex->status < r_tex_c::SIZE_KNOWN) {
1645-
#ifdef _WIN32
1646-
Sleep(1);
1647-
#else
16481645
std::this_thread::sleep_for(std::chrono::milliseconds(1));
1649-
#endif
16501646
}
16511647
width = hnd->sh->tex->fileWidth;
16521648
height = hnd->sh->tex->fileHeight;

engine/render/r_texture.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
// Module: Render Texture
55
//
66

7-
#include <algorithm>
87
#include <mutex>
9-
#include <thread>
108
#include <vector>
119
#include <atomic>
10+
#include <thread>
1211
#include "r_local.h"
1312

1413
#include "cmp_core.h"
@@ -506,7 +505,7 @@ static gli::texture2d_array TranscodeTexture(gli::texture2d_array src, gli::form
506505

507506
for (size_t blockRow = 0; blockRow < srcBlocksPerRow; ++blockRow) {
508507
const size_t rowBase = blockRow * srcBlockSize.y;
509-
const size_t rowsLeft = (std::min)(size_t{4}, size_t(dstExtent.y) - rowBase);
508+
const size_t rowsLeft = (std::min)(size_t(4),dstExtent.y - rowBase);
510509

511510
for (size_t blockCol = 0; blockCol < srcBlocksPerColumn; ++blockCol) {
512511
// Read source 4x4 texel block, no branching needed.
@@ -526,7 +525,7 @@ static gli::texture2d_array TranscodeTexture(gli::texture2d_array src, gli::form
526525

527526
// Here we work off that dstData points at the top left pixel of the block row in the destination.
528527
const size_t colBase = blockCol * srcBlockSize.x;
529-
const size_t colsLeft = (std::min)(size_t{4}, size_t(dstExtent.x) - colBase);
528+
const size_t colsLeft = (std::min)(size_t(4),dstExtent.x - colBase);
530529
const size_t colBytesLeft = colsLeft * 4;
531530
for (size_t innerRow = 0; innerRow < rowsLeft; ++innerRow) {
532531
auto* dstPtr = dstData + dstRowStride * innerRow + colBase * 4;

engine/system/sys_main.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ class sys_IMain {
6868
bool debuggerRunning = false;
6969
int processorCount = 0;
7070
std::filesystem::path basePath;
71-
std::filesystem::path launchCwd;
7271
std::optional<std::filesystem::path> userPath;
7372
std::optional<std::string> userPathReason;
7473

0 commit comments

Comments
 (0)