Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  A bug in the 1.4.1_01 server vm!  (Read 4277 times)
0 Members and 1 Guest are viewing this topic.
Offline princec

« JGO Spiffy Duke »


Medals: 434
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Posted 2002-12-05 12:45:26 »

Hurrah! I've always wanted to find one of these.

The following:

1  
2  
3  
4  
5  
            int buttonFlags = (Mouse.isButtonDown(0) ? 1 : 0) |
                  (Mouse.isButtonDown(1) ? 2 : 0) |
                  (Mouse.isButtonDown(2) ? 4 : 0);
           
            assert buttonFlags >= 0;


produces an assertion error in the server VM (1.4.1_01, Win32, WinXP). The client VM is unaffected. Naughty naughty, as it is indeed impossible for that assertion to be thrown.

So, back to using the client VM then...

Cas Smiley

Offline Seb

Senior Newbie




import com.acme.Bomb;


« Reply #1 - Posted 2002-12-05 16:30:42 »

By the way, what is the actual value buttonFlags has in each VM?

In other words? is this an assertion bug? or something really funny in the the way the server VM handles bit ORing.

Seb

Offline cfmdobbie

Senior Devvie


Medals: 1


Who, me?


« Reply #2 - Posted 2002-12-05 16:31:23 »

Cool, what's the value of buttonFlags when the assert fails?

Hellomynameis Charlie Dobbie.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Seb

Senior Newbie




import com.acme.Bomb;


« Reply #3 - Posted 2002-12-05 16:42:46 »

Never mind, I just read your diary  Grin

Seb

Offline princec

« JGO Spiffy Duke »


Medals: 434
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #4 - Posted 2002-12-05 16:45:37 »

Something like -126 or -128. Most bizarre. Of course, when I try to chop it out and make a test case it won't happen, but it happens without fail when I run the game. Ah well.

Cas Smiley

Offline Herkules

Senior Devvie




Friendly fire isn't friendly!


« Reply #5 - Posted 2002-12-06 05:38:34 »

In this case it looks more like the bug is somewhere else and appears just there by accident? Is it with LWJGL? Well, there's plenty of native code in it.....

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline cfmdobbie

Senior Devvie


Medals: 1


Who, me?


« Reply #6 - Posted 2002-12-06 09:08:52 »

Naaa, if you follow through the code path, the result should be in the range 0-7.  The method that's executing to provide the boolean test has no direct effect on the value of buttonFlags.  If that line of code comes out with a value outside the range 0-7, there's something decidedly fishy going on.

Hellomynameis Charlie Dobbie.
Offline princec

« JGO Spiffy Duke »


Medals: 434
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #7 - Posted 2002-12-06 11:01:21 »

It's definitely Hotspot. I had suspected the stack corruption was my fault somehow in the native libs but it doesn't occur in client and doesn't occur in server for quite some time. In fact, it takes about as much time as server does to think about doing a compile. And besides, a stack corruption is always followed by a crash, and this doesn't crash, it just has a bizarre value in it at the end.

Cas Smiley

Offline elias

Senior Devvie





« Reply #8 - Posted 2002-12-12 16:51:26 »

No, it's still the lwjgl lib's fault!

At least that's what I found out after running into a similar problem, namely the test

if (Mouse.isButtonDown(i) == buttons)

Sometimes (only on the win32 build of lwjgl) the Mouse.isButtonDown(i) and buttons would both be true when I printed them, but the test actually failed!

To understand why, you have to look at the code that polls the mouse under win32:

               jbooleanArray buttonsArray = (jbooleanArray) env->GetStaticObjectField(clazz, fid_button);
               BYTE * buttons = (BYTE *) env->GetPrimitiveArrayCritical(buttonsArray, NULL);
               memcpy(buttons, diMouseState.rgbButtons, 4);
               env->ReleasePrimitiveArrayCritical(buttonsArray, buttons, 0);

Other than the fact that I think SetBooleanArrayRegion() should be used instead of GetPrimitiveArrayCritical/ReleasePrimitiveArrayCritical, there's a problem with that code. diMouseState.rgbButtons contains the mouse button states as returned by DirectInput in an array of BYTEs, which corresponds to the jboolean datatype the java button array buttons contains. The problem is that directinput does not always return JNI_TRUE or JNI_FALSE, the only two values allowed to be in a jboolean data type! This is what makes the assumptions made by the VMs invalid (an == test between two jbooleans could fail in this case).

I fixed this in lwjgl CVS by setting the button array entries to JNI_TRUE if DirectInput returned something != 0, and JNI_FALSE otherwise. This makes the test first mentioned always do the right thing.

- elias

Offline princec

« JGO Spiffy Duke »


Medals: 434
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #9 - Posted 2002-12-12 17:00:08 »

Heh Smiley It may be us that causes it but there seems to be a bit of a grey area in the spec doesn't there? It works fine under the client VM, but it looks like the server VM relies on a more accurate representation of JNI_TRUE Smiley

Interesting that this technically means we could compare a Java boolean value and have it both != false and != true Smiley

Thanks for spotting it.

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline elias

Senior Devvie





« Reply #10 - Posted 2002-12-12 17:17:23 »

You're right - I can't find that jbooleans have to be JNI_TRUE or JNI_FALSE either. But it's clearly what the JNI API expects :-)

- elias

Offline Herkules

Senior Devvie




Friendly fire isn't friendly!


« Reply #11 - Posted 2002-12-13 08:18:53 »

Grin

How could I know it was the native code....?



HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline Herkules

Senior Devvie




Friendly fire isn't friendly!


« Reply #12 - Posted 2002-12-13 08:25:09 »

BTW, did you ever try -Xcheck:jni ??

For JXInput, this fails for some reason I never could find out.....

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline elias

Senior Devvie





« Reply #13 - Posted 2002-12-13 11:57:46 »

-Xcheck:jni - never used it but I've heard of it before

...

And yes, it complains about lwjgl too, I'll look into that.

- elias

Offline elias

Senior Devvie





« Reply #14 - Posted 2002-12-13 15:52:05 »

Hmm the -Xcheck:jni option makes a call to Mouse.poll puke with:

FATAL ERROR in native method: Field type (static) mismatch in JNI get/set field operations
       at org.lwjgl.input.Mouse.nPoll(Native Method)
       at org.lwjgl.input.Mouse.poll(Mouse.java:148)

Coming from a call in nPoll like this:
       jbooleanArray buttonsArray = (jbooleanArray) env->GetStaticObjectField(clazz, fid_button);

I can't really understand this. The fid_button id is fetched correctly with

fid_button = env->GetStaticFieldID(clazz, "button", "[Z");

And as there's is no GetStaticArrayField, GetStaticObjectField seems like the correct way to get an array field, like String objects are fetched.

Someone?

- elias

Offline Herkules

Senior Devvie




Friendly fire isn't friendly!


« Reply #15 - Posted 2002-12-13 15:52:07 »

That's what it complains about for me:


1  
2  
3  
FATAL ERROR in native method: Field type (static) mismatch in JNI get/set field operations
   at de.hardcode.jxinput.directinput.DirectInputDriver.nativeupdate(Native
 Method)

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (35 views)
2014-12-15 09:26:44

Mr.CodeIt (26 views)
2014-12-14 19:50:38

BurntPizza (56 views)
2014-12-09 22:41:13

BurntPizza (90 views)
2014-12-08 04:46:31

JscottyBieshaar (51 views)
2014-12-05 12:39:02

SHC (67 views)
2014-12-03 16:27:13

CopyableCougar4 (69 views)
2014-11-29 21:32:03

toopeicgaming1999 (129 views)
2014-11-26 15:22:04

toopeicgaming1999 (120 views)
2014-11-26 15:20:36

toopeicgaming1999 (34 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!