google / filament

Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
https://google.github.io/filament/
Apache License 2.0
17.82k stars 1.89k forks source link

Calling function flushAndWait will always block on it if I not run it on main thread. Under the mac arm64 architecture. #8137

Open as010101 opened 2 months ago

as010101 commented 2 months ago

⚠️ Issues not using this template will be systematically closed.

Describe the bug I want to use off-screen rendering to do something. When developing on the Mac platform, for some reason, I must work on non-main thread . Then I found that if I render on a non-main thread, it will be blocked in flushAndWait,This happened to me on Mac(M1), but not on Windows.

To Reproduce Steps to reproduce the behavior: the code like this:

void test(){
//do init   engine , scene, render
....
//  do  begin frame ,   readpixel ,  endframe,  flushAndWait
renderer_->beginFrame(swapchain_);
 renderer_->readPixels(....);
renderer_->endFrame(swapchain_);
//block here
engine_.flushAndWait();

}

int main(){
    std::thread work(test); 
    work.detach()
    getchar();

    return 0;
}

Expected behavior hope can on non-main thread render image (on mac M1 arm64)

Screenshots no Logs no

Desktop (please complete the following information):

Additional context

pixelflinger commented 1 month ago

Does this happen with the Metal backend too?

as010101 commented 1 month ago

Does this happen with the Metal backend too?

Yes, I use the filament example hellotriangle.cpp, just run it on non-main thread, it cant work . the code like this:

int test3(int argc, char** argv);
int main(int argc, char** argv) {
     std::thread work(test3, argc, argv);
     work.detach();
     getchar();
     return 0;
}

int test3(int argc, char** argv) {
    App app{};
    app.config.title = "hellotriangle";
    handleCommandLineArguments(argc, argv, &app);
    app.config.backend = Engine::Backend::METAL;
.........
}

the error msg :

2024-09-29 14:40:18.060578+0800 hellotriangle[68943:4741088] [threadmgrsupport] _TSGetMainThread_block_invoke:Main thread potentially initialized incorrectly, cf <rdar://problem/67741850>
2024-09-29 14:40:18.210423+0800 hellotriangle[68943:4741088] [default] 0x100005405: TCC deny IOHIDDeviceOpen
2024-09-29 14:40:18.210441+0800 hellotriangle[68943:4741088] [default] 0x100005405: TCC deny IOHIDDeviceOpen
2024-09-29 14:40:18.222796+0800 hellotriangle[68943:4741088] [default] 0x1000008d3: TCC deny IOHIDDeviceOpen
2024-09-29 14:40:18.222842+0800 hellotriangle[68943:4741088] [default] 0x1000008d3: TCC deny IOHIDDeviceOpen
2024-09-29 14:40:18.234804+0800 hellotriangle[68943:4741088] [default] 0x1000007b5: TCC deny IOHIDDeviceOpen
2024-09-29 14:40:18.234824+0800 hellotriangle[68943:4741088] [default] 0x1000007b5: TCC deny IOHIDDeviceOpen
2024-09-29 14:40:18.260696+0800 hellotriangle[68943:4741088] WARN: 

Assertion failure at SDL_GetWindowWMInfo_REAL (/Users/mac-m1/filament/third_party/libsdl2/src/video/SDL_video.c:3637), triggered 1 time:
  'window && window->magic == &_this->window_magic'
2024-09-29 14:40:18.274959+0800 hellotriangle[68943:4741088] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001a0de50b8 __exceptionPreprocess + 240
    1   libobjc.A.dylib                     0x00000001a0b2f8dc objc_exception_throw + 60
    2   CoreFoundation                      0x00000001a0e1003c _CFBundleGetValueForInfoKey + 0
    3   AppKit                              0x00000001a38f48cc -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 372
    4   AppKit                              0x00000001a38df8c8 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 948
    5   AppKit                              0x00000001a3a87018 -[NSPanel _initContent:styleMask:backing:defer:contentView:] + 48
    6   AppKit                              0x00000001a38df508 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 56
    7   AppKit                              0x00000001a3a86fcc -[NSPanel initWithContentRect:styleMask:backing:defer:] + 48
    8   AppKit                              0x00000001a38ddd30 -[NSWindowTemplate nibInstantiate] + 292
    9   AppKit                              0x00000001a38a8984 -[NSIBObjectData instantiateObject:] + 236
    10  AppKit                              0x00000001a38a8208 -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 392
    11  AppKit                              0x00000001a389c79c loadNib + 416
    12  AppKit                              0x00000001a389bccc +[NSBundle(NSNibLoading) _loadNibFile:nameTable:options:withZone:ownerBundle:] + 800
    13  AppKit                              0x00000001a389b8d0 -[NSBundle(NSNibLoading) loadNibNamed:owner:topLevelObjects:] + 220
    14  AppKit                              0x00000001a3c05610 -[NSAlert init] + 148
    15  hellotriangle                       0x0000000100ed761c Cocoa_ShowMessageBox + 44
    16  hellotriangle                       0x0000000100eb886c SDL_ShowMessageBox_REAL + 328
    17  hellotriangle                       0x0000000100dd4e88 SDL_PromptAssertion + 632
    18  hellotriangle                       0x0000000100dd491c SDL_ReportAssertion_REAL + 360
    19  hellotriangle                       0x0000000100eb8454 SDL_GetWindowWMInfo_REAL + 156
    20  hellotriangle                       0x0000000100de49f4 SDL_GetWindowWMInfo + 44
    21  hellotriangle                       0x000000010035feb8 getNativeWindow + 64
    22  hellotriangle                       0x0000000100351ca0 _ZN11FilamentApp6WindowC2EPS_RK6ConfigNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEEmm + 576
    23  hellotriangle                       0x000000010034fba4 _ZN11FilamentApp6WindowC1EPS_RK6ConfigNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEEmm + 60
    24  hellotriangle                       0x000000010034dd30 _ZN11FilamentApp3runERK6ConfigNSt3__18functionIFvPN8filament6EngineEPNS5_4ViewEPNS5_5SceneEEEESD_NS4_IFvS7_S9_EEENS4_IFvS7_S9_SB_PNS5_8RendererEEEESJ_mm + 192
    25  hellotriangle                       0x0000000100341334 _Z5test3iPPc + 440
    26  hellotriangle                       0x00000001003440e8 _ZNSt3__1L8__invokeIPFiiPPcEJiS2_EEEDTclscT_fp_spscT0_fp0_EEOS5_DpOS6_ + 52
    27  hellotriangle                       0x0000000100344068 _ZNSt3__1L16__thread_executeINS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEPFiiPPcEJiS7_EJLm2ELm3EEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE + 76
    28  hellotriangle                       0x0000000100343704 _ZNSt3__1L14__thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEPFiiPPcEiS8_EEEEEPvSC_ + 84
    29  libsystem_pthread.dylib             0x00000001a0c9826c _pthread_start + 148
    30  libsystem_pthread.dylib             0x00000001a0c9308c thread_start + 8
)
2024-09-29 14:40:18.275232+0800 hellotriangle[68943:4741088] [General] An uncaught exception was raised
2024-09-29 14:40:18.275247+0800 hellotriangle[68943:4741088] [General] NSWindow drag regions should only be invalidated on the Main Thread!
2024-09-29 14:40:18.275445+0800 hellotriangle[68943:4741088] [General] (
    0   CoreFoundation                      0x00000001a0de50b8 __exceptionPreprocess + 240
    1   libobjc.A.dylib                     0x00000001a0b2f8dc objc_exception_throw + 60
    2   CoreFoundation                      0x00000001a0e1003c _CFBundleGetValueForInfoKey + 0
    3   AppKit                              0x00000001a38f48cc -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 372
    4   AppKit                              0x00000001a38df8c8 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 948
    5   AppKit                              0x00000001a3a87018 -[NSPanel _initContent:styleMask:backing:defer:contentView:] + 48
    6   AppKit                              0x00000001a38df508 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 56
    7   AppKit                              0x00000001a3a86fcc -[NSPanel initWithContentRect:styleMask:backing:defer:] + 48
    8   AppKit                              0x00000001a38ddd30 -[NSWindowTemplate nibInstantiate] + 292
    9   AppKit                              0x00000001a38a8984 -[NSIBObjectData instantiateObject:] + 236
    10  AppKit                              0x00000001a38a8208 -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 392
    11  AppKit                              0x00000001a389c79c loadNib + 416
    12  AppKit                              0x00000001a389bccc +[NSBundle(NSNibLoading) _loadNibFile:nameTable:options:withZone:ownerBundle:] + 800
    13  AppKit                              0x00000001a389b8d0 -[NSBundle(NSNibLoading) loadNibNamed:owner:topLevelObjects:] + 220
    14  AppKit                              0x00000001a3c05610 -[NSAlert init] + 148
    15  hellotriangle                       0x0000000100ed761c Cocoa_ShowMessageBox + 44
    16  hellotriangle                       0x0000000100eb886c SDL_ShowMessageBox_REAL + 328
    17  hellotriangle                       0x0000000100dd4e88 SDL_PromptAssertion + 632
    18  hellotriangle                       0x0000000100dd491c SDL_ReportAssertion_REAL + 360
    19  hellotriangle                       0x0000000100eb8454 SDL_GetWindowWMInfo_REAL + 156
    20  hellotriangle                       0x0000000100de49f4 SDL_GetWindowWMInfo + 44
    21  hellotriangle                       0x000000010035feb8 getNativeWindow + 64
    22  hellotriangle                       0x0000000100351ca0 _ZN11FilamentApp6WindowC2EPS_RK6ConfigNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEEmm + 576
    23  hellotriangle                       0x000000010034fba4 _ZN11FilamentApp6WindowC1EPS_RK6ConfigNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEEmm + 60
    24  hellotriangle                       0x000000010034dd30 _ZN11FilamentApp3runERK6ConfigNSt3__18functionIFvPN8filament6EngineEPNS5_4ViewEPNS5_5SceneEEEESD_NS4_IFvS7_S9_EEENS4_IFvS7_S9_SB_PNS5_8RendererEEEESJ_mm + 192
    25  hellotriangle                       0x0000000100341334 _Z5test3iPPc + 440
    26  hellotriangle                       0x00000001003440e8 _ZNSt3__1L8__invokeIPFiiPPcEJiS2_EEEDTclscT_fp_spscT0_fp0_EEOS5_DpOS6_ + 52
    27  hellotriangle                       0x0000000100344068 _ZNSt3__1L16__thread_executeINS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEPFiiPPcEJiS7_EJLm2ELm3EEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE + 76
    28  hellotriangle                       0x0000000100343704 _ZNSt3__1L14__thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEPFiiPPcEiS8_EEEEEPvSC_ + 84
    29  libsystem_pthread.dylib             0x00000001a0c9826c _pthread_start + 148
    30  libsystem_pthread.dylib             0x00000001a0c9308c thread_start + 8
)
libc++abi: terminating with uncaught exception of type NSException
Signal: SIGABRT (signal SIGABRT)