compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

[compose-gradle-plugin] run task makes AWT segfault

Open ptitjes opened this issue 3 years ago • 1 comments
trafficstars

When your run a compose application with the run task contributed by the compose gradle plugin, it adds to the Java command line the following system property:

-Dcompose.application.configure.swing.globals=true

This makes the JVM crash when opening an AWT file dialog:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f5c2c0fa3a7, pid=27662, tid=27710
#
# JRE version: OpenJDK Runtime Environment (Red_Hat-18.0.2.0.9-1.rolling.fc36) (18.0.2+9) (build 18.0.2+9)
# Java VM: OpenJDK 64-Bit Server VM (Red_Hat-18.0.2.0.9-1.rolling.fc36) (18.0.2+9, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# C  [libcairo.so.2+0x973a7]
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h" (or dumping to /home/*************************/core.27662)
#
# An error report file with more information is saved as:
# /home/*************************/hs_err_pid27662.log
#
# If you would like to submit a bug report, please visit:
#   https://bugzilla.redhat.com/enter_bug.cgi?product=Fedora&component=java-latest-openjdk&version=36
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

I cannot provide the full error log nor the core dump.

However, the following minimal application runs well with -Dcompose.application.configure.swing.globals=false but crashes with -Dcompose.application.configure.swing.globals=true:

import androidx.compose.ui.window.*
import java.awt.*

fun main() = application {
    Window(
        title = "Test Application",
        onCloseRequest = ::exitApplication,
    ) {
        AwtWindow(
            create = {
                object : FileDialog(window, "Title", LOAD) {
                    override fun setVisible(value: Boolean) {
                        super.setVisible(value)
                        if (value) {
                            println(file)
                        }
                    }
                }
            },
            dispose = FileDialog::dispose
        )
    }
}

OS: Linux fedora 5.18.17-200.fc36.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Aug 11 14:36:06 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux JVM version: openjdk 18.0.2 2022-07-19 (also crashes with openjdk 17.0.4 2022-07-19) Compose version: 1.2.0-alpha01-dev755

ptitjes avatar Aug 18 '22 15:08 ptitjes

As a workaround, I override the jvm args with the compose gradle plugin dsl:

compose.desktop {
    application {
        // ...

        jvmArgs("-Dcompose.application.configure.swing.globals=false")

        // ...
    }
}

ptitjes avatar Aug 18 '22 15:08 ptitjes

So now my workaround does not work anymore. Here is a reproduction repository https://github.com/ptitjes/repro-compose-issue-2249.

You'll find two main files:

  • Main.kt, launches an AWT FileDialog through Compose integration (and fails)
  • MainAwt.kt, launchs an AWT FileDialog directly (and succeeds)

ptitjes avatar Jan 11 '23 15:01 ptitjes

I can also reproduce this with https://github.com/oss-review-toolkit/ort-workbench, ./gradlew run, and then clicking on "Load ORT Result".

sschuberth avatar Jan 17 '23 15:01 sschuberth

Looks like it's related to using Wayland (as opposed to X11).

sschuberth avatar Jan 17 '23 16:01 sschuberth

I'm getting a different type of fatal error when running Compose Desktop on WSLg regardless of what I set -Dcompose.application.configure.swing.globals to. I'm trying to run the compose-multiplatform-template project from JetBrains out of the box on WSLg. The same works fine in an Ubuntu VM, just not WSLg for me. Were you able to get any type of resolution to this?

# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f5ab7f96e60, pid=21736, tid=21758
#
# JRE version: OpenJDK Runtime Environment Zulu17.44+53-CA (17.0.8.1+1) (build 17.0.8.1+1-LTS)
# Java VM: OpenJDK 64-Bit Server VM Zulu17.44+53-CA (17.0.8.1+1-LTS, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# C  [libstdc++.so.6+0x229e60]
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/adstotz/code/personal/compose-multiplatform-template/desktopApp/hs_err_pid21736.log
#
# If you would like to submit a bug report, please visit:
#   http://www.azul.com/support/
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

adstotz avatar Oct 11 '23 21:10 adstotz