Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use libuv run loop for macOS (CMake) #3059

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

louwers
Copy link
Collaborator

@louwers louwers commented Nov 30, 2024

The CFRunLoop is crashing with GLFW on macOS.

I tried fixing it, but I am getting non-descriptive segfaults.

Stack trace
/Users/bart/src/maplibre-native/vendor/metal-cpp/Foundation/NSSharedPtr.hpp:219:16: runtime error: member call on null pointer of type 'NS::Referencing<MTL::Texture, MTL::Resource>'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Users/bart/src/maplibre-native/vendor/metal-cpp/Foundation/NSSharedPtr.hpp:219:16 in 
/Users/bart/src/maplibre-native/vendor/metal-cpp/Foundation/NSObject.hpp:112:49: runtime error: member call on null pointer of type 'NS::Referencing<MTL::Texture, MTL::Resource> *'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Users/bart/src/maplibre-native/vendor/metal-cpp/Foundation/NSObject.hpp:112:49 in 
/Users/bart/src/maplibre-native/vendor/metal-cpp/Foundation/NSSharedPtr.hpp:219:16: runtime error: member call on null pointer of type 'NS::Referencing<MTL::DepthStencilState>'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Users/bart/src/maplibre-native/vendor/metal-cpp/Foundation/NSSharedPtr.hpp:219:16 in 
/Users/bart/src/maplibre-native/vendor/metal-cpp/Foundation/NSObject.hpp:112:49: runtime error: member call on null pointer of type 'NS::Referencing<MTL::DepthStencilState> *'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Users/bart/src/maplibre-native/vendor/metal-cpp/Foundation/NSObject.hpp:112:49 in 
/Users/bart/src/maplibre-native/vendor/metal-cpp/Foundation/NSSharedPtr.hpp:219:16: runtime error: member call on null pointer of type 'NS::Referencing<MTL::Texture, MTL::Resource>'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Users/bart/src/maplibre-native/vendor/metal-cpp/Foundation/NSSharedPtr.hpp:219:16 in 
/Users/bart/src/maplibre-native/vendor/metal-cpp/Foundation/NSObject.hpp:112:49: runtime error: member call on null pointer of type 'NS::Referencing<MTL::Texture, MTL::Resource> *'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Users/bart/src/maplibre-native/vendor/metal-cpp/Foundation/NSObject.hpp:112:49 in 
/Users/bart/src/maplibre-native/vendor/metal-cpp/Foundation/NSSharedPtr.hpp:219:16: runtime error: member call on null pointer of type 'NS::Referencing<MTL::SamplerState>'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Users/bart/src/maplibre-native/vendor/metal-cpp/Foundation/NSSharedPtr.hpp:219:16 in 
/Users/bart/src/maplibre-native/vendor/metal-cpp/Foundation/NSObject.hpp:112:49: runtime error: member call on null pointer of type 'NS::Referencing<MTL::SamplerState> *'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Users/bart/src/maplibre-native/vendor/metal-cpp/Foundation/NSObject.hpp:112:49 in 
AddressSanitizer:DEADLYSIGNAL
=================================================================
==21109==ERROR: AddressSanitizer: SEGV on unknown address 0x000000010b20 (pc 0x000196424270 bp 0x00016d750a40 sp 0x00016d750a00 T0)
==21109==The signal is caused by a READ memory access.
    #0 0x196424270 in objc_release+0x10 (libobjc.A.dylib:arm64e+0x8270)
    #1 0x196428134 in objc_autoreleasePoolPop+0x100 (libobjc.A.dylib:arm64e+0xc134)
    #2 0x19689c7bc in _CFAutoreleasePoolPop+0x1c (CoreFoundation:arm64e+0x3c7bc)
    #3 0x1969af954 in __CFRunLoopPerCalloutARPEnd+0x2c (CoreFoundation:arm64e+0x14f954)
    #4 0x1968f7e44 in __CFRunLoopDoTimer+0x410 (CoreFoundation:arm64e+0x97e44)
    #5 0x1968f7934 in __CFRunLoopDoTimers+0x160 (CoreFoundation:arm64e+0x97934)
    #6 0x1968dd0ec in __CFRunLoopRun+0x73c (CoreFoundation:arm64e+0x7d0ec)
    #7 0x1968dc330 in CFRunLoopRunSpecific+0x238 (CoreFoundation:arm64e+0x7c330)
    #8 0x196957a0c in CFRunLoopRun+0x3c (CoreFoundation:arm64e+0xf7a0c)
    #9 0x102af0758 in mbgl::util::RunLoop::run() run_loop.cpp:38
    #10 0x1027c4cb0 in GLFWView::run() glfw_view.cpp:1119
    #11 0x1028ef6ac in main main.cpp:222
    #12 0x196474270  (<unknown module>)

This PR changes the CMake config to use the the libuv-based run loop on macOS instead, which seems to work fine.

cmake . -B build \                                                                               
            -G Ninja \
            -DCMAKE_BUILD_TYPE=Debug \
            -DCMAKE_CXX_COMPILER_LAUNCHER=/opt/homebrew/bin/ccache \
            -DMLN_WITH_OPENGL=OFF \
            -DMLN_WITH_METAL=ON \
            -DMLN_LEGACY_RENDERER=OFF \
            -DMLN_DRAWABLE_RENDERER=ON \
            -DMLN_WITH_WERROR=OFF
build/platform/glfw/mbgl-glfw --style "https://tiles.openfreemap.org/styles/liberty"

@louwers louwers added build Related to build, configuration or CI/CD macOS labels Nov 30, 2024
Copy link

Bloaty Results 🐋

Compared to main

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  [ = ]       0  [ = ]       0    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results/pr-3059-compared-to-main.txt

Compared to d387090 (legacy)

    FILE SIZE        VM SIZE    
 --------------  -------------- 
   +30% +34.5Mi  +432% +25.8Mi    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results/pr-3059-compared-to-legacy.txt

Copy link

Benchmark Results ⚡

Benchmark                                                     Time             CPU      Time Old      Time New       CPU Old       CPU New
------------------------------------------------------------------------------------------------------------------------------------------
OVERALL_GEOMEAN                                            -0.0025         -0.0021             0             0             0             0

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/benchmark-results/pr-3059-compared-to-main.txt

Copy link

github-actions bot commented Dec 5, 2024

Bloaty Results (iOS) 🐋

Compared to main

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  -0.0%     -64  [ = ]       0    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results-ios/pr-3059-compared-to-main.txt

@louwers
Copy link
Collaborator Author

louwers commented Dec 5, 2024

When I run the tests Map.ContinuousRendering hangs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Related to build, configuration or CI/CD macOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant