Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3509 Members - Latest Member: lioneltenel

26. May 2012, 09:48:58 pm
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)A big, FAT, bug
Pages: [1] 2
Print
Author Topic: A big, FAT, bug  (Read 2912 times)
kukanani
Fierce Warrior
****
Offline Offline

Posts: 504


My game is coming along fairly smoothly...


View Profile WWW
« on: 26. April 2007, 02:45:46 am »

A very annoying bug with Canvas3dPanel.  The
Code:
registerKeyboard()
method does not accept a Canvas3dPanel, and it can't be cast to a Canvas3D.  Is there another way to add a key Listener?

Kukanani
Logged

xith.setCoolnessLevel(10);
jMe.setCoolnessLevel(0);
xith.rock();
kukanani
Fierce Warrior
****
Offline Offline

Posts: 504


My game is coming along fairly smoothly...


View Profile WWW
« Reply #1 on: 26. April 2007, 02:52:41 am »

By the way, when I tty this:

Code:
this.getInputManager().registerKeyboard(this.getInputManager().getKeyboard());

I get this:

Exception in thread "Thread-4" java.lang.NullPointerException
   at org.xith3d.utility.input.InputManagerImpl.update(InputManagerImpl.java:325)
   at org.xith3d.render.loop.RenderLoop.updateInputDevices(RenderLoop.java:527)
   at org.xith3d.render.loop.RenderLoop.loopIteration(RenderLoop.java:562)
   at exodus.game.threeD.worlds.zero.two.Exodus3dWorld.loopIteration(Exodus3dWorld.java:90)
   at org.xith3d.render.loop.RenderLoop.nextIteration(RenderLoop.java:792)
   at org.xith3d.render.loop.RenderLoop.run(RenderLoop.java:867)
   at java.lang.Thread.run(Unknown Source)


Huh Huh Huh
Logged

xith.setCoolnessLevel(10);
jMe.setCoolnessLevel(0);
xith.rock();
kukanani
Fierce Warrior
****
Offline Offline

Posts: 504


My game is coming along fairly smoothly...


View Profile WWW
« Reply #2 on: 26. April 2007, 02:54:06 am »

Also, this

Code:
        this.getInputManager().registerKeyboard(this.getInputManager().getKeyboards().get(0));

gives me this

Exception in thread "AWT-EventQueue-1" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
   at java.util.Vector.get(Unknown Source)
   at java.util.Collections$UnmodifiableList.get(Unknown Source)
   at exodus.game.threeD.worlds.zero.two.Exodus3dWorld.prepareHeiarchy(Exodus3dWorld.java:108)
   at exodus.game.threeD.worlds.zero.two.Exodus3dWorld.<init>(Exodus3dWorld.java:96)
   at exodus.game.games.zero.two.Exodus.world(Exodus.java:98)
   at exodus.game.games.zero.two.Exodus.initiateGUI(Exodus.java:80)
   at exodus.game.games.zero.two.Exodus.<init>(Exodus.java:48)
   at exodus.game.awt.zero.two.ExodusTitleScreen.logIn(ExodusTitleScreen.java:286)
   at exodus.game.awt.zero.two.ExodusTitleScreen$6.actionPerformed(ExodusTitleScreen.java:159)
   at exodus.awt.components.XawtButton.processMouseEvent(XawtButton.java:68)
   at java.awt.Component.processEvent(Unknown Source)
   at java.awt.Component.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Window.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.EventQueue.dispatchEvent(Unknown Source)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.run(Unknown Source)
Logged

xith.setCoolnessLevel(10);
jMe.setCoolnessLevel(0);
xith.rock();
kukanani
Fierce Warrior
****
Offline Offline

Posts: 504


My game is coming along fairly smoothly...


View Profile WWW
« Reply #3 on: 26. April 2007, 02:54:51 am »

It just hit me that the getKeyboard() method is showing up null because I haven't registered one.  Is this the case, or am I off track?
Logged

xith.setCoolnessLevel(10);
jMe.setCoolnessLevel(0);
xith.rock();
kukanani
Fierce Warrior
****
Offline Offline

Posts: 504


My game is coming along fairly smoothly...


View Profile WWW
« Reply #4 on: 26. April 2007, 02:58:26 am »

this might be it:

Code:
        this.getInputManager().registerKeyboard(
        this.getInputManager().registerKeyboard(canvas3d.getCanvas()));
Logged

xith.setCoolnessLevel(10);
jMe.setCoolnessLevel(0);
xith.rock();
kukanani
Fierce Warrior
****
Offline Offline

Posts: 504


My game is coming along fairly smoothly...


View Profile WWW
« Reply #5 on: 26. April 2007, 03:00:53 am »

Whoops, that doesn't make any sense. I meant this:

Code:
        this.getInputManager().registerKeyboard(canvas3d.getCanvas());
Logged

xith.setCoolnessLevel(10);
jMe.setCoolnessLevel(0);
xith.rock();
jeepndesert
Becoming dependent
**
Offline Offline

Posts: 103


jeep_in_desert@yahoo.com
View Profile WWW
« Reply #6 on: 26. April 2007, 04:57:59 am »

Make sure you've added the 3D peer to canvas and added the canvas to the view. Then, get the 3D peer from canvas and the awt component (I think the component is created when you create the 3d peer) to add the input listener. This is how I add a plain awt key listener.

Code:
canvas.get3DPeer().getComponent().addKeyListener(localInputListener);

Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #7 on: 26. April 2007, 08:06:06 am »

A very annoying bug with Canvas3dPanel.  The
Code:
registerKeyboard()
method does not accept a Canvas3dPanel, and it can't be cast to a Canvas3D.  Is there another way to add a key Listener?

As you already discovered, there's a getCanvas() method, that returns the Canvas3D. Of course it can't be casted to Canvas3D, since it extends Panel. Canvas3DPanel and Canvas3DJPanel both implement the Canvas3DWrapper interface, which has the getCanvas() method. I guess you're still using an older release. In the current release (for quite a while) there are the registerKeyboard/registerMouse methods overloaded to also take a Canvas3DWrapper (Canvas3DPanel/Canvas3DJPanel). So there should not be a problem.

And I can't understand, why this should be a "big FAT bug". It's not bigger or fatter than others. This is not even a minor bug, but misusage. And please always check, if a bug is fixed in the most recent version.

By the way, when I tty this:

Code:
this.getInputManager().registerKeyboard(this.getInputManager().getKeyboard());

I get this:

Exception in thread "Thread-4" java.lang.NullPointerException
   at org.xith3d.utility.input.InputManagerImpl.update(InputManagerImpl.java:325)
   at org.xith3d.render.loop.RenderLoop.updateInputDevices(RenderLoop.java:527)
   at org.xith3d.render.loop.RenderLoop.loopIteration(RenderLoop.java:562)
   at exodus.game.threeD.worlds.zero.two.Exodus3dWorld.loopIteration(Exodus3dWorld.java:90)
   at org.xith3d.render.loop.RenderLoop.nextIteration(RenderLoop.java:792)
   at org.xith3d.render.loop.RenderLoop.run(RenderLoop.java:867)
   at java.lang.Thread.run(Unknown Source)


Huh Huh Huh

Of course you get this. Why is this astonishing? If you haven't registered a Keyboard, this method of course returns null. The JavaDoc even tells this. And registering a null Keyboard throws an NPE. That's it.

Also, this

Code:
        this.getInputManager().registerKeyboard(this.getInputManager().getKeyboards().get(0));

gives me this

Exception in thread "AWT-EventQueue-1" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
   at java.util.Vector.get(Unknown Source)
   at java.util.Collections$UnmodifiableList.get(Unknown Source)
   at exodus.game.threeD.worlds.zero.two.Exodus3dWorld.prepareHeiarchy(Exodus3dWorld.java:108)
   at exodus.game.threeD.worlds.zero.two.Exodus3dWorld.<init>(Exodus3dWorld.java:96)
   at exodus.game.games.zero.two.Exodus.world(Exodus.java:98)
   at exodus.game.games.zero.two.Exodus.initiateGUI(Exodus.java:80)
   at exodus.game.games.zero.two.Exodus.<init>(Exodus.java:48)
   at exodus.game.awt.zero.two.ExodusTitleScreen.logIn(ExodusTitleScreen.java:286)
   at exodus.game.awt.zero.two.ExodusTitleScreen$6.actionPerformed(ExodusTitleScreen.java:159)
   at exodus.awt.components.XawtButton.processMouseEvent(XawtButton.java:68)
   at java.awt.Component.processEvent(Unknown Source)
   at java.awt.Component.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Window.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.EventQueue.dispatchEvent(Unknown Source)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.run(Unknown Source)


Yes, of course.

It just hit me that the getKeyboard() method is showing up null because I haven't registered one.  Is this the case, or am I off track?

You might be off track Wink.

this might be it:

Code:
        this.getInputManager().registerKeyboard(
        this.getInputManager().registerKeyboard(canvas3d.getCanvas()));

Whoops, that doesn't make any sense. I meant this:

Code:
        this.getInputManager().registerKeyboard(canvas3d.getCanvas());

Exactly. Even if you're able to directly add instances of Canvas3DWrapper (Canvas3DPanel/Canvas3DJPanel) to these methods in the current version.

I've added more declarative NPEs to the registerKeyboard() and registerMouse() methods, so that people can directly read the cause of the Exception.

Make sure you've added the 3D peer to canvas and added the canvas to the view. Then, get the 3D peer from canvas and the awt component (I think the component is created when you create the 3d peer) to add the input listener. This is how I add a plain awt key listener.

Code:
canvas.get3DPeer().getComponent().addKeyListener(localInputListener);

This is not necessary. You never have to handle the CanvasPeer creation on your own. This is the way it was handled in the ancient xith times Wink. Nowadays you just invoke one of the create*() methods of Canvas3DFactory and you will get a fully initialized Canvas3D, which of course includes a fully initialized CanvasPeer. The same for Canvas3DPanel/Canvas3DJPanel. They both only need to be instatiated and they are fully set up.

I hope, this clears everything up a bit.

Marvin
Logged
kukanani
Fierce Warrior
****
Offline Offline

Posts: 504


My game is coming along fairly smoothly...


View Profile WWW
« Reply #8 on: 26. April 2007, 01:51:09 pm »

Quote
And I can't understand, why this should be a "big FAT bug". It's not bigger or fatter than others. This is not even a minor bug, but misusage. And please always check, if a bug is fixed in the most recent version.

Got it.  Wink  It was just over-exaggeration.
Logged

xith.setCoolnessLevel(10);
jMe.setCoolnessLevel(0);
xith.rock();
'n ddrylliog
Guru
*****
Offline Offline

Posts: 1188



View Profile WWW Email
« Reply #9 on: 26. April 2007, 03:07:53 pm »

Got it.  Wink  It was just over-exaggeration.
Wow, a double-pleonasm Smiley
Logged
kukanani
Fierce Warrior
****
Offline Offline

Posts: 504


My game is coming along fairly smoothly...


View Profile WWW
« Reply #10 on: 26. April 2007, 05:30:25 pm »

this:

Code:
this.getInputManager().registerKeyboard(canvas3d.getCanvas());

actually appears to do nothing.  I also have this code:

Code:
protected void onKeyReleased(int key) {
switch(key) {
case KeyCode.VK_UP:
direction = FORWARD;
System.out.println("Key Pressed");  //for debugging purposes
break;
}
}

is this correct?  The phrase "Key Pressed" never gets printed to output.  Huh
Logged

xith.setCoolnessLevel(10);
jMe.setCoolnessLevel(0);
xith.rock();
'n ddrylliog
Guru
*****
Offline Offline

Posts: 1188



View Profile WWW Email
« Reply #11 on: 27. April 2007, 03:30:59 pm »

actually, your class has to implement InputAdapterRenderLoop (if it's in the context I suppose it is) *OR* it should implement KeyboardListener and be added with this.getInputManager().getKeyboard().registerListener(this OR keyboardListener)
Logged
kukanani
Fierce Warrior
****
Offline Offline

Posts: 504


My game is coming along fairly smoothly...


View Profile WWW
« Reply #12 on: 27. April 2007, 08:42:00 pm »

I'm pretty sure this is right:

Code:
//class declaration
public class myClass extends RenderLoop implements KeyboardListener {

//blah blah blah...
        this.getInputManager().registerKeyboard(canvas3d.getCanvas());
        this.getInputManager().getKeyboard().registerListener(this);
//blah blah blah...
public void onKeyReleased(int key) {
direction = FORWARD;
System.out.println("Key Released");  //for debugging purposes
}

public void onKeyTyped(char keyChar) {
direction = FORWARD;
System.out.println("Typed");  //for debugging purposes
}

public void onKeyPressed(int key) {
direction = FORWARD;
System.out.println("Key Pressed");  //for debugging purposes
}


again, none of the words are ever sent to output.  Do I need to request focus or something?
Logged

xith.setCoolnessLevel(10);
jMe.setCoolnessLevel(0);
xith.rock();
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #13 on: 27. April 2007, 08:55:29 pm »

Do I need to request focus or something?

No should not be necessary. Please try this:

Code:
public class MyClass extends InputAdapterRenderLoop
{
    // blah, blah, blah...
   
    public void onKeyPressed(int key)
    {
        System.out.println( "Key Pressed: " + key );
    }
   
    public void onKeyReleased(int key)
    {
        System.out.println( "Key Released: " + key );
    }
   
    public void onKeyTyped(char ch)
    {
        System.out.println( "Key Typed: " + ch );
    }
   
    public MyClass()
    {
        super( 128f );
       
        // ...
       
        // please use this method!
        this.getInputManager().registerKeyboardAndMouse( myCanvasPanel );
    }
}

There's a small difference, if you use the registerKeyboardAndMouse() method, which takes a Canvas3DWrapper instance (your CanvasPanel in your case) instead of myCanvasPenel.getCanvas(), since it registers a component bound listener instead of a Toolkit bound one, which is certainly what you want, if you use CanvasPanel.

Even if you don't seem to want to use InputAdapterRenderLoop, we can check, if this works for you. The only reason not to use InputAdapterRenderLoop, but RenderLoop is, that you want to listen for input events from another class.

If the above example works, we can still see, if we can get it to work without IARL on your system.

Marvin
Logged
kukanani
Fierce Warrior
****
Offline Offline

Posts: 504


My game is coming along fairly smoothly...


View Profile WWW
« Reply #14 on: 27. April 2007, 09:24:24 pm »

Ok, I admit.  All this time I have completely fooled myself into thinking I had SVN versions installed.  Well, I didn't.  Now that I've finally gotten this through my head, I get this Eclipse error:

The project was not built since its build path is incomplete. Cannot find the class file for org.xith3d.scenegraph.Light. Fix the build path then try building this project.


I can't continue to test programs (or code at all, for that matter) until this is sorted out.
Logged

xith.setCoolnessLevel(10);
jMe.setCoolnessLevel(0);
xith.rock();
Pages: [1] 2
Print
Jump to:  

Theme orange-lt created by panic