MetalNanoVG
MetalNanoVG copied to clipboard
Crash: Blending enabled for render target 0, pixelformat MTLPixelFormatInvalid
I just got a report from a beta tester of my app that after a few hours leaving the interface on mac, the app crashed with this error. Currently, I can't reproduce this bug on my machine. I guess checking if colorTexture has an invalid pixel format could fix this issue, or something else might be wrong here.
Process: Youlean Loudness Meter 2 [14160]
Path: /Applications/Youlean Loudness Meter 2.app/Contents/MacOS/Youlean Loudness Meter 2
Identifier: com.Youlean.standalone.Youlean-Loudness-Meter-2
Version: 2.4.1 (2.4.1)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Youlean Loudness Meter 2 [14160]
User ID: 501
Date/Time: 2020-09-02 22:09:47.673 +0100
OS Version: Mac OS X 10.12.6 (16G2136)
Report Version: 12
Anonymous UUID: 52E837E2-0DED-4E93-D3A1-BBEA57065E3E
Time Awake Since Boot: 26000 seconds
System Integrity Protection: enabled
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Application Specific Information:
-[MTLRenderPipelineDescriptorInternal validateWithDevice:]:1798: failed assertion `Blending is enabled for render target 0; however, the pixelformat MTLPixelFormatInvalid for this render target is not blendable.'
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fffa02e7d42 __pthread_kill + 10
1 libsystem_pthread.dylib 0x00007fffa03d5457 pthread_kill + 90
2 libsystem_c.dylib 0x00007fffa024d420 abort + 129
3 libsystem_c.dylib 0x00007fffa0214893 __assert_rtn + 320
4 com.apple.Metal 0x00007fff8de69e0b MTLReportFailure + 822
5 com.apple.Metal 0x00007fff8de68c26 -[MTLRenderPipelineDescriptorInternal validateWithDevice:] + 988
6 com.apple.Metal 0x00007fff8de5b20b -[MTLCompiler newRenderPipelineStateWithDescriptor:options:reflection:error:completionHandler:] + 70
7 com.apple.Metal 0x00007fff8de430f0 -[_MTLDevice newRenderPipelineStateWithDescriptor:error:] + 65
8 com.Youlean.standalone.Youlean-Loudness-Meter-2 0x0000000100469803 -[MNVGcontext updateRenderPipelineStatesForBlend:pixelFormat:] + 467
9 com.Youlean.standalone.Youlean-Loudness-Meter-2 0x00000001004686b0 -[MNVGcontext renderFlush] + 896
10 com.Youlean.standalone.Youlean-Loudness-Meter-2 0x00000001002b77da nvgEndFrame + 26
11 com.Youlean.standalone.Youlean-Loudness-Meter-2 0x0000000100258d7a ygraphics::yg_end_draw_frame(yg_t*, double, double, double, double) + 362
12 com.Youlean.standalone.Youlean-Loudness-Meter-2 0x000000010033e848 -[IGraphicsCocoa_vYoulean_Loudness_Meter_sa render] + 184
13 com.Youlean.standalone.Youlean-Loudness-Meter-2 0x000000010033d9e8 -[IGraphicsCocoa_vYoulean_Loudness_Meter_sa displayLayer:] + 88
14 com.apple.QuartzCore 0x00007fff9057fa86 CA::Layer::display() + 142
15 com.apple.QuartzCore 0x00007fff90574036 CA::Layer::display_if_needed(CA::Transaction*) + 572
16 com.apple.QuartzCore 0x00007fff90574161 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 35
17 com.apple.QuartzCore 0x00007fff90569918 CA::Context::commit_transaction(CA::Transaction*) + 280
18 com.apple.QuartzCore 0x00007fff9045e701 CA::Transaction::commit() + 475
19 com.apple.QuartzCore 0x00007fff9045f11c CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 108
20 com.apple.CoreFoundation 0x00007fff8a590857 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
21 com.apple.CoreFoundation 0x00007fff8a5907c7 __CFRunLoopDoObservers + 391
22 com.apple.CoreFoundation 0x00007fff8a570fd6 CFRunLoopRunSpecific + 454
23 com.apple.HIToolbox 0x00007fff89acfebc RunCurrentEventLoopInMode + 240
24 com.apple.HIToolbox 0x00007fff89acfcf1 ReceiveNextEventCommon + 432
25 com.apple.HIToolbox 0x00007fff89acfb26 _BlockUntilNextEventMatchingListInModeWithFilter + 71
26 com.apple.AppKit 0x00007fff88064a04 _DPSNextEvent + 1120
27 com.apple.AppKit 0x00007fff887e07ee -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2796
28 com.apple.AppKit 0x00007fff8805938b -[NSApplication run] + 926
29 com.apple.AppKit 0x00007fff88023dbe NSApplicationMain + 1237
30 libdyld.dylib 0x00007fffa01b9235 start + 1
It might be that the drawable returns nil for some reason. I am not setting allowsNextDrawableTimeout so it might just timeout after one second. I am auto releasing drawable as stated here https://developer.apple.com/documentation/quartzcore/cametallayer?language=objc
I guess this should do the trick. I will test and see if that prevents the crash.
id<CAMetalDrawable> drawable = nil;
if (colorTexture == nil) {
drawable = _metalLayer.nextDrawable;
colorTexture = drawable.texture;
}
if (colorTexture.pixelFormat == MTLPixelFormatInvalid) return;