JavaFX possible bug

Hi, community and david_bernard_31! Thanx for supporting cool JFX project, but i have trouble while using it.


It happens when i just changing HBox panel. I mean i removing all children of panel and then adding new ones.
Better look code ithink:

FxPlatformExecutor.runOnFxApplication(() -> {
            for (Unit unit : battleManager.getUnits()) {
                if (unit.isAlive()) {
                    ImageView imageView = new ImageView(getClass().getResource("/png/" + unit.getImageName()).toExternalForm());
                    imageView.setEffect(new SepiaTone(0.9));

U can ignore unit and controller entities, it doesn’t matter at all. This code simply clear orderPanel(HBox), creating ImageView and add it into panel. Dat’s it! Sometimes it is going ok, but sometimes image views r just sit on top each other like if panel wasn’t Hbox. It is very strange bug. As i suspect it happens cause of i’m changing GUI dynamically and sometimes it happens not in JavaFX thread (even code wrapped in FxPlatformExecutor.runOnFxApplication). Am i right? Can anyone give me advice about how to solve this? Any help appreciated

if you do anything outside of javafx thread, it is simply false and anything might happen.
Anyway does the same bug also happen with plain jfx outside of jme?

Because the ui binding does not change the rendering logic at all, it just grabs a screenshot (simplified) converts to texture and displays in jme. All layouting logic is unchanged.

Hi, thx for reply. As i know JFX FxPlatformExecutor.runOnFxApplication() should guarantee than code inside it will execute in JavaFX thread. What u mean “plain jfx outside of jme”?
The problem appears periodically, not every use case, dat’s strange. I suspected MAYBE code executed not in JavaFX thread, but if we look inside library we will see

public static void runOnFxApplication(Runnable task) { if(Platform.isFxApplicationThread()) {; } else { Platform.runLater(task); } }

Empire_Phoenix, as i know u created a game using JavaFX, right? U probably used some dynamic gui content, do u? If u did, have u any thread issues like i have and how u solve them?

No I had so far no ui issues and I use tons of dynamic ui’s.

I suggest to just put a
if(! Platform.isFxApplicationThread()){
throw new RuntimeException(“details”);

basically everywhere, I usually found my bugs that way (if they were Thread related). The performance cost is negligible (alternativly use asserts).

I meant just create a javafx window and put the problematic part of the ui in it, and see if it makes problems there as well.

Thanx, i will use this method. As i understood u the code i’ve posted above looks buggy cause i can’t be sure it executing in right thread, right?

We use com.sun.javafx.application.PlatformImpl.runLater(Runnable r) from a normal AppState.update(float tpf) method to update dynamic content for Skylimit Tycoon, but we keep track of tpf so we only update 25 times per second.

Updating to often should not cause any problems, (except maybee performance)
Yes, I suspect a multithreading error, or alternativly you found a layout bug in javafx

Yeah, we only limit the update for performance. We’ve not noticed any thread issues.

Thank u, guys! I finally found bug in my code, when i forgot wrap code runLater. Now seems like all works just fine, need more tests. I even will try to omit tonegod now(unfort this cool library not supported since 2014 as i know) and do all stuff on JavaFX. If u r interested i can share results of this experiment later

1 Like

Yes share your result.

Ok, now i can post some results here.
Maybe just simpe image will be enough for the first time.

I know this image looks quite poorly(no real models, effects and stuff) but for now we just talking about possibility of using only JavaFX as GUI. And it looks like it is possible at this stage of my development. Hope this helps someone.

1 Like