Jump to content
Excelsior Forums
Sign in to follow this  
deiruch

Yet another NullPointerException

Recommended Posts

Hi,

it's me again. I have another crash report... This time it's a NullPointerException in the method getHeightDiff(). Code is as follows:

 public Piece calcBestPos(Piece _currentPiece,Piece _nextPiece,int[][] _field)
 {
   [...]
   int[][] futureField2=new int[Constants.FIELD_WIDTH][Constants.FIELD_HEIGHT];

   [...]
   insertPiece(futureField,_nextPiece,futureField2);
   double curScore=rateBoard(futureField,futureField2);
   [...]
 }

 double rateBoard(int[][] _futureField1,int[][] _field2)
 {
   [...]
   double maxHeight=getMaxHeight(_field2);
   double heightDiff=getHeightDiff(_field2);
   [...]
 }

 private double getMaxHeight(int[][] _field)
 {
   int minY=_field[0].length;
   for(int x=0;x<_field.length;x++)
     for(int y=0;y<minY;y++)
       if(_field[x][y]!=CField.C_EMPTY)
       {
         minY=y;
         break;
       }

   return (_field[0].length-minY)/(double)_field[0].length;
 }

 private double getHeightDiff(int[][] _field)
 {
   double yDiff=0;
   int yOld=_field[0].length;
   for(int y=_field[0].length-1;y>=0;y--)
     if(_field[0][y]!=CField.C_EMPTY)
       yOld=y;

   for(int x=1;x<_field.length;x++)
   {
     int yMin=_field[x].length;
     for(int y=_field[x].length-1;y>=0;y--)
       if(_field[x][y]!=CField.C_EMPTY)
         yMin=y;

     double diff=yOld-yMin;
     if(diff<0)
       diff=-diff;
     diff-=0.2;
     if(diff<0)
       diff=0;
     yDiff+=diff*diff*diff;
     yOld=yMin;
   }
   return yDiff;
 }

Again, I fail to see how this crash can happen in getHeightDiff. If there was something wrong with the array getMaxHeight() should've crashed first. Also note that the array is thread-private - so it can't be a multi-threading issue. This code is run in a thread of a thread-pool as a Future.

I'm a bit stranded. Anyone any ideas? Should I send the full source somewhere?

The application was compiled with JET 7.2 MP1 and the crash is not reproducable. It's weird that I get crash reports of NullPointerExceptions from all over the place from various machines. The user ran this under Windows 7 on a dual-core machine.

Cheers,

Simon

Share this post


Link to post
Share on other sites

it's me again. I have another crash report... This time it's a NullPointerException in the method getHeightDiff()

I'm seeing a pattern here. I get more reports from random NullPointerExceptions all over the place every day. And 99% of the time I can't understand how that could've happened. So far I couldn't reproduce the problem on my machine - it seems to happen very seldom.

Share this post


Link to post
Share on other sites

Hi Simon,

Do you use native libraries in your application? Random NPEs can be caused by subtle bugs in native libraries.

Try to stress-test your application to figure out how to reproduce NPE.

If the error can be reproduced, then we will be able to debug it and figure out what happens.

You can send your sample to Excelsior JET support.

Share this post


Link to post
Share on other sites

Yes we use several native libraries: LWJGL, NativeBass and BASS.

I ran the app several hundred times by now for hours and have yet to reproduce it. It happens approximately once every 5'000 runs of our game. Anyone can download the game from our website. I couldn't identify a pattern of the crashes: Sometimes it crashes early on, sometimes only after an hour - sometimes here, sometimes there.

Share this post


Link to post
Share on other sites

I still cannot reproduce the problem reliably. The application crashed on my machine too once, but after the single crash it worked perfectly fine again. Do you have any suggestions what I could try next? Can you help?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×