Jump to content
  • Advertisement
Sign in to follow this  
bornander

Weird SonyEricsson J2ME matrix behaviour

This topic is 5456 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, In my j2me game (mipd1.0) I'm writing a single integer to an array of integers declared as: public static int MATRIX_WIDTH = 8; public static int MATRIX_HEIGHT = 16; private int[][] data = new int[ MATRIX_HEIGHT ][ MATRIX_WIDTH ]; The method used for writing looks like this: public void writeData(int x, int y, int dataToWrite) { if ( x < 0 || x >= MATRIX_WIDTH ) return; if ( y < 0 || y >= MATRIX_HEIGHT ) return; data[ y ][ x ] = dataToWrite; } The weirdness is that sometimes more than just one value gets written to the array data. When debugging I checked how many values in the array there was that were greater than 0 and got (for example) 18, after the call to this method the same calculation return 29 instead of the expected 19. The behaviour exists on my Z600 as well as in the emulator. regards, /bornander

Share this post


Link to post
Share on other sites
Advertisement
Don't see anything wrong with that code there.. maybe it's the code that's calling it which is causing problems? Maybe you're calling it with writeData(y, x, ...) instead of writeDate(x,y,...) ?

Also, I would recommend removing these two lines:
if ( x < 0 || x >= MATRIX_WIDTH )
return;
if ( y < 0 || y >= MATRIX_HEIGHT )
return;

I don't know exactly how your program works, but most likely the code should not be trying to write to indices that are out of bounds. And if it IS trying to do that, then you *want* it to throw an error, so you can find out about it and fix it. So if you remove those two lines, you'll start getting very helpful ArrayIndexOutOfBounds exceptions if that's what's happening.

Share this post


Link to post
Share on other sites
Ontop of removing the if statements i would also remove the function all together and just have

data[ y ][ x ] = dataToWrite;

inserted straight into your code. Remember you are working on small devices with limited memory and file size.

Other than that your code looks fine and should work. Maybe if you posted more of what you are trying to do.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!