RPTools / maptool

Virtual Tabletop for playing roleplaying games with remote players or face to face.
http://rptools.net
GNU Affero General Public License v3.0
802 stars 263 forks source link

[Bug]: MapTool locked up when entering HTML editor of token edit dialog in Mac of Japanese environment #3915

Open fw opened 1 year ago

fw commented 1 year ago

Describe the Bug

MapTool hung up when using the HTML WYSIWYG editor in the Notes and GM Notes of token edit dialog with Japanese input sources (and probably other CJK input sources too) on macOS.

To Reproduce

  1. Open System Preferences on macOS.
  2. Launch Keyboard contained the System Preferences.
  3. Choose Input Source tab within the Keyboard.
  4. Add Japanese language.
  5. Check the Show Input menu in the menu bar (probably, it is the default).
  6. Launch MapTool.
  7. Select Hiragana, Katakana or Romaji within input source in menubar at macOS. It can select when clicking the flag of U.S. in the menu bar.
  8. Drop any token on the map.
  9. Open the Token Edit dialog.
  10. Open the Notes or GM Notes tab.
  11. Choose "Text type" to "text/html"
  12. Change the beneath tab to "HTML".
  13. Click the edit area several times(probably up to ten times).
  14. MapTool hanged with getting the Spinning Wheel.

Expected Behaviour

I want to use the rich editor without my Mac locking up.

Screenshots

No response

MapTool Info

1.13.0-beta.1

Desktop

macOS 10.15 (Catalina)

Additional Context

Probably, the cause of this issue is the same as #2635.

kwvanderlinde commented 1 year ago

I haven't tried to reproduce this yet (I'd have to figure out my system's language support first) but I have noticed there are some concurrency issues in HtmlEditorSplitGui, particularly the constructor. Two parts to that:

  1. We use Platform.runLater() to initialize the JavaFX portions of the UI. But that logic is not guaranteed to complete by the time the constructor finishes, meaning it's possible for other methods to access uninitialized or partially initialized fields (in particular htmEditor). This probably wouldn't result in a hang, but could result in NPEs or something if the JFX initialization took unusually long for some reason.
  2. In the context of Platform.runLater(), we are calling jfxPanel.setScene(). That should happen on the Swing thread, not the JavaFX thread. This can cause hanging as some Swing components take locks meant only for the Swing thread.

We should go through that class and double-check that tasks complete when we expect, and that we respect thread confinement.