[SOLVED]Crash on Slick util Texture drawing

Found some new stuff:

  1. Use a normal ArrayList. For iterating, create one copy, and iterate over that. Any adds/removals should be done to the original list
  2. You are loading textures EVERY FRAME! I’m not entirely sure how SlickUtil works, but maybe you should save the textures somewhere.

To lauch jvisualvm (Windows) Alt-R, type in jvisualvm, press enter.
Find you application, double click, look at the graphs etc. do some sampling/profiling. Find wheter it’s CPU or RAM usage that’s causing the problem.

  1. A normal arraylist gives me a ConcurrentModificationException. I read that I can’t catch it, because catching it is only for debugging, and shouldn’t be part of the final code.
  2. I am saving the textures in the objects’ classes…? the only time I am loading textures is in the creation of new objects, or while evolving a star(nebula-star-pulsar-etc…)
  3. I don’t think jvisualvm works with windows XP

I’ll try stress testing without stars evolving.

Change


private static void update()
   {
      if(!player.dead)
      {
         for(SpaceObject so : objects)
         {
            if(so.dead)
            {
               so = null;
               objects.remove(so);
            }
            else
            {
               if(!so.equals(player))
                  so.update();
            }
         }
         player.update();
      }
   }

to:


private static void update()
   {
      if(!player.dead)
      {
         ArrayList<SpaceObject> copyOfObjects = new ArrayList<SpaceObject>(objects);
         for(SpaceObject so : copyOfObjects)
         {
            if(so.dead)
            {
               so = null;
               objects.remove(so);
            }
            else
            {
               if(!so.equals(player))
                  so.update();
            }
         }
         player.update();
      }
   }

Then you can use a normal arraylist.

  1. You evolve all stars every frame. Didn’t see the random.nextInt().

But still, you need to save the textures somewhere, you’re loading the same texture over and over again each time you call loadTexture().

  1. Okay, nm.

Just finished stress testing, frames still dropped, but at exponentially slower rates than before :o. I think my issue has been solved, I all need is to implement the changes :D. I will use the Array List, and maybe make an enum of textures, or simply define all the possible textures in the class, not just the default. So many months of development went down the drain after only ~11 days of programming :’(. I’ll write in the needed code, stress test, and tell you the results.

I’m not sure I get what you’re saying. Catching is not for debugging. Catching is for trying to recover from or do something useful with an error. If you can’t recover from the error, don’t catch it. If you want to debug potential errors, set your debugger to break on exceptions.

As for the ArrayList problem, use an iterator to traverse a collection if you think you might want to remove something from the collection. I’ve mentioned it before here with an example of how it’s done.

Ok, but no need, I got it figured out now, thanks.