File retrieval from storage location makes the app crash on iPadOS

I’m having constant crash on my device running iPadOS. The crash didn’t trigger on simulator but on physical device only.

I was trying to save a file to File.applicationStorageDirectory and later retrieve. While writing - the app does not complaint, but while retrieving the file, the app crash.

Here’s the code that I’m using to write file:

var fs:FileStream = new FileStream();
fs.open(
      File.applicationStorageDirectory.resolvePath("settings" + File.separator +"preferences.txt"), 
      FileMode.WRITE);
fs.writeUTFBytes(cast(data, String));
fs.close();

Next, I tries to retrieve the file:

var fl = File.applicationStorageDirectory.resolvePath("settings" + File.separator +"preferences.txt");        
if (fl.exists)
{
        var fs:FileStream = new FileStream();
        fs.addEventListener(ProgressEvent.PROGRESS, onOutputProgress);
        fs.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorReadChannel);
        fs.addEventListener(Event.COMPLETE, onFileReadCompletes);
        fl.canonicalize();
        fs.openAsync(target, FileMode.READ);
}

Unfortunately, crash doesn’t provide much of an information but this:

Thread 0 name:
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x00000001ef1c7198 __pthread_kill + 8 (:-1)
1 libsystem_pthread.dylib 0x00000001fe69a5f8 pthread_kill + 208 (pthread.c:1670)
2 libsystem_c.dylib 0x00000001bb0c84b8 abort + 124 (abort.c:118)
3 libc++abi.dylib 0x00000001fe5d2f54 abort_message + 128 (:-1)
4 libc++abi.dylib 0x00000001fe5c3a4c demangling_terminate_handler() + 300 (:-1)
5 libobjc.A.dylib 0x00000001ad5bab0c _objc_terminate() + 140 (objc-exception.mm:501)
6 libc++abi.dylib 0x00000001fe5d2424 std::__terminate(void (*)()) + 12 (:-1)
7 libc++abi.dylib 0x00000001fe5d4f90 __cxa_rethrow + 144 (:-1)
8 libobjc.A.dylib 0x00000001ad5b70fc objc_exception_rethrow + 40 (objc-exception.mm:401)
9 CoreFoundation 0x00000001b42d1de4 CFRunLoopRunSpecific + 780 (CFRunLoop.c:3434)
10 GraphicsServices 0x00000001ebae5998 GSEventRunModal + 160 (GSEvent.c:2196)
11 UIKitCore 0x00000001b656434c -[UIApplication _run] + 868 (UIApplication.m:3782)
12 UIKitCore 0x00000001b6563fc4 UIApplicationMain + 312 (UIApplication.m:5372)
13 GBAuth3 0x0000000101250f80 0x100f68000 + 3051392
14 dyld 0x00000001d1a80344 start + 1860 (dyldMain.cpp:1165)

I think I found the culprit (in my codes):
fl.canonicalize();

Once this removed to run on iOS, the app stops to crash. I rather run the command on desktop only now,

#if desktop
fl.canonicalize();
#end

The problem seems to have fixed now. Sorry, for the noise. )

1 Like

Interesting, I wonder if the internal FileSystem.readDirectory() call is throwing an exception on iOS.