Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when using a View with optional content #362

Closed
foscomputerservices opened this issue Jan 19, 2021 · 0 comments · Fixed by #364
Closed

Crash when using a View with optional content #362

foscomputerservices opened this issue Jan 19, 2021 · 0 comments · Fixed by #364
Assignees
Labels
bug Something isn't working

Comments

@foscomputerservices
Copy link
Contributor

Describe the bug

Given the following code:

private struct NewsImageView: View {
  let bodyViewModel: NewsFeedItemModel

  var body: some View {
    if let image = bodyViewModel.image {
      VStack {
        image.view

        Spacer()
      }
    }
  }
}

I get the following crash:

Could not cast value of type 'Swift.Optional<TokamakCore.VStack<TokamakCore.TupleView<(TokamakCore.ModifiedContent<TokamakCore.ModifiedContent<TokamakCore.ModifiedContent<TokamakCore.ModifiedContent<DMTDViews.DMTDImageView, TokamakCore._PaddingLayout>, TokamakCore._FrameLayout>, TokamakCore._BackgroundModifier<TokamakCore._ShapeView<TokamakCore.RoundedRectangle, TokamakCore.Color>>>, TokamakCore._OverlayModifier<TokamakCore._ShapeView<TokamakCore._StrokedShape<TokamakCore.RoundedRectangle>, TokamakCore.Color>>>, TokamakCore.Spacer)>>>' (0xf02238) to 'TokamakCore.ViewDeferredToRenderer' (0xf1afe4).
dev.js:48:17
Could not cast value of type 'Swift.Optional<TokamakCore.VStack<TokamakCore.TupleView<(TokamakCore.ModifiedContent<TokamakCore.ModifiedContent<TokamakCore.ModifiedContent<TokamakCore.ModifiedContent<DMTDViews.DMTDImageView, TokamakCore._PaddingLayout>, TokamakCore._FrameLayout>, TokamakCore._BackgroundModifier<TokamakCore._ShapeView<TokamakCore.RoundedRectangle, TokamakCore.Color>>>, TokamakCore._OverlayModifier<TokamakCore._ShapeView<TokamakCore._StrokedShape<TokamakCore.RoundedRectangle>, TokamakCore.Color>>>, TokamakCore.Spacer)>>>' (0xf02238) to 'TokamakCore.ViewDeferredToRenderer' (0xf1afe4).
dev.js:48:17
    writeSync webpack:///./entrypoint/dev.js?:48
    fd_write webpack:///./node_modules/@wasmer/wasi/lib/index.esm.js?:115
    fd_write webpack:///./node_modules/@wasmer/wasi/lib/index.esm.js?:115
    Z webpack:///./node_modules/@wasmer/wasi/lib/index.esm.js?:102
    write http://127.0.0.1:8081/dev.js line 97 > eval line 77 > WebAssembly.instantiate:66666684
    swift_reportError http://127.0.0.1:8081/dev.js line 97 > eval line 77 > WebAssembly.instantiate:50168666
    swift::fatalError(unsigned int, char const*, ...) http://127.0.0.1:8081/dev.js line 97 > eval line 77 > WebAssembly.instantiate:50168724
    swift::swift_dynamicCastFailure(void const*, char const*, void const*, char const*, char const*) http://127.0.0.1:8081/dev.js line 97 > eval line 77 > WebAssembly.instantiate:50140000
    swift::swift_dynamicCastFailure(swift::TargetMetadata<swift::InProcess> const*, swift::TargetMetadata<swift::InProcess> const*, char const*) http://127.0.0.1:8081/dev.js line 97 > eval line 77 > WebAssembly.instantiate:50140097
    _dynamicCastToExistential(swift::OpaqueValue*, swift::OpaqueValue*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetExistentialTypeMetadata<swift::InProcess> const*, swift::DynamicCastFlags) http://127.0.0.1:8081/dev.js line 97 > eval line 77 > WebAssembly.instantiate:50148977
    swift_dynamicCastImpl(swift::OpaqueValue*, swift::OpaqueValue*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetMetadata<swift::InProcess> const*, swift::DynamicCastFlags) http://127.0.0.1:8081/dev.js line 97 > eval line 77 > WebAssembly.instantiate:50146194
    swift_dynamicCast http://127.0.0.1:8081/dev.js line 97 > eval line 77 > WebAssembly.instantiate:50141706
    $s11TokamakCore7AnyViewVyACxcAA0D0RzlufcACypcfU_ http://127.0.0.1:8081/dev.js line 97 > eval line 77 > WebAssembly.instantiate:45725698
    $s11TokamakCore15StackReconcilerC6render16compositeElement4body6resultqd__AA016MountedCompositeG0CyxG_s24ReferenceWritableKeyPathCyAJypGs0nO0CyAJqd__ypcGtlF http://127.0.0.1:8081/dev.js line 97 > eval line 77 > WebAssembly.instantiate:45385640
    $s11TokamakCore15StackReconcilerC6render13compositeViewAA03AnyG0VAA016MountedCompositeG0CyxG_tF http://127.0.0.1:8081/dev.js line 97 > eval line 77 > WebAssembly.instantiate:45386565
    $s11TokamakCore20MountedCompositeViewC5mount6before2on4withy10TargetTypeQzSg_AA0C7ElementCyxGSgAA15StackReconcilerCyxGtF http://127.0.0.1:8081/dev.js line 97 > eval line 77 > WebAssembly.instantiate:44977731
    $s11TokamakCore20MountedCompositeViewC5mount6before2on4withy10TargetTypeQzSg_AA0C7ElementCyxGSgAA15StackReconcilerCyxGtF http://127.0.0.1:8081/dev.js line 97 > eval line 77 > WebAssembly.instantiate:44978046
    $s11TokamakCore15MountedHostViewC5mount6before2on4withy10TargetTypeQzSg_AA0C7ElementCyxGSgAA15StackReconcilerCyxGtFyAMXEfU0_ http://127.0.0.1:8081/dev.js line 97 > eval line 77 > WebAssembly.instantiate:45065615
    $s11TokamakCore15MountedHostViewC5mount6before2on4withy10TargetTypeQzSg_AA0C7ElementCyxGSgAA15StackReconcilerCyxGtFyAMXEfU0_TA http://127.0.0.1:8081/dev.js line 97 > eval line 77 > WebAssembly.instantiate:45064663
    $s11TokamakCore14MountedElementCyxGs5Error_pIggzo_ADsAE_pIegnzo_AA8RendererRzlTR http://127.0.0.1:8081/dev.js line 97 > eval line 77 > WebAssembly.instantiate:44942870
    $s11TokamakCore14MountedElementCyxGs5Error_pIggzo_ADsAE_pIegnzo_AA8RendererRzlTRTA

I think that this is from AnyView.swift:63:

  bodyType = V.Body.self
  self.view = view
  if view is ViewDeferredToRenderer {
    // swiftlint:disable:next force_cast
    bodyClosure = { ($0 as! ViewDeferredToRenderer).deferredBody } // <<-- here?
  } else {
    // swiftlint:disable:next force_cast
    bodyClosure = { AnyView(($0 as! V).body) }
  }

I'm not sure what the appropriate solution would be here. I thought that the ViewBuilder would handle this case and substitute an EmptyView, but that doesn't seem to be the case. I'm sure I'm missing something simple for the fix, I just can't quite grasp it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants