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

Tutorials and samples crash on MacOS Sequoia #326

Open
nanran98 opened this issue Nov 23, 2024 · 1 comment
Open

Tutorials and samples crash on MacOS Sequoia #326

nanran98 opened this issue Nov 23, 2024 · 1 comment

Comments

@nanran98
Copy link

nanran98 commented Nov 23, 2024

Successfully built the DiligentEngine on a MacBook Pro with M4 Pro chips running macOS Sequoia 15.1. However, samples (e.g., Tutorial01_HelloTriangle) crash on both the GL and Vulkan backends. After hours of debugging and searching, I decided to post an issue here.

I am new to DiligentEngine and I am not familiar with Objective-C++ nor AppKit, and I greatly appreciate any assistance.

P.S. I have also tested this on a friend's Intel MacBook Pro 2020 with intel iris graphics, and encountered the same issue.

To repoduce (just a clean clone from the latest commit):

git clone --recursive https://github.com/DiligentGraphics/DiligentEngine.git

cmake -S . -B ./build/MacOS_tmp -G "Xcode"
cmake --build ./build/MacOS_tmp/

Building tools and envs:

# cmake --version
cmake version 3.28.3
# xcodebuild -version
Xcode 16.0
Build version 16A242d
# python3 --version  
Python 3.12.5
For vulkan information
# vulkaninfo --summary
==========
VULKANINFO
==========

Vulkan Instance Version: 1.3.296


Instance Extensions: count = 17
-------------------------------
VK_EXT_debug_report                    : extension revision 10
VK_EXT_debug_utils                     : extension revision 2
VK_EXT_headless_surface                : extension revision 1
VK_EXT_layer_settings                  : extension revision 2
VK_EXT_metal_surface                   : extension revision 1
VK_EXT_surface_maintenance1            : extension revision 1
VK_EXT_swapchain_colorspace            : extension revision 5
VK_KHR_device_group_creation           : extension revision 1
VK_KHR_external_fence_capabilities     : extension revision 1
VK_KHR_external_memory_capabilities    : extension revision 1
VK_KHR_external_semaphore_capabilities : extension revision 1
VK_KHR_get_physical_device_properties2 : extension revision 2
VK_KHR_get_surface_capabilities2       : extension revision 1
VK_KHR_portability_enumeration         : extension revision 1
VK_KHR_surface                         : extension revision 25
VK_LUNARG_direct_driver_loading        : extension revision 1
VK_MVK_macos_surface                   : extension revision 3

Instance Layers: count = 6
--------------------------
VK_LAYER_KHRONOS_profiles         Khronos Profiles layer         1.3.275  version 1
VK_LAYER_KHRONOS_shader_object    Khronos Shader object layer    1.3.275  version 1
VK_LAYER_KHRONOS_synchronization2 Khronos Synchronization2 layer 1.3.275  version 1
VK_LAYER_KHRONOS_validation       Khronos Validation Layer       1.3.275  version 1
VK_LAYER_LUNARG_api_dump          LunarG API dump layer          1.3.275  version 2
VK_LAYER_LUNARG_screenshot        LunarG image capture layer     1.3.275  version 1

Devices:
========
GPU0:
        apiVersion         = 1.2.296
        driverVersion      = 0.2.2019
        vendorID           = 0x106b
        deviceID           = 0xf010209
        deviceType         = PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
        deviceName         = Apple M4 Pro
        driverID           = DRIVER_ID_MOLTENVK
        driverName         = MoltenVK
        driverInfo         = 1.2.11
        conformanceVersion = 0.0.0.0
        deviceUUID         = 0000106b-0f01-0209-0000-000000000000
        driverUUID         = 4d564b00-0000-27e3-0f01-020900000000
For cmake output
-- The C compiler identification is AppleClang 16.0.0.16000026
-- The CXX compiler identification is AppleClang 16.0.0.16000026
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMAKE_BUILD_TYPE is not specified, default to Debug. Note that this is only relevant for single-configuration generators (such as Makefile Generators and Ninja).
Target processor: x86_64
CMake generator: Xcode
Target platform: MacOS 64
DiligentCorePro module is not found. Metal backend will be disabled

D3D11_SUPPORTED:  FALSE
D3D12_SUPPORTED:  FALSE
GL_SUPPORTED:     TRUE
GLES_SUPPORTED:   FALSE
VULKAN_SUPPORTED: TRUE
METAL_SUPPORTED:  FALSE
WEBGPU_SUPPORTED: FALSE

Additional Clang compile options for release configurations: -mavx2
-- Found Python3: /usr/local/Frameworks/Python.framework/Versions/3.12/bin/python3.12 (found version "3.12.5") found components: Interpreter
-- optimizer enabled
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- SPIRV-Cross: Finding Git version for SPIRV-Cross.
-- Found Git: /usr/local/bin/git (found version "2.46.0")
-- SPIRV-Cross: Git hash: diligent-v2.5.6-44-g65d73934
-- Architecture: x86_64
-- DiligentCore commit hash: 953c6a45
Using Vulkan library path: /Users/septicmk/VulkanSDK/1.3.296.0/macOS/lib
-- Found OpenGL: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/System/Library/Frameworks/OpenGL.framework
-- The ASM compiler identification is AppleClang
-- Found assembler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
CMake Warning (dev) at DiligentTools/ThirdParty/libpng/CMakeLists.txt:61 (option):
  Policy CMP0077 is not set: option() honors normal variables.  Run "cmake
  --help-policy CMP0077" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

  For compatibility with older versions of CMake, option is clearing the
  normal variable 'PNG_FRAMEWORK'.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Deprecation Warning at DiligentTools/ThirdParty/libpng/CMakeLists.txt:102 (message):
  The option PNG_BUILD_ZLIB has been deprecated; please use ZLIB_ROOT instead


-- Found AWK program: /usr/bin/awk
Looking in indexes: http://mirrors.cloud.tencent.com/pypi/simple
Requirement already satisfied: libclang==16.0.6 in /usr/local/lib/python3.12/site-packages (16.0.6)

[notice] A new release of pip is available: 24.2 -> 24.3.1
[notice] To update, run: python3.12 -m pip install --upgrade pip
Looking in indexes: http://mirrors.cloud.tencent.com/pypi/simple
Requirement already satisfied: jinja2 in /usr/local/lib/python3.12/site-packages (3.1.3)
Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.12/site-packages (from jinja2) (2.1.5)

[notice] A new release of pip is available: 24.2 -> 24.3.1
[notice] To update, run: python3.12 -m pip install --upgrade pip
-- Including Cocoa support
Fetching GLTF assets...
-- Configuring done (48.8s)
-- Generating done (0.1s)
-- Build files have been written to: /Users/septicmk/project/DiligentEngine/build/MacOS_tmp

Error message (Both GL and VK report):

# open ./Tutorial01_HelloTriangle
2024-11-23 12:34:07.953 Tutorial01_HelloTriangle[22490:191519] +[IMKClient subclass]: chose IMKClient_Modern
2024-11-23 12:34:07.953 Tutorial01_HelloTriangle[22490:191519] +[IMKInputSession subclass]: chose IMKInputSession_Modern
fish: Job 1, './Tutorial01_HelloTriangle' terminated by signal SIGSEGV (Address boundary error)

lldb backtrace:

backtrace
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x3293a071ca00)
  * frame #0: 0x00007ff8140d56bf libobjc.A.dylib`objc_release + 31
    frame #1: 0x00007ff8140d9072 libobjc.A.dylib`AutoreleasePoolPage::releaseUntil(objc_object**) + 186
    frame #2: 0x00007ff8140d63ba libobjc.A.dylib`objc_autoreleasePoolPop + 235
    frame #3: 0x00000001000077ac Tutorial01_HelloTriangle`-[ViewBase awakeFromNib](self=0x00007fb3d9249160, _cmd="awakeFromNib") at ViewBase.mm:59:4
    frame #4: 0x0000000100006c83 Tutorial01_HelloTriangle`-[MetalView awakeFromNib](self=0x00007fb3d9249160, _cmd="awakeFromNib") at MetalView.mm:54:5
    frame #5: 0x00007ff81457c2ef CoreFoundation`-[NSSet makeObjectsPerformSelector:] + 215
    frame #6: 0x00007ff817de8a93 AppKit`-[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 1360
    frame #7: 0x00007ff817e5ce4d AppKit`-[NSNib _instantiateNibWithExternalNameTable:options:] + 659
    frame #8: 0x00007ff817e5cac5 AppKit`-[NSNib _instantiateWithOwner:options:topLevelObjects:] + 143
    frame #9: 0x00007ff817e5c321 AppKit`-[NSViewController loadView] + 331
    frame #10: 0x00007ff817e5c07e AppKit`-[NSViewController _loadViewIfRequired] + 72
    frame #11: 0x00007ff8184c3a98 AppKit`__24-[NSViewController view]_block_invoke + 27
    frame #12: 0x00007ff817e53da8 AppKit`NSPerformVisuallyAtomicChange + 134
    frame #13: 0x00007ff817e5bff5 AppKit`-[NSViewController view] + 123
    frame #14: 0x00007ff818023d61 AppKit`-[NSWindow _contentViewControllerChanged] + 111
    frame #15: 0x00007ff817e53da8 AppKit`NSPerformVisuallyAtomicChange + 134
    frame #16: 0x00007ff818023c73 AppKit`-[NSWindow setContentViewController:] + 104
    frame #17: 0x000000010000742d Tutorial01_HelloTriangle`-[ModeSelectionViewController goVulkan:](self=0x0000600000f48580, _cmd="goVulkan:", sender=0x00007fb3d871bee0) at ModeSelectionViewController.mm:85:22
    frame #18: 0x00007ff817feeb0f AppKit`-[NSApplication(NSResponder) sendAction:to:from:] + 335
    frame #19: 0x00007ff817fee987 AppKit`-[NSControl sendAction:to:] + 86
    frame #20: 0x00007ff817fee8b9 AppKit`__26-[NSCell _sendActionFrom:]_block_invoke + 131
    frame #21: 0x00007ff817fee7c2 AppKit`-[NSCell _sendActionFrom:] + 171
    frame #22: 0x00007ff817fee6e8 AppKit`-[NSButtonCell _sendActionFrom:] + 105
    frame #23: 0x00007ff817feb5d3 AppKit`NSControlTrackMouse + 1904
    frame #24: 0x00007ff817feae3f AppKit`-[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 125
    frame #25: 0x00007ff817feacc1 AppKit`-[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 700
    frame #26: 0x00007ff817fea0a9 AppKit`-[NSControl mouseDown:] + 666
    frame #27: 0x00007ff817fe897e AppKit`-[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 4471
    frame #28: 0x00007ff817f621bd AppKit`-[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 409
    frame #29: 0x00007ff817f61e09 AppKit`-[NSWindow(NSEventRouting) sendEvent:] + 339
    frame #30: 0x00007ff81883c9da AppKit`-[NSApplication(NSEventRouting) sendEvent:] + 1546
    frame #31: 0x00007ff8183b07a3 AppKit`-[NSApplication _handleEvent:] + 65
    frame #32: 0x00007ff817dfac25 AppKit`-[NSApplication run] + 654
    frame #33: 0x00007ff817dcdf36 AppKit`NSApplicationMain + 823
    frame #34: 0x000000010000cc12 Tutorial01_HelloTriangle`main(argc=1, argv=0x0000000308832ee8) at main.m:22:12
    frame #35: 0x00000002047112cd dyld`start + 1805
(lldb) q
@nanran98
Copy link
Author

Workaround:

change https://github.com/DiligentGraphics/DiligentTools/blob/fe39c86848ed5f56b3a5440af6511585079da1c0/NativeApp/Apple/Source/Classes/OSX/ViewBase.mm#L47-L59

to

    //@autoreleasepool
    {
        NSArray<NSString*>* arguments = [[NSProcessInfo processInfo] arguments];
        const auto ArgCount = arguments.count;
        Args.resize(ArgCount);
        ArgStr.resize(ArgCount);
        for(size_t i = 0; i < ArgCount; ++i)
        {
            ArgStr[i] = [arguments[i] cStringUsingEncoding:NSUTF8StringEncoding];
            Args[i]   = ArgStr[i].c_str();
        }
        //[arguments release];
   }

It seems that [[NSProcessInfo processInfo] arguments] is already autoreleased (though this is uncertain). Removing the autorelease seems to resolve the issue, as samples and tutorials now run as expected.

Not sure if this resolves the issue correctly; perhaps some Objective-C++ experts can take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant