TysonMay / monoxna

Automatically exported from code.google.com/p/monoxna
0 stars 0 forks source link

KeyboarState & PreviousKeyboardState problem #62

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hello!

I am reporting bug concerned with keyboard.
It fails if you try to run xna game that uses current and previous keyboard
state. Here is example:

KeyboardState previousKeyboardState, currentKeyboardState;
...
currentKeyboardState = Keyboard.GetState ();
previousKeyboardState.IsKeyDown (Keys.Space) & currentKeyboardState.IsKeyUp
(Keys.Space)
previousKeyboardState = Keyboard.GetState ();

is shows error:
Unhandled Exception: System.NullReferenceException: Object reference not
set to an instance of an object
  at monoXnaTest.Game1.Update (Microsoft.Xna.Framework.GameTime gameTime)
[0x000ae] in /home/gasper/Projects/monoXnaTest/monoXnaTest/Game1.cs:150 
  at Microsoft.Xna.Framework.Game.Tick () [0x00000] 
  at Microsoft.Xna.Framework.SdlGameHost.Run () [0x00000] 
  at Microsoft.Xna.Framework.Game.Run () [0x00000] 
  at monoXnaTest.Program.Main (System.String[] args) [0x00006] in
/home/gasper/Projects/monoXnaTest/monoXnaTest/Program.cs:14 
The application was terminated by a signal: SIGHUP

BTW: normal usage of keyboard works!

Original issue reported on code.google.com by gse...@gmail.com on 4 May 2010 at 5:10

GoogleCodeExporter commented 8 years ago
I think the problem is with your code. The previous keyboard state hasn't been 
set
the first time you query it (second line in your code). You should write an if 
test
for this special case.

As a side note: I think it is better to change the last statement to:
previousKeyboardState = currentKeyboardState;

Original comment by lav...@gmail.com on 4 May 2010 at 5:23

GoogleCodeExporter commented 8 years ago
sorry, I didn't copy exact code, it's typo. 
Code is like you did :)
but problem is here:
-------------
previousKeyboardState.IsKeyDown (Keys.Space) & currentKeyboardState.IsKeyUp
(Keys.Space)
-------------

can you try? just compare current and previous
I think I can make test

Original comment by gse...@gmail.com on 4 May 2010 at 5:31

GoogleCodeExporter commented 8 years ago
Attach the entire source and I'll test it.

Original comment by lav...@gmail.com on 4 May 2010 at 5:33

GoogleCodeExporter commented 8 years ago
It's commented now.

just uncomment following lines:

int krneki;

if (prejsnjeStanjeTipkovnice.IsKeyDown (Keys.I) & stanjeTipkovnice.IsKeyUp 
(Keys.I))

    krneki = 0;

Original comment by gse...@gmail.com on 4 May 2010 at 5:58

Attachments:

GoogleCodeExporter commented 8 years ago
The problem is what I mentioned in my first comment. You need to write an if 
that
handles the first update (when prejsnjeStanjeTipkovnice is null)

Original comment by lav...@gmail.com on 4 May 2010 at 6:13

GoogleCodeExporter commented 8 years ago

Original comment by lav...@gmail.com on 4 May 2010 at 6:24

GoogleCodeExporter commented 8 years ago
I totaly forgot that.

MSXNA can handle this excpetion. I think it ignores it.

Original comment by gse...@gmail.com on 4 May 2010 at 7:04