Metal Layer: crash on FileChooser::launchAsync (Mac)

Hello. I’m on latest develop. When I’m trying to launch file chooser I’ve got a crash and this error. @reuk could you take a look pls?

-[MTLDebugDevice newBufferWithBytesNoCopy:length:options:deallocator:]:687: failed assertion `Buffer Validation
Cannot create buffer of zero length.
newBufferWithBytesNoCopy:pointer must not be nil.

Backtrace:

0   libsystem_kernel.dylib        	    0x7ff8044e7ffe __pthread_kill + 10
1   libsystem_pthread.dylib       	    0x7ff80451e1ff pthread_kill + 263
2   libsystem_c.dylib             	    0x7ff804469d24 abort + 123
3   libsystem_c.dylib             	    0x7ff8044690cb __assert_rtn + 314
4   Metal                         	    0x7ff80cfa38a4 MTLReportFailure.cold.1 + 43
5   Metal                         	    0x7ff80cf8dc05 MTLReportFailure + 529
6   Metal                         	    0x7ff80cf86378 _MTLMessageContextEnd + 1278
7   Metal                         	    0x7ff80ced7bdf -[MTLTextureDescriptorInternal validateWithDevice:] + 3296
8   AMDMTLBronzeDriver            	    0x7ffa20b724f5 -[BronzeMtlTexture initInternalWithDevice:descriptor:] + 59
9   Loopmix                       	       0x10f24641a juce::CoreGraphicsMetalLayerRenderer::GpuTexturePool::GpuTexturePool(id<MTLDevice>, MTLTextureDescriptor*) + 138 (juce_CGMetalLayerRenderer_mac.h:212)
10  Loopmix                       	       0x10f246355 juce::CoreGraphicsMetalLayerRenderer::GpuTexturePool::GpuTexturePool(id<MTLDevice>, MTLTextureDescriptor*) + 37 (juce_CGMetalLayerRenderer_mac.h:210)
11  Loopmix                       	       0x10f245721 std::__1::__unique_if<juce::CoreGraphicsMetalLayerRenderer::GpuTexturePool>::__unique_single std::__1::make_unique<juce::CoreGraphicsMetalLayerRenderer::GpuTexturePool, id<MTLDevice>&, MTLTextureDescriptor*&>(id<MTLDevice>&, MTLTextureDescriptor*&) + 97 (unique_ptr.h:728)
12  Loopmix                       	       0x10f2452da juce::CoreGraphicsMetalLayerRenderer::Resources::Resources(id<MTLDevice>, CAMetalLayer*) + 1850 (juce_CGMetalLayerRenderer_mac.h:277)
13  Loopmix                       	       0x10f244b65 juce::CoreGraphicsMetalLayerRenderer::Resources::Resources(id<MTLDevice>, CAMetalLayer*) + 37 (juce_CGMetalLayerRenderer_mac.h:234)
14  Loopmix                       	       0x10f244391 std::__1::__unique_if<juce::CoreGraphicsMetalLayerRenderer::Resources>::__unique_single std::__1::make_unique<juce::CoreGraphicsMetalLayerRenderer::Resources, id<MTLDevice>, CAMetalLayer*&>(id<MTLDevice>&&, CAMetalLayer*&) + 97 (unique_ptr.h:728)
15  Loopmix                       	       0x10f243d00 juce::RectangleList<float> juce::CoreGraphicsMetalLayerRenderer::drawRectangleList<juce::NSViewComponentPeer::displayLayer(CALayer*)::'lambda'(auto&&...)>(CAMetalLayer*, float, juce::NSViewComponentPeer::displayLayer(CALayer*)::'lambda'(auto&&...)&&, juce::RectangleList<float>, bool) + 768 (juce_CGMetalLayerRenderer_mac.h:88)
16  Loopmix                       	       0x10f22dc76 juce::NSViewComponentPeer::displayLayer(CALayer*) + 230 (juce_NSViewComponentPeer_mac.mm:1992)
17  Loopmix                       	       0x10f23fc7e juce::JuceCALayerDelegate::JuceCALayerDelegate()::'lambda'(objc_object*, objc_selector*, CALayer*)::operator()(objc_object*, objc_selector*, CALayer*) const + 62 (juce_NSViewComponentPeer_mac.mm:151)
18  Loopmix                       	       0x10f23fcd5 juce::JuceCALayerDelegate::JuceCALayerDelegate()::'lambda'(objc_object*, objc_selector*, CALayer*)::__invoke(objc_object*, objc_selector*, CALayer*) + 37 (juce_NSViewComponentPeer_mac.mm:148)

Thanks for reporting, that’s fixed here:

Unfortunately, it doesn’t fix crash on my end. The assertion is hit before the changed lines in this commit. Specifically, it happens during construction of Resources object at line 88:
resources = std::make_unique<Resources> (device.get(), layer);

In Resources ctor the failing line is

I can see that bytesPerRow is zero. Sorry I hadn’t provided these details in the first post.

However, I’ve tried AudioRecordingDemo and it starts file chooser just fine. Here is my code that runs FileChooser. Do you think the problem is related with passing parentComponent?

fileChooser.reset(new FileChooser("Add folder to the list..", lastSamplePath, {}, true, false, this));

fileChooser->launchAsync(FileBrowserComponent::openMode | FileBrowserComponent::canSelectDirectories,
...

I’m not able to reproduce any crash/assertion here, but I do see some logging output in the console which disappears if I move the following check to line 85, before the if (resources == nullptr...:

        if (CGSizeEqualToSize (transformedFrameSize, CGSizeZero))
            return dirtyRegions;

Please can you try that out and let me know if the problem you’re seeing is resolved?

1 Like

Yes, it runs without assertion and errors in log now. Thank you!