I’ve recently started using jME, I think its great! I’ve had a bit of trouble along the way, taking forever for me to find out what’s wrong (mostly my part )
I’ve been having a bit of trouble with NiftyGUI buttons. I’ll give you a bit of context to the problem:
In my game (Blocksmith) after an amount of loading and logging in, you come to the main menu. After clicking on Single Player (button works fine) it switches to (through the pipeline calling nifty.gotoScreen(“sp-main-hud”). It also hides the mouse:
So far it works fine. The problem comes when I press Escape to bring down the Escape Menu. After it slides down and the mouse reappears, if the mouse happens to reappear over a button, simply moving the mouse activates the button. This can have disastrous effects: it appears over the Main Menu option, it navigates to the Main Menu, it also happens to be sitting on the Single Player button again, and now you’re back in Single Player! (Note that was an older version - the buttons don’t line up so well now)
If you manage to move the mouse off that button before the Escape Menu finishes sliding in, then all is well. The problem now is that you have to click TWICE on a button to get it to activate.
I’ve got an amount of code to deal with the NiftyGUI (a NiftyHelper class), and most of the time I’ve got it setup to reset the focus of the current screen when it loads. Also an amount of code is sitting there with the focus reset in an effort to reset any mouse things:
// To reset focus:
// These two don’t seem to do anything/help at all
All of my Nifty work (I think) is being done in the LWJGL thread - the update thread, mostly by means of app.enqueue(…). I have a system of executors as well to run things in the background.
I think I’ve got a bit more work to do (reducing it to the minimum codebase for failure) but I’d appreciate anyone pointing out me overlooking things or any obvious issues.
PS I can post more code if necessary!
I can’t tell from your description what might be wrong. Can you supply a testcase? But please make sure to create a http://sscce.org/
Thanks for response!
I’ve made a screencapture video of the bug, apologies for the quality and the background noise. Please note that the two things can be done in any order, not just as the video demonstrates.
I’m just starting the testcase now. Start from a new BasicGame or whatever the default jME project is? And how would you like it delivered? I can upload a zip of the project to a website of mine if you want.
Ok I’ve gone and written a simple testcase for the bug. (Was a lot quicker and simpler to reproduce than I expected)
Download zip of Project (297.06 KB)
Download self-standing jar file (6.9 MB)
To run once booted up (load into jME SDK):
- Click start
- - It will switch to HUD mode
- Press Home (without moving mouse at all)
- -It will return to the home screen
- Move the mouse
- -The button will activate (onClick event) and you'll return to the HUD
- Press Home again - this time, wildly move the mouse and continue pressing Home until you reach the MainMenu with the mouse off the button
- Now try clicking on the button
- -It shouldn't do anything
- Click it again and you should arrive in the HUD
- Press Escape to exit
While coding the testcase, I decided to print a Stack Trace from the button handling code in the ScreenController. The very first click results in: (trimmed to highlight difference)
java.lang.Exception: printStackTrace Method
The mouse-move 'click' results in this: (trimmed to match)
java.lang.Exception: printStackTrace Method
Notice the MouseMotionEvent as opposed to the MouseButtonEvent in the second trace.
I've written both my game and the testcase on Linux, but they both still fail on Windows.
Hope that's enough.
Thank you for your excellent testcase!
I can reproduce your issue now but I’m unable to fix it since it seems to be a problem in the InputSystemJme class (the Nifty integration into jme3). However I’ve created Issue 520 on the jme3 bug tracker and described the problem in detail there.
Someone with a better understanding needs to add some kind of reset to the InputSystemJme class I think when the mouse cursor is hidden (or when it is shown again).
Thanks for the issue report, we’ll take a look …
Thank for that.
This seems such a strange bug (and also relatively easy to reproduce) that I can’t think how someone hasn’t noticed this before… maybe it was a recently introduced bug?
Anyway thanks for getting this in the issue tracker. I don’t know heaps about the system internally, but I’d be happy to help get this fixed.
I’ve downloaded the source for jME, put the code in one directory structure using a bash script (so I don’t have to look in each unit of jME) and plugged it into the Library → JMonkeyEngine libraries → Source files. So I can browse most of source code. Other parts that are bundled into jars I decompiled and stuffed in there too.
If I’m of any help I’d appreciate any pointers on how to edit jME source. (Just load it up in Netbeans?)
I guess there just aren’t many people turning the mouse off while buttons are pressed down and then on again (since that’s what causes the problem). I’ve seen a few reports of what is possibly this issue on this forum but from what I saw everyone disappeared when asked for a test case.
It would appear that the bug has been fixed:
http://code.google.com/p/jmonkeyengine/issues/detail?id=520 - Issue description
http://code.google.com/p/jmonkeyengine/source/detail?r=9614 - Bug fix 1
http://code.google.com/p/jmonkeyengine/source/detail?r=9615 - Bug fix 2
But I haven’t tested yet… sometime I should run it against the test case.
Does anyone know when the jME stable will be released? Or is that undeterminate?
Just updated to the nightly and I think it is fixed.