warrenm / GLTFKit2

A glTF 2.0 asset loader and exporter for Objective-C and Swift.
MIT License
156 stars 27 forks source link

Synchronous asset loading raises an exception #10

Closed lenkawell closed 2 years ago

lenkawell commented 2 years ago

It seems like synchronous asset loading is failing with some kind of exception.

I apologize that I cannot seem to get more info. I can't locate an error code or a very helpful backtrace to include. I have an exception handler (do / catch in Swift) which is being invoked, but error is nil. Let me know if this is useful or if I should continue to look for more info.

* thread #13, queue = 'com.metalbyexample.gltfkit2.asset-loader'
    frame #0: 0x00000001ae4c6538 libsystem_kernel.dylib`read + 8
    frame #1: 0x00000001af46a840 Foundation`_NSReadFromFileDescriptorWithProgress + 236
    frame #2: 0x00000001af462c94 Foundation`_NSReadBytesFromFileWithExtendedAttributes + 764
    frame #3: 0x00000001af476b30 Foundation`-[NSData(NSData) initWithContentsOfFile:] + 100
    frame #4: 0x00000001af4ff750 Foundation`+[NSData(NSData) dataWithContentsOfURL:] + 40
  * frame #5: 0x0000000102132e20 GLTFKit2`-[GLTFAssetReader syncLoadAssetWithURL:data:options:handler:](self=0x00006000016f8360, _cmd="syncLoadAssetWithURL:data:options:handler:", assetURL=@"file:///Users/lenkawell/Library/Containers/com.pepper.timebox/Data/Library/Application%20Support/TimeboxUserModels/18CEBA0C-8D2E-4366-8238-E844E5A2B347-Len%20avatar.glb", data=0x0000000000000000, options=0x0000000207722760, handler=0x000000010214e77c) at GLTFAssetReader.m:251:36
    frame #6: 0x00000001021328b8 GLTFKit2`__52+[GLTFAssetReader loadAssetWithURL:options:handler:]_block_invoke(.block_descriptor=0x000060000463d340) at GLTFAssetReader.m:207:9
    frame #7: 0x00000001023dfff0 libdispatch.dylib`_dispatch_call_block_and_release + 32
    frame #8: 0x00000001023e1d24 libdispatch.dylib`_dispatch_client_callout + 20
    frame #9: 0x00000001023e5694 libdispatch.dylib`_dispatch_continuation_pop + 816
    frame #10: 0x00000001023e458c libdispatch.dylib`_dispatch_async_redirect_invoke + 696
    frame #11: 0x00000001023f9a0c libdispatch.dylib`_dispatch_root_queue_drain + 408
    frame #12: 0x00000001023fa640 libdispatch.dylib`_dispatch_worker_thread2 + 196
    frame #13: 0x0000000102197ed8 libsystem_pthread.dylib`_pthread_wqthread + 228
warrenm commented 2 years ago

This backtrace doesn't seem indicative of a crash, but it's entirely possible that an assertion or other error is bubbling up out of the sync loading API. Does this happen with all glTF files? If not, can you attach a representative one?

lenkawell commented 2 years ago

The app isn't crashing - its Swift catch block is being invoked. I've tried setting an All Exceptions breakpoint, but it doesn't break there.

I thought I'd try using the synchronous form of GLTFAsset() because I have my own operation queues that manage async loading of all model files. When I use the async version of GLTFAsset.load() it works (at least it loads the model ok - there is still some synchronization issue that I haven't debugged yet).

The synchronous API problem seems to occur with 6 different models that I've tried (including the ones I posted in other issues, like Fox.glb).

Here's the synchronous code snipett:

        let asset = try GLTFAsset(url: url, options: [:])
        let source = GLTFSCNSceneSource(asset: asset)
        if let scene = source.defaultScene {
            return scene
        } else {
        }

Here is a "bt all" (I disabled my own operation queues for this test to hopefully simplify the traces): btall.txt

warrenm commented 2 years ago

Thanks for the additional detail. I'll investigate this.

warrenm commented 2 years ago

There was an off-by-one error in the blocking logic for synchronous loading. This should be fixed as of 0038041.

lenkawell commented 2 years ago

Seems to work fine now. Thanks!