vinceglb / FileKit

Pick and save Files, Medias and Folder for Kotlin Multiplatform / KMP and Compose Multiplatform / CMP
https://vinceglb.github.io/FileKit/
MIT License
295 stars 13 forks source link

readByte() crashes when running application on a real device #58

Closed SpaceXC closed 1 week ago

SpaceXC commented 2 weeks ago

When I tried to call PlatformFile#readByte() function, the app crashes. The file picker functions are working perfectly on both emulators and real devices. The readByte() function is working perfectly on emulators.

Xcode v.: Version 16.0 beta 2 emulator ipad os v.: 18.0 real device ipad os v.: 18.0

SpaceXC commented 2 weeks ago

stacktrace:

CoreGraphics PDF has logged an error. Set environment variable "CG_PDF_VERBOSE" to learn more.
Uncaught Kotlin exception: kotlin.IllegalStateException: Failed to read data from file:///private/var/mobile/Containers/Shared/AppGroup/6AE4198B-71C6-4C0A-A8CC-D479B0509426/File%20Provider%20Storage/%E2%91%A0%E7%A5%96%E5%9B%BD%E5%B1%B1%E6%98%8E%E6%B0%B4%E7%A7%80.pdf
    at 0   Tunify.debug.dylib                  0x1087e4d23        kfun:kotlin.Throwable#<init>(kotlin.String?){} + 119 
    at 1   Tunify.debug.dylib                  0x1087de703        kfun:kotlin.Exception#<init>(kotlin.String?){} + 115 
    at 2   Tunify.debug.dylib                  0x1087de923        kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 115 
    at 3   Tunify.debug.dylib                  0x1087dee3b        kfun:kotlin.IllegalStateException#<init>(kotlin.String?){} + 115 
    at 4   Tunify.debug.dylib                  0x1096a7e73        kfun:io.github.vinceglb.filekit.core.PlatformFile.readBytes$lambda$0#internal + 663 
    at 5   Tunify.debug.dylib                  0x1096a862b        kfun:io.github.vinceglb.filekit.core.PlatformFile.$readBytes$lambda$0$FUNCTION_REFERENCE$0.invoke#internal + 135 
    at 6   Tunify.debug.dylib                  0x1088e3db3        kfun:kotlin.Function2#invoke(1:0;1:1){}1:2-trampoline + 115 
    at 7   Tunify.debug.dylib                  0x1087ed0c7        kfun:kotlin.coroutines.intrinsics.object-4.invokeSuspend#internal + 731 
    at 8   Tunify.debug.dylib                  0x1088e36cf        kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#invokeSuspend(kotlin.Result<kotlin.Any?>){}kotlin.Any?-trampoline + 67 
    at 9   Tunify.debug.dylib                  0x1087e9adb        kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 623 
    at 10  Tunify.debug.dylib                  0x1088e37af        kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Result<1:0>){}-trampoline + 99 
    at 11  Tunify.debug.dylib                  0x1089c071f        kfun:kotlinx.coroutines.DispatchedTask#run(){} + 1879 
    at 12  Tunify.debug.dylib                  0x1089ee337        kfun:kotlinx.coroutines.Runnable#run(){}-trampoline + 91 
    at 13  Tunify.debug.dylib                  0x1089c3123        kfun:kotlinx.coroutines.internal.LimitedDispatcher.Worker.run#internal + 231 
    at 14  Tunify.debug.dylib                  0x1089ee337        kfun:kotlinx.coroutines.Runnable#run(){}-trampoline + 91 
    at 15  Tunify.debug.dylib                  0x1089e5e1b        kfun:kotlinx.coroutines.MultiWorkerDispatcher.$workerRunLoop$lambda$2COROUTINE$0.invokeSuspend#internal + 1467 
    at 16  Tunify.debug.dylib                  0x1089e625f        kfun:kotlinx.coroutines.MultiWorkerDispatcher.workerRunLoop$lambda$2#internal + 295 
    at 17  Tunify.debug.dylib                  0x1089e65cf        kfun:kotlinx.coroutines.MultiWorkerDispatcher.$workerRunLoop$lambda$2$FUNCTION_REFERENCE$3.invoke#internal + 135 
    at 18  Tunify.debug.dylib                  0x1088e3db3        kfun:kotlin.Function2#invoke(1:0;1:1){}1:2-trampoline + 115 
    at 19  Tunify.debug.dylib                  0x1087ed0c7        kfun:kotlin.coroutines.intrinsics.object-4.invokeSuspend#internal + 731 
    at 20  Tunify.debug.dylib                  0x1088e36cf        kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#invokeSuspend(kotlin.Result<kotlin.Any?>){}kotlin.Any?-trampoline + 67 
    at 21  Tunify.debug.dylib                  0x1087e9adb        kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 623 
    at 22  Tunify.debug.dylib                  0x1088e37af        kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Result<1:0>){}-trampoline + 99 
    at 23  Tunify.debug.dylib                  0x1089c071f        kfun:kotlinx.coroutines.DispatchedTask#run(){} + 1879 
    at 24  Tunify.debug.dylib                  0x1089ee337        kfun:kotlinx.coroutines.Runnable#run(){}-trampoline + 91 
    at 25  Tunify.debug.dylib                  0x1089699d3        kfun:kotlinx.coroutines.EventLoopImplBase#processNextEvent(){}kotlin.Long + 1247 
    at 26  Tunify.debug.dylib                  0x1089ee083        kfun:kotlinx.coroutines.EventLoop#processNextEvent(){}kotlin.Long-trampoline + 51 
    at 27  Tunify.debug.dylib                  0x1089df5fb        kfun:kotlinx.coroutines.BlockingCoroutine.joinBlocking#internal + 435 
    at 28  Tunify.debug.dylib                  0x1089de45f        kfun:kotlinx.coroutines#runBlocking(kotlin.coroutines.CoroutineContext;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,0:0>){0§<kotlin.Any?>}0:0 + 1395 
    at 29  Tunify.debug.dylib                  0x1089de63f        kfun:kotlinx.coroutines#runBlocking$default(kotlin.coroutines.CoroutineContext?;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,0:0>;kotlin.Int){0§<kotlin.Any?>}0:0 + 239 
    at 30  Tunify.debug.dylib                  0x1089e4273        kfun:kotlinx.coroutines.MultiWorkerDispatcher.workerRunLoop#internal + 183 
    at 31  Tunify.debug.dylib                  0x1089e54db        kfun:kotlinx.coroutines.MultiWorkerDispatcher.<init>$lambda$1$lambda$0#internal + 67 
    at 32  Tunify.debug.dylib                  0x1089e67d7        kfun:kotlinx.coroutines.MultiWorkerDispatcher.$<init>$lambda$1$lambda$0$FUNCTION_REFERENCE$5.invoke#internal + 71 
    at 33  Tunify.debug.dylib                  0x1089e68a7        kfun:kotlinx.coroutines.MultiWorkerDispatcher.$<init>$lambda$1$lambda$0$FUNCTION_REFERENCE$5.$<bridge-UNN>invoke(){}#internal + 71 
    at 34  Tunify.debug.dylib                  0x1088e014b        kfun:kotlin.Function0#invoke(){}1:0-trampoline + 99 
    at 35  Tunify.debug.dylib                  0x1087f5c2f        WorkerLaunchpad + 131 
    at 36  Tunify.debug.dylib                  0x10893ece3        _ZN6Worker19processQueueElementEb + 2635 
    at 37  Tunify.debug.dylib                  0x10893e123        _ZN12_GLOBAL__N_113workerRoutineEPv + 219 
    at 38  libsystem_pthread.dylib             0x225eef37b        _pthread_start + 135 
    at 39  libsystem_pthread.dylib             0x225eea493        thread_start + 7 
    Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.runtime.BroadcastFrameClock@afd4528, StandaloneCoroutine{Cancelling}@b171580, FlushCoroutineDispatcher@b294160]
        at 0   Tunify.debug.dylib                  0x1087e4d23        kfun:kotlin.Throwable#<init>(kotlin.String?){} + 119 
        at 1   Tunify.debug.dylib                  0x1087de703        kfun:kotlin.Exception#<init>(kotlin.String?){} + 115 
        at 2   Tunify.debug.dylib                  0x1087de923        kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 115 
        at 3   Tunify.debug.dylib                  0x1089e7c17        kfun:kotlinx.coroutines.internal.DiagnosticCoroutineContextException#<init>(kotlin.coroutines.CoroutineContext){} + 167 
        at 4   Tunify.debug.dylib                  0x1089bc9cb        kfun:kotlinx.coroutines.internal#handleUncaughtCoroutineException(kotlin.coroutines.CoroutineContext;kotlin.Throwable){} + 647 
        at 5   Tunify.debug.dylib                  0x108965637        kfun:kotlinx.coroutines#handleCoroutineException(kotlin.coroutines.CoroutineContext;kotlin.Throwable){} + 515 
        at 6   Tunify.debug.dylib                  0x10895974b        kfun:kotlinx.coroutines.StandaloneCoroutine.handleJobException#internal + 167 
        at 7   Tunify.debug.dylib                  0x1089ef4d3        kfun:kotlinx.coroutines.JobSupport#handleJobException(kotlin.Throwable){}kotlin.Boolean-trampoline + 59 
        at 8   Tunify.debug.dylib                  0x10896f15b        kfun:kotlinx.coroutines.JobSupport.finalizeFinishingState#internal + 1135 
        at 9   Tunify.debug.dylib                  0x1089775c3        kfun:kotlinx.coroutines.JobSupport.tryMakeCompletingSlowPath#internal + 2035 
        at 10  Tunify.debug.dylib                  0x108976d97        kfun:kotlinx.coroutines.JobSupport.tryMakeCompleting#internal + 755 
        at 11  Tunify.debug.dylib                  0x1089768c7        kfun:kotlinx.coroutines.JobSupport#makeCompletingOnce(kotlin.Any?){}kotlin.Any? + 379 
        at 12  Tunify.debug.dylib                  0x108955d23        kfun:kotlinx.coroutines.AbstractCoroutine#resumeWith(kotlin.Result<1:0>){} + 211 
        at 13  Tunify.debug.dylib                  0x1088e37af        kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Result<1:0>){}-trampoline + 99 
        at 14  Tunify.debug.dylib                  0x1087e9cf7        kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 1163 
        at 15  Tunify.debug.dylib                  0x1088e37af        kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Result<1:0>){}-trampoline + 99 
        at 16  Tunify.debug.dylib                  0x1089c0663        kfun:kotlinx.coroutines.DispatchedTask#run(){} + 1691 
        at 17  Tunify.debug.dylib                  0x1089ee337        kfun:kotlinx.coroutines.Runnable#run(){}-trampoline + 91 
        at 18  Tunify.debug.dylib                  0x10943c2b7        kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.dispatch$lambda$1$lambda$0#internal + 475 
        at 19  Tunify.debug.dylib                  0x10943d81f        kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.$dispatch$lambda$1$lambda$0$FUNCTION_REFERENCE$4.invoke#internal + 75 
        at 20  Tunify.debug.dylib                  0x10943d91b        kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.$dispatch$lambda$1$lambda$0$FUNCTION_REFERENCE$4.$<bridge-UNN>invoke(){}#internal + 71 
        at 21  Tunify.debug.dylib                  0x1088e014b        kfun:kotlin.Function0#invoke(){}1:0-trampoline + 99 
        at 22  Tunify.debug.dylib                  0x10943bbbf        kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.performRun#internal + 319 
        at 23  Tunify.debug.dylib                  0x10943c43f        kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.dispatch$lambda$1#internal + 239 
        at 24  Tunify.debug.dylib                  0x10943d2cb        kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.$dispatch$lambda$1$FUNCTION_REFERENCE$0.invoke#internal + 139 
        at 25  Tunify.debug.dylib                  0x1088e3db3        kfun:kotlin.Function2#invoke(1:0;1:1){}1:2-trampoline + 115 
        at 26  Tunify.debug.dylib                  0x1087ed0c7        kfun:kotlin.coroutines.intrinsics.object-4.invokeSuspend#internal + 731 
        at 27  Tunify.debug.dylib                  0x1088e36cf        kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#invokeSuspend(kotlin.Result<kotlin.Any?>){}kotlin.Any?-trampoline + 67 
        at 28  Tunify.debug.dylib                  0x1087e9adb        kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 623 
        at 29  Tunify.debug.dylib                  0x1088e37af        kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Result<1:0>){}-trampoline + 99 
        at 30  Tunify.debug.dylib                  0x1089c071f        kfun:kotlinx.coroutines.DispatchedTask#run(){} + 1879 
        at 31  Tunify.debug.dylib                  0x1089ee337        kfun:kotlinx.coroutines.Runnable#run(){}-trampoline + 91 
        at 32  Tunify.debug.dylib                  0x1089ea14f        kfun:kotlinx.coroutines.DarwinMainDispatcher.dispatch$lambda$0#internal + 67 
        at 33  Tunify.debug.dylib                  0x1089ea3cb        kfun:kotlinx.coroutines.DarwinMainDispatcher.$dispatch$lambda$0$FUNCTION_REFERENCE$1.invoke#internal + 71 
        at 34  Tunify.debug.dylib                  0x1089ea49b        kfun:kotlinx.coroutines.DarwinMainDispatcher.$dispatch$lambda$0$FUNCTION_REFERENCE$1.$<bridge-UNN>invoke(){}#internal + 71 
        at 35  Tunify.debug.dylib                  0x1088e014b        kfun:kotlin.Function0#invoke(){}1:0-trampoline + 99 
        at 36  Tunify.debug.dylib                  0x1089eb3df        _6f72672e6a6574627261696e732e6b6f746c696e783a6b6f746c696e782d636f726f7574696e65732d636f72652f6f70742f6275696c644167656e742f776f726b2f343465633665383530643563363366302f6b6f746c696e782d636f726f7574696e65732d636f72652f6e617469766544617277696e2f7372632f44697370617463686572732e6b74_knbridge13 + 191 
        at 37  libdispatch.dylib                   0x105804aaf        _dispatch_call_block_and_release + 31 
        at 38  libdispatch.dylib                   0x10580679b        _dispatch_client_callout + 19 
        at 39  libdispatch.dylib                   0x105816e67        _dispatch_main_queue_drain + 1075 
        at 40  libdispatch.dylib                   0x105816a23        _dispatch_main_queue_callback_4CF + 43 
        at 41  CoreFoundation                      0x19f405167        <redacted> + 15 
        at 42  CoreFoundation                      0x19f402387        <redacted> + 2011 
        at 43  CoreFoundation                      0x19f401713        CFRunLoopRunSpecific + 607 
        at 44  GraphicsServices                    0x1eaed11c3        GSEventRunModal + 163 
        at 45  UIKitCore                           0x1a1f71563        <redacted> + 887 
        at 46  UIKitCore                           0x1a201f52f        UIApplicationMain + 339 
        at 47  SwiftUI                             0x1a3b47efb        <redacted> + 167 
        at 48  SwiftUI                             0x1a3b22537        <redacted> + 99 
        at 49  SwiftUI                             0x1a3b25397        $s7SwiftUI3AppPAAE4mainyyFZ + 223 
        at 50  Tunify.debug.dylib                  0x1086f057b        $s6Tunify6iOSAppV5$mainyyFZ + 39 
        at 51  Tunify.debug.dylib                  0x1086f062b        __debug_main_executable_dylib_entry_point + 11 
        at 52  dyld                                0x1c4f93ccf        <redacted> + 2759 
trexxon-nanno commented 2 weeks ago

Same here.. iOS Simulator works fine, but Device is crashing with same error.

vinceglb commented 2 weeks ago

Hey @SpaceXC and @trexxon-nanno! Thanks for reporting this! I reproduced the crash on my side and actually working on a fix. I'll push the fix shortly 👌

vinceglb commented 1 week ago

It should be fixed with version 0.6.3. Do not hesitate to reopen the issue if it still happens 👌

SpaceXC commented 1 week ago

Thank you very much! Appreciate!