JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.81k stars 1.15k forks source link

IllegalStateException when trying to run on iOS Simulator without Metal support #3443

Open tabatsky opened 1 year ago

tabatsky commented 1 year ago

Describe the bug When I'm trying to run compose-multiplatform-ios-android-template on iOS Simulator without Metal support (iOS Simulator under macOS Ventura on VMWare Workstation), I'm getting the following error:

Uncaught Kotlin exception: kotlin.IllegalStateException: Metal is not supported on this system at 0 My application 0x107c94feb kfun:kotlin.Throwable#(kotlin.String?){} + 107 at 1 My application 0x107c8eed7 kfun:kotlin.Exception#(kotlin.String?){} + 103 at 2 My application 0x107c8f107 kfun:kotlin.RuntimeException#(kotlin.String?){} + 103 at 3 My application 0x107c8f407 kfun:kotlin.IllegalStateException#(kotlin.String?){} + 103 at 4 My application 0x1080a190b kfun:org.jetbrains.skiko.redrawer.MetalRedrawer#(org.jetbrains.skiko.SkiaLayer){} + 1147 at 5 My application 0x1080746c6 kfun:org.jetbrains.skiko.SkiaLayer#attachTo(platform.UIKit.UIView){} + 422 at 6 My application 0x10808abda kfun:org.jetbrains.skiko.SkikoUIView#load(){}org.jetbrains.skiko.SkikoUIView + 3642 at 7 My application 0x1083f749b kfun:androidx.compose.ui.window.ComposeWindow#objc:loadView + 1755 at 8 My application 0x108404b63 _6f72672e6a6574627261696e732e636f6d706f73652e75693a75692f6f70742f6275696c644167656e742f776f726b2f356234626566333562333562396631322f636f6d706f73652f75692f75692f7372632f75696b69744d61696e2f6b6f746c696e2f616e64726f6964782f636f6d706f73652f75692f77696e646f772f436f6d706f736557696e646f772e75696b69742e6b74_knbridge208 + 195 at 9 UIKitCore 0x124d0ca15 -[UIViewController loadViewIfRequired] + 92 at 10 UIKitCore 0x124d0d242 -[UIViewController view] + 26 at 11 SwiftUI 0x11396c751 get_witness_table 7SwiftUI4ViewRzlAA15ModifiedContentVyxAA11_ClipEffectVyAA9RectangleVGGAaBHPxAaBHD1AiA0C8ModifierHPyHCHCTm + 3662 at 12 SwiftUI 0x11396c73f get_witness_table 7SwiftUI4ViewRzlAA15ModifiedContentVyxAA11_ClipEffectVyAA9RectangleVGGAaBHPxAaBHD1__AiA0C8ModifierHPyHCHCTm + 3644 at 13 SwiftUI 0x11414b20b block_destroy_helper + 19612 at 14 SwiftUI 0x11414b041 block_destroy_helper + 19154 at 15 SwiftUI 0x11414c083 block_destroy_helper + 23316 at 16 SwiftUI 0x11414b0fe block_destroy_helper + 19343 at 17 SwiftUI 0x113b7ebb2 get_witness_table 7SwiftUI4ViewRzlAA15ModifiedContentVyxAA30_EnvironmentKeyWritingModifierVyAA11FindContextVGGAaBHPxAaBHD1AiA0cI0HPyHCHCTm + 16333 at 18 SwiftUI 0x113b82d81 get_witness_table 7SwiftUI4ViewRzlAA15ModifiedContentVyxAA30_EnvironmentKeyWritingModifierVyAA11FindContextVGGAaBHPxAaBHD1AiA0cI0HPyHCHCTm + 33180 at 19 SwiftUI 0x113b7d117 get_witness_table 7SwiftUI4ViewRzlAA15ModifiedContentVyxAA30_EnvironmentKeyWritingModifierVyAA11FindContextVGGAaBHPxAaBHD1__AiA0cI0HPyHCHCTm + 9522 at 20 SwiftUI 0x113b7ea85 get_witness_table 7SwiftUI4ViewRzlAA15ModifiedContentVyxAA30_EnvironmentKeyWritingModifierVyAA11FindContextVGGAaBHPxAaBHD1AiA0cI0HPyHCHCTm + 16032 at 21 SwiftUI 0x113b7df1d get_witness_table 7SwiftUI4ViewRzlAA15ModifiedContentVyxAA30_EnvironmentKeyWritingModifierVyAA11FindContextVGGAaBHPxAaBHD1AiA0cI0HPyHCHCTm + 13112 at 22 SwiftUI 0x11326e838 swift_memcpy32_8 + 6748 at 23 AttributeGraph 0x117cbf749 _ZN2AG5Graph11UpdateStack6updateEv + 547 at 24 AttributeGraph 0x117cbfefe _ZN2AG5Graph16update_attributeENS_4data3ptrINS_4NodeEEEj + 436 at 25 AttributeGraph 0x117cc781c _ZN2AG5Graph20input_value_ref_slowENS_4data3ptrINS_4NodeEEENS_11AttributeIDEjPK15AGSwiftMetadataRhl + 308 at 26 AttributeGraph 0x117cdf39b AGGraphGetValue + 217 at 27 SwiftUI 0x113b7f795 get_witness_table 7SwiftUI4ViewRzlAA15ModifiedContentVyxAA30_EnvironmentKeyWritingModifierVyAA11FindContextVGGAaBHPxAaBHD1AiA0cI0HPyHCHCTm + 19376 at 28 SwiftUI 0x113b7f8ae get_witness_table 7SwiftUI4ViewRzlAA15ModifiedContentVyxAA30_EnvironmentKeyWritingModifierVyAA11FindContextVGGAaBHPxAaBHD1AiA0cI0HPyHCHCTm + 19657 at 29 SwiftUI 0x11326e838 swift_memcpy32_8 + 6748 at 30 AttributeGraph 0x117cbf749 _ZN2AG5Graph11UpdateStack6updateEv + 547 at 31 AttributeGraph 0x117cbfefe _ZN2AG5Graph16update_attributeENS_4data3ptrINS_4NodeEEEj + 436 at 32 AttributeGraph 0x117cc7798 _ZN2AG5Graph20input_value_ref_slowENS_4data3ptrINS_4NodeEEENS_11AttributeIDEjPK15AGSwiftMetadataRhl + 176 at 33 AttributeGraph 0x117cdf1b0 AGGraphGetInputValue + 241 at 34 SwiftUI 0x11345c888 block_destroy_helper + 82323 at 35 SwiftUI 0x1136c1843 objectdestroyTm + 7841 at 36 SwiftUI 0x11367b355 swift_memcpy99_8 + 117603 at 37 SwiftUI 0x11367b20d swift_memcpy99_8 + 117275 at 38 SwiftUI 0x11367b37d swift_memcpy99_8 + 117643 at 39 SwiftUI 0x113d54395 block_destroy_helper + 83627 at 40 SwiftUI 0x1136ae482 swift_memcpy38_4 + 34764 at 41 SwiftUI 0x1131c2dca swift_memcpy40_8 + 17334 at 42 SwiftUI 0x113233e76 objectdestroy.7158Tm + 12391 at 43 AttributeGraph 0x117cbf749 _ZN2AG5Graph11UpdateStack6updateEv + 547 at 44 AttributeGraph 0x117cbfefe _ZN2AG5Graph16update_attributeENS_4data3ptrINS_4NodeEEEj + 436 at 45 AttributeGraph 0x117cc781c _ZN2AG5Graph20input_value_ref_slowENS_4data3ptrINS_4NodeEEENS_11AttributeIDEjPK15AGSwiftMetadataRhl + 308 at 46 AttributeGraph 0x117cdf1b0 AGGraphGetInputValue + 241 at 47 SwiftUI 0x1133f0fa0 swift_memcpy20_8 + 7016 at 48 SwiftUI 0x1133f1b90 swift_memcpy20_8 + 10072 at 49 SwiftUI 0x1136c15d5 objectdestroyTm + 7219 at 50 SwiftUI 0x112fee1e7 objectdestroy.10Tm + 1176579 at 51 SwiftUI 0x1131c0cf9 swift_memcpy40_8 + 8933 at 52 SwiftUI 0x1131f4a41 objectdestroy.1648Tm + 6854 at 53 AttributeGraph 0x117cbf749 _ZN2AG5Graph11UpdateStack6updateEv + 547 at 54 AttributeGraph 0x117cbfefe _ZN2AG5Graph16update_attributeENS_4data3ptrINS_4NodeEEEj + 436 at 55 AttributeGraph 0x117cc781c _ZN2AG5Graph20input_value_ref_slowENS_4data3ptrINS_4NodeEEENS_11AttributeIDEjPK15AGSwiftMetadataRhl + 308 at 56 AttributeGraph 0x117cdf39b AGGraphGetValue + 217 at 57 SwiftUI 0x113f7da38 objectdestroyTm + 92430 at 58 SwiftUI 0x11323742c __swift_destroy_boxed_opaque_existential_1Tm + 8868 at 59 AttributeGraph 0x117cbf749 _ZN2AG5Graph11UpdateStack6updateEv + 547 at 60 AttributeGraph 0x117cbfefe _ZN2AG5Graph16update_attributeENS_4data3ptrINS_4NodeEEEj + 436 at 61 AttributeGraph 0x117ccca6e _ZN2AG8Subgraph6updateEj + 958 at 62 SwiftUI 0x1136ac6d2 swift_memcpy38_4 + 27164 at 63 SwiftUI 0x113eed38e swift_allocate_boxed_opaque_existential_1Tm + 68009 at 64 SwiftUI 0x113ee3141 __swift_allocate_boxed_opaque_existential_1Tm + 26460 at 65 SwiftUI 0x1142a94be swift_memcpy106_8 + 51965 at 66 SwiftUI 0x1142a9504 swift_memcpy106_8 + 52035 at 67 UIKitCore 0x125c52082 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2312 at 68 QuartzCore 0x10bec8d97 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 525 at 69 QuartzCore 0x10bed4848 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 64 at 70 QuartzCore 0x10bde415d _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 623 at 71 QuartzCore 0x10be1a804 _ZN2CA11Transaction6commitEv + 722 at 72 UIKitCore 0x125637577 34-[UIApplication _firstCommitBlock]_block_invoke_2 + 33 at 73 CoreFoundation 0x10b6be985 CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 11 at 74 CoreFoundation 0x10b6be147 CFRunLoopDoBlocks + 398 at 75 CoreFoundation 0x10b6b89ce CFRunLoopRun + 909 at 76 CoreFoundation 0x10b6b8263 CFRunLoopRunSpecific + 559 at 77 GraphicsServices 0x110d1824d GSEventRunModal + 138 at 78 UIKitCore 0x1256177be -[UIApplication _run] + 993 at 79 UIKitCore 0x12561c5dd UIApplicationMain + 122 at 80 SwiftUI 0x113f875ec swift_memcpy93_8 + 12402 at 81 SwiftUI 0x113f874a5 swift_memcpy93_8 + 12075 at 82 SwiftUI 0x11369d60f __swift_memcpy195_8 + 14236 at 83 My application 0x107c7f51d $s14My_application6iOSAppV5$mainyyFZ + 29 (/Users/jatx/AndroidStudioProjects/compose-multiplatform-template/iosApp/iosApp/iOSApp.swift:) at 84 My application 0x107c7f5a8 main + 8 at 85 dyld 0x10a621383 0x0 + 4469166979 at 86 ??? 0x119e0041e 0x0 + 4729078814

I've tried to set SKIKO_RENDER_API environment variable to "SOFTWARE" value like following:

struct ComposeView: UIViewControllerRepresentable {
    func makeUIViewController(context: Context) -> UIViewController {
        setenv("SKIKO_RENDER_API", "SOFTWARE", 1)
        return Main_iosKt.MainViewController()
    }

    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}

But it does not help.

Affected platforms Select one of the platforms below:

Versions

To Reproduce Steps and/or the code snippet to reproduce the behavior:

  1. Run macOS on VMWare Workstation.
  2. Try to launch compose-multiplatform-ios-android-template from Android Studio or XCode.
  3. See error

Expected behavior App is starting in iOS Simulator without errors.

elijah-semyonov commented 1 year ago

@tabatsky Software renderer is not supported for iOS target and Metal is only available on conventional setups (VMWare doesn't provide Metal driver). Implementing it is very low priority for us and likely won't be fixed.

vbudilov commented 1 year ago

Hi Elijah, mind elaborating on this? Is there anything that can be done to run the app on an iOS simulator? I'm running the simulator on a MacBook Pro (not in a VM) and I'm getting the same error. Here's my config:

image
elijah-semyonov commented 1 year ago

Can you provide more info about Compose, Kotlin, macOS versions, MacBook model? It should run on simulator just fine.

Can you create a new Xcode iOS app (Swift, Storyboard) project and put this code into ViewController.swift

import UIKit
import Metal

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let device = MTLCreateSystemDefaultDevice()

        print(device)
    }
}

and launch it on very same simulator? What does it print?

If it prints nil, something is wrong with your Xcode installation or simulator configuration.

Woren commented 10 months ago

I had/have similar problem. Configuration: MacBook Pro M2 Max, 64GB RAM; MacOS 14.0 (23A344), Xcode 15.0 (15A240d); Kotlin 1.9.10; Compose 1.5.3;

iPhone 15 Pro with iOS 17.0 prints nil, changing simulator to same configuration but this time Pro Max prints: Optional(<CaptureMTLDevice: 0x10d109c30> -> <MTLDebugDevice: 0x10d109a10> -> <MTLSimDevice: 0x10d109360> name = Apple iOS simulator GPU)

Also I got this problem for different project not just this template.

jabouzi commented 8 months ago

I just got the same error, more the already installed app stopped working, I had an xcode command line update waiting and I restarted the simulator and everything is back as before

juanka-cybergod commented 6 months ago

Same Error, there is any solution ?

elijah-semyonov commented 5 months ago

Try to reinstall Xcode, inability to instantiate MTLDevice on the simulator is not something we can fix from our side.

okushnikov commented 1 month ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

TzvetomirBG commented 3 weeks ago

In my case kotlin multiplatform project with native UI (SwiftUI) from the Kotlin Multiplatform Wizard is perfectly running on my VMWare macOS system but the kotlin multiplatform project with compose UI framework is giving the error: kotlin.IllegalStateException: Metal is not supported on this system. So i guess that the problem is not in the Software renderer but in the difference of the the UI Implementation.