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 mixing with JavaFx coroutines #17

Closed
dector opened this issue Oct 18, 2020 · 9 comments
Closed

Crash when mixing with JavaFx coroutines #17

dector opened this issue Oct 18, 2020 · 9 comments
Assignees
Milestone

Comments

@dector
Copy link
Collaborator

dector commented Oct 18, 2020

I'm migrating existing JavaFx app to current Compose version. Found an issue when trying to render Text():

Log fragment
---------------  T H R E A D  ---------------

Current thread (0x00007fd358873800): JavaThread "JavaFX Application Thread" [_thread_in_native, id=4109, stack(0x00007fd2c9b45000,0x00007fd2c9c46000)]

Stack: [0x00007fd2c9b45000,0x00007fd2c9c46000], sp=0x00007fd2c9c3d868, free space=994k
Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [libfreetype.so.6+0x8a053]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j org.jetbrains.skija.paragraph.Paragraph._nLayout(JF)V+0
j org.jetbrains.skija.paragraph.Paragraph.layout(F)Lorg/jetbrains/skija/paragraph/Paragraph;+8
j androidx.compose.ui.text.platform.DesktopParagraphIntrinsics.(Ljava/lang/String;Landroidx/compose/ui/text/TextStyle;Ljava/util/List;Ljava/util/List;Landroidx/compose/ui/unit/Density;Landroidx/compose/ui/text/font/Font$ResourceLoader;)V+104
j androidx.compose.ui.text.platform.DesktopParagraphIntrinsicsKt.ActualParagraphIntrinsics(Ljava/lang/String;Landroidx/compose/ui/text/TextStyle;Ljava/util/List;Ljava/util/List;Landroidx/compose/ui/unit/Density;Landroidx/compose/ui/text/font/Font$ResourceLoader;)Landroidx/compose/ui/text/ParagraphIntrinsics;+50
j androidx.compose.ui.text.ParagraphIntrinsicsKt.ParagraphIntrinsics(Ljava/lang/String;Landroidx/compose/ui/text/TextStyle;Ljava/util/List;Ljava/util/List;Landroidx/compose/ui/unit/Density;Landroidx/compose/ui/text/font/Font$ResourceLoader;)Landroidx/compose/ui/text/ParagraphIntrinsics;+46
j androidx.compose.ui.text.MultiParagraphIntrinsics.(Landroidx/compose/ui/text/AnnotatedString;Landroidx/compose/ui/text/TextStyle;Ljava/util/List;Landroidx/compose/ui/unit/Density;Landroidx/compose/ui/text/font/Font$ResourceLoader;)V+268
j androidx.compose.ui.text.TextDelegate.layoutIntrinsics(Landroidx/compose/ui/unit/LayoutDirection;)V+72
j androidx.compose.ui.text.TextDelegate.layoutText(FFLandroidx/compose/ui/unit/LayoutDirection;)Landroidx/compose/ui/text/MultiParagraph;+2
j androidx.compose.ui.text.TextDelegate.layout-BAnaFRY(JLandroidx/compose/ui/unit/LayoutDirection;Landroidx/compose/ui/text/TextLayoutResult;)Landroidx/compose/ui/text/TextLayoutResult;+206
j androidx.compose.foundation.text.CoreTextKt$CoreText$10.invoke(Landroidx/compose/ui/MeasureScope;Ljava/util/List;J)Landroidx/compose/ui/MeasureScope$MeasureResult;+31
j androidx.compose.foundation.text.CoreTextKt$CoreText$10.invoke(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+16
j androidx.compose.ui.LayoutKt$measureBlocksOf$1.measure-2MWCACw(Landroidx/compose/ui/MeasureScope;Ljava/util/List;J)Landroidx/compose/ui/MeasureScope$MeasureResult;+22
j androidx.compose.ui.node.InnerPlaceable.performMeasure-BRTryo0(J)Landroidx/compose/ui/Placeable;+22
j androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+7
j androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(J)Landroidx/compose/ui/Placeable;+5
j androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+7
j androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(J)Landroidx/compose/ui/Placeable;+5
j androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+7
j androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(J)Landroidx/compose/ui/Placeable;+5
j androidx.compose.ui.node.LayerWrapper.performMeasure-BRTryo0(J)Landroidx/compose/ui/Placeable;+2
j androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+7
j androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(J)Landroidx/compose/ui/Placeable;+5
j androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+7
j androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke()V+11
j androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke()Ljava/lang/Object;+1
j androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)V+149
j androidx.compose.ui.platform.DesktopOwner.observeMeasureModelReads(Landroidx/compose/ui/node/LayoutNode;Lkotlin/jvm/functions/Function0;)V+27
j androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(J)Z+218
j androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+115
j androidx.compose.ui.node.LayoutNode.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+5
j androidx.compose.foundation.layout.BoxKt$Box$1$1.invoke(Landroidx/compose/ui/MeasureScope;Ljava/util/List;J)Landroidx/compose/ui/MeasureScope$MeasureResult;+223
j androidx.compose.foundation.layout.BoxKt$Box$1$1.invoke(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+16
j androidx.compose.ui.LayoutKt$MeasuringIntrinsicsMeasureBlocks$1.measure-2MWCACw(Landroidx/compose/ui/MeasureScope;Ljava/util/List;J)Landroidx/compose/ui/MeasureScope$MeasureResult;+22
j androidx.compose.ui.node.InnerPlaceable.performMeasure-BRTryo0(J)Landroidx/compose/ui/Placeable;+22
j androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+7
j androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke()V+11
j androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke()Ljava/lang/Object;+1
j androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)V+149
j androidx.compose.ui.platform.DesktopOwner.observeMeasureModelReads(Landroidx/compose/ui/node/LayoutNode;Lkotlin/jvm/functions/Function0;)V+27
j androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(J)Z+218
j androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+115
j androidx.compose.ui.node.LayoutNode.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+5
j androidx.compose.ui.platform.DesktopSelectionKt$Wrap$1$1.invoke(Landroidx/compose/ui/MeasureScope;Ljava/util/List;J)Landroidx/compose/ui/MeasureScope$MeasureResult;+92
j androidx.compose.ui.platform.DesktopSelectionKt$Wrap$1$1.invoke(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+16
j androidx.compose.ui.LayoutKt$MeasuringIntrinsicsMeasureBlocks$1.measure-2MWCACw(Landroidx/compose/ui/MeasureScope;Ljava/util/List;J)Landroidx/compose/ui/MeasureScope$MeasureResult;+22
j androidx.compose.ui.node.InnerPlaceable.performMeasure-BRTryo0(J)Landroidx/compose/ui/Placeable;+22
j androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+7
j androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(J)Landroidx/compose/ui/Placeable;+5
j androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+7
j androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(J)Landroidx/compose/ui/Placeable;+5
j androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+7
j androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke()V+11
j androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke()Ljava/lang/Object;+1
j androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)V+149
j androidx.compose.ui.platform.DesktopOwner.observeMeasureModelReads(Landroidx/compose/ui/node/LayoutNode;Lkotlin/jvm/functions/Function0;)V+27
j androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(J)Z+218
j androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+115
j androidx.compose.ui.node.LayoutNode.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+5
j androidx.compose.ui.RootMeasureBlocks.measure-2MWCACw(Landroidx/compose/ui/MeasureScope;Ljava/util/List;J)Landroidx/compose/ui/MeasureScope$MeasureResult;+60
j androidx.compose.ui.node.InnerPlaceable.performMeasure-BRTryo0(J)Landroidx/compose/ui/Placeable;+22
j androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+7
j androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(J)Landroidx/compose/ui/Placeable;+5
j androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+7
j androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(J)Landroidx/compose/ui/Placeable;+5
j androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+7
j androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(J)Landroidx/compose/ui/Placeable;+5
j androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+7
j androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(J)Landroidx/compose/ui/Placeable;+5
j androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+7
j androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(J)Landroidx/compose/ui/Placeable;+5
j androidx.compose.ui.node.LayerWrapper.performMeasure-BRTryo0(J)Landroidx/compose/ui/Placeable;+2
j androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(J)Landroidx/compose/ui/Placeable;+7
j androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke()V+11
j androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke()Ljava/lang/Object;+1
j androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;+110
j androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)V+123
j androidx.compose.ui.platform.DesktopOwner.observeMeasureModelReads(Landroidx/compose/ui/node/LayoutNode;Lkotlin/jvm/functions/Function0;)V+27
j androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(J)Z+218
j androidx.compose.ui.node.LayoutNode.remeasure-BRTryo0$ui(J)Z+5
j androidx.compose.ui.node.MeasureAndLayoutDelegate.doRemeasure(Landroidx/compose/ui/node/LayoutNode;)Z+13
j androidx.compose.ui.node.MeasureAndLayoutDelegate.access$doRemeasure(Landroidx/compose/ui/node/MeasureAndLayoutDelegate;Landroidx/compose/ui/node/LayoutNode;)Z+2
j androidx.compose.ui.node.MeasureAndLayoutDelegate.measureAndLayout()Z+186
j androidx.compose.ui.platform.DesktopOwner.draw(Lorg/jetbrains/skija/Canvas;)V+11
j androidx.compose.ui.platform.DesktopOwners.onRender(Lorg/jetbrains/skija/Canvas;IIJ)V+56
j androidx.compose.desktop.OwnersRenderer.onRender(Lorg/jetbrains/skija/Canvas;IIJ)V+16
j androidx.compose.desktop.FrameSkiaLayer.preparePicture(J)V+70
j androidx.compose.desktop.FrameSkiaLayer.access$preparePicture(Landroidx/compose/desktop/FrameSkiaLayer;J)V+2
j androidx.compose.desktop.FrameSkiaLayer$wrapped$1.redrawLayer()V+11
j androidx.compose.desktop.FrameSkiaLayer.onFrame(J)V+9
j androidx.compose.desktop.FrameSkiaLayer.access$onFrame(Landroidx/compose/desktop/FrameSkiaLayer;J)V+2
j androidx.compose.desktop.FrameSkiaLayer$frameDispatcher$1.invokeSuspend(Ljava/lang/Object;)Ljava/lang/Object;+40
j androidx.compose.desktop.FrameSkiaLayer$frameDispatcher$1.invoke(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+15
j androidx.compose.desktop.FrameDispatcher$job$1.invokeSuspend(Ljava/lang/Object;)Ljava/lang/Object;+135
j kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(Ljava/lang/Object;)V+46
j kotlinx.coroutines.DispatchedTask.run()V+334
j com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Ljava/lang/Runnable;)Ljava/lang/Void;+1
j com.sun.javafx.application.PlatformImpl$$Lambda$192.run()Ljava/lang/Object;+4
v ~StubRoutines::call_stub
j java.security.AccessController.doPrivileged(Ljava/security/PrivilegedAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;+0 java.base@11.0.8
j com.sun.javafx.application.PlatformImpl.lambda$runLater$11(Ljava/lang/Runnable;Ljava/security/AccessControlContext;)V+7
j com.sun.javafx.application.PlatformImpl$$Lambda$191.run()V+8
j com.sun.glass.ui.InvokeLaterDispatcher$Future.run()V+4
v ~StubRoutines::call_stub
j com.sun.glass.ui.gtk.GtkApplication._runLoop(Ljava/lang/Runnable;Z)V+0
j com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(Ljava/lang/Runnable;Z)V+7
j com.sun.glass.ui.gtk.GtkApplication$$Lambda$179.run()V+12
j java.lang.Thread.run()V+11 java.base@11.0.8
v ~StubRoutines::call_stub

siginfo: si_signo: 11 (SIGSEGV), si_code: 2 (SEGV_ACCERR), si_addr: 0x00007fd321298053

This happens only when Text() is present in hierarchy AND javafx coroutines are included as a dependency.

Here is MRS (open it in IDEA and run MainKt - app will crash almost instantly).

compose-issue.zip

@olonho
Copy link
Contributor

olonho commented Oct 19, 2020

Interesting problem, seems Swing (used by Compose) and JavaFX coroutine dispatchers cannot coexist. So not sure, if such a config is supported. Is it possible to not use JFX coroutine dispatcher?

@dector
Copy link
Collaborator Author

dector commented Oct 19, 2020

Not a major issue for me TBH - I was going to rewrite JavaFX granulary but now I'll just write Compose GUI as a separate app.

So, there is no need to waste time on fixing this.

@pacher
Copy link

pacher commented Nov 5, 2020

So, there is no need to waste time on fixing this.

Please do waste time on fixing this.
I just saw the announcement and will start to migrate to Compose from JavaFx today. But it can not be all done in once, there will be things missing etc. So Compose and JavaFx will co-exist for quite some time for me (I am planning to have JavaFx in different pop-up windows)

And anyway it is quite puzzling to me how is the simple presence of different dispatcher can cause an issue. What if I want to write or use other non-standard dispatchers? What causes the issue? What to look out for?

@mel4tonin4
Copy link

I'd like to gradually experiment with Compose in a JavaFx application which is the desktop version and the control panel of the supporting service of a mobile application, and this is a showstopper for me, too.
Please, do not ignore this issue.

@olonho
Copy link
Contributor

olonho commented Nov 6, 2020

@igordmn IIRC you had simple fix with more explicit dispatcher selector. Can we apply it and check if it helps?

@pacher
Copy link

pacher commented Nov 6, 2020

Wild guess: just find and replace Dispatchers.Main with Dispatchers.Swing in compose codebase?

@olonho olonho added this to the M2 milestone Nov 12, 2020
copybara-service bot pushed a commit to androidx/androidx that referenced this issue Nov 12, 2020
Users can use multiple dispatchers in their code.
For example we can use JavaFX coroutine dispatcher:
JetBrains/compose-multiplatform#17

In that case Dispatchers.Main will become Dispatchers.JavaFx and compose code will be not working properly.

Test: ./gradlew jvmTest desktopTest -Pandroidx.compose.multiplatformEnabled=true
Change-Id: I91a35a4bad8a62a7a533c80dabbbddc213f36baa
@olonho
Copy link
Contributor

olonho commented Nov 16, 2020

@dector could you please check if issue has gone with the build "0.2.0-build123"?

@dector
Copy link
Collaborator Author

dector commented Nov 17, 2020

@olonho 0.2.0-build123 fixes this issue for my sample.

@okushnikov
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants