HumbleUI / JWM

Cross-platform window management and OS integration library for Java
Apache License 2.0
571 stars 46 forks source link

X11: AppX11::getScale code could fail #218

Closed tonsky closed 10 months ago

tonsky commented 2 years ago

Experienced on:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f7255da2ad1, pid=944795, tid=944796
#
# JRE version: OpenJDK Runtime Environment (14.0.2+12) (build 14.0.2+12-Debian-2)
# Java VM: OpenJDK 64-Bit Server VM (14.0.2+12-Debian-2, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# C  [libc.so.6+0x15fad1]
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# If you would like to submit a bug report, please visit:
#   https://bugs.debian.org/openjdk-14
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

---------------  S U M M A R Y ------------

Command Line: clojure.main -m user --interactive

Host: AMD Ryzen 5 2600 Six-Core Processor, 12 cores, 15G, Debian GNU/Linux 11 (bullseye)
Time: Fri Mar  4 12:58:41 2022 CET elapsed time: 2 seconds (0d 0h 0m 2s)

---------------  T H R E A D  ---------------

Current thread (0x00007f7250017000):  JavaThread "main" [_thread_in_native, id=944796, stack(0x00007f7254571000,0x00007f7254672000)]

Stack: [0x00007f7254571000,0x00007f7254672000],  sp=0x00007f7254669948,  free space=994k
Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [libc.so.6+0x15fad1]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  io.github.humbleui.jwm.App._nGetScreens()[Lio/github/humbleui/jwm/Screen;+0
j  io.github.humbleui.jwm.App.getScreens()[Lio/github/humbleui/jwm/Screen;+20
j  io.github.humbleui.core$screens.invokeStatic()Ljava/lang/Object;+15
j  io.github.humbleui.core$screens.invoke()Ljava/lang/Object;+0
j  user$make_window.invokeStatic()Ljava/lang/Object;+18
j  user$make_window.invoke()Ljava/lang/Object;+0
j  user$_main$fn__3555.invoke()Ljava/lang/Object;+24
j  clojure.lang.AFn.run()V+1
j  io.github.humbleui.jwm.App.lambda$start$0(Ljava/lang/Runnable;)V+39
j  io.github.humbleui.jwm.App$$Lambda$28.run()V+4
v  ~StubRoutines::call_stub
j  io.github.humbleui.jwm.App._nStart(Ljava/lang/Runnable;)V+0
j  io.github.humbleui.jwm.App.start(Ljava/lang/Runnable;)V+9
j  io.github.humbleui.core$start.invokeStatic(Ljava/lang/Object;)Ljava/lang/Object;+6
j  io.github.humbleui.core$start.invoke(Ljava/lang/Object;)Ljava/lang/Object;+3
j  user$_main.invokeStatic(Lclojure/lang/ISeq;)Ljava/lang/Object;+41
j  user$_main.doInvoke(Ljava/lang/Object;)Ljava/lang/Object;+6
J 1088 c1 clojure.lang.RestFn.applyTo(Lclojure/lang/ISeq;)Ljava/lang/Object; (3076 bytes) @ 0x00007f723871e4d4 [0x00007f72387081e0+0x00000000000162f4]
j  clojure.lang.Var.applyTo(Lclojure/lang/ISeq;)Ljava/lang/Object;+5
J 1355 c1 clojure.core$apply.invokeStatic(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; (21 bytes) @ 0x00007f72387e96e4 [0x00007f72387e9360+0x0000000000000384]
j  clojure.main$main_opt.invokeStatic(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+412
j  clojure.main$main_opt.invoke(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+6
j  clojure.main$main.invokeStatic(Lclojure/lang/ISeq;)Ljava/lang/Object;+376
j  clojure.main$main.doInvoke(Ljava/lang/Object;)Ljava/lang/Object;+6
J 1088 c1 clojure.lang.RestFn.applyTo(Lclojure/lang/ISeq;)Ljava/lang/Object; (3076 bytes) @ 0x00007f723871e4d4 [0x00007f72387081e0+0x00000000000162f4]
j  clojure.lang.Var.applyTo(Lclojure/lang/ISeq;)Ljava/lang/Object;+5
j  clojure.main.main([Ljava/lang/String;)V+20
v  ~StubRoutines::call_stub
TheDrawingCoder-Gamer commented 10 months ago

This isn't actually AppX11::getScale's fault. It's the fault of getScreen checking the bounding box, which apparently causes a crash.

Another stack trace, from a different library utilizing JWM

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007ff4600bcf97, pid=17104, tid=17128
#
# JRE version: OpenJDK Runtime Environment (11.0.21+9) (build 11.0.21+9)
# Java VM: OpenJDK 64-Bit Server VM (11.0.21+9, mixed mode, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# C  [libjwm_x64.so+0x1bf97]  jwm::WindowX11::getContentPosition(int&, int&)+0x27
#
# 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/bulby/Documents/GitHub/ModestUI/sample/core.17104)
#
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

---------------  S U M M A R Y ------------

Command Line: Main

Host: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz, 8 cores, 7G, EndeavourOS Linux
Time: Mon Nov 27 17:22:43 2023 EST elapsed time: 148.441363 seconds (0d 0h 2m 28s)

---------------  T H R E A D  ---------------

Current thread (0x00007ff478761000):  JavaThread "io-compute-3" daemon [_thread_in_native, id=17128, stack(0x00007ff44a5ff000,0x00007ff44a6ff000)]

Stack: [0x00007ff44a5ff000,0x00007ff44a6ff000],  sp=0x00007ff44a6fc2a0,  free space=1012k
Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [libjwm_x64.so+0x1bf97]  jwm::WindowX11::getContentPosition(int&, int&)+0x27

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J 1851  io.github.humbleui.jwm.WindowX11._nGetScreen()Lio/github/humbleui/jwm/Screen; (0 bytes) @ 0x00007ff46819e5f8 [0x00007ff46819e5c0+0x0000000000000038]
J 1766 c1 io.github.humbleui.jwm.WindowX11.getScreen()Lio/github/humbleui/jwm/Screen; (25 bytes) @ 0x00007ff460ecd454 [0x00007ff460ecd3c0+0x0000000000000094]
J 1811 c2 cats.effect.IOFiber.runLoop(Lcats/effect/IO;II)V (4067 bytes) @ 0x00007ff468182dbc [0x00007ff4681812a0+0x0000000000001b1c]
J 1699 c1 cats.effect.IOFiber.execR()V (96 bytes) @ 0x00007ff460ea302c [0x00007ff460ea2b40+0x00000000000004ec]
J 1624 c1 cats.effect.IOFiber.run()V (113 bytes) @ 0x00007ff460e85f1c [0x00007ff460e85880+0x000000000000069c]
v  ~StubRoutines::call_stub
j  io.github.humbleui.jwm.App._nStart(Ljava/lang/Runnable;)V+0
j  io.github.humbleui.jwm.App.start(Ljava/lang/Runnable;)V+17
j  gay.menkissing.modestui.App$.start$$anonfun$1$$anonfun$1(Lcats/effect/kernel/Resource;Lcats/effect/kernel/Async;Lcats/effect/std/Dispatcher;)V+9
j  gay.menkissing.modestui.App$.$anonfun$adapted$1(Lcats/effect/kernel/Resource;Lcats/effect/kernel/Async;Lcats/effect/std/Dispatcher;)Ljava/lang/Object;+4
j  gay.menkissing.modestui.App$$$Lambda$252.apply()Ljava/lang/Object;+16
j  cats.effect.IOFiber.runLoop(Lcats/effect/IO;II)V+1344
j  cats.effect.IOFiber.execR()V+92
j  cats.effect.IOFiber.run()V+61
j  cats.effect.unsafe.WorkerThread.run()V+1385
v  ~StubRoutines::call_stub
tonsky commented 10 months ago

Thanks! Any ideas how to fix?

TheDrawingCoder-Gamer commented 10 months ago

I think X11 has a "XGetWindowAttributes" that returns a struct containing a back pointer to the screen. Docs: https://www.x.org/releases/X11R7.7/doc/man/man3/XGetWindowAttributes.3.xhtml

TheDrawingCoder-Gamer commented 10 months ago

This function also returns the root window, so I think translate coords can still work