This site requires JavaScript, please enable it in your browser!
Greenfoot back
AwesomeNameGuy
AwesomeNameGuy wrote ...

2011/12/14

Interesting Error

AwesomeNameGuy AwesomeNameGuy

2011/12/14

#
Not sure what to make of this: java.lang.NullPointerException at greenfoot.collision.ibsp.IBSPColChecker.getOneIntersectingObject(IBSPColChecker.java:831) at greenfoot.collision.ColManager.getOneIntersectingObject(ColManager.java:188) at greenfoot.World.getOneIntersectingObject(World.java:749) at greenfoot.Actor.getOneIntersectingObject(Actor.java:906) at Enemy.detectCollisions(Enemy.java:164) at Enemy.act(Enemy.java:60) at ElectricSpark.act(ElectricSpark.java:28) at greenfoot.core.Simulation.actActor(Simulation.java:507) at greenfoot.core.Simulation.runOneLoop(Simulation.java:470) at greenfoot.core.Simulation.runContent(Simulation.java:204) at greenfoot.core.Simulation.run(Simulation.java:194) Anyway, I was checking my scenario for bugs and this happened, right after I died in my game. The detectCollisions method just checks for the player via getOneIntersectingObject and doesn't do anything if the player is null, so I don't know if it's a problem with my code or what. Any advice on how to prevent something like this?
mjrb4 mjrb4

2011/12/14

#
Could you post the scenario so we can have a look?
davmac davmac

2011/12/14

#
Is it possible that you're calling "getIntersectingObjects" on/from an actor that isn't in the world?
AwesomeNameGuy AwesomeNameGuy

2011/12/14

#
Well here's the offending method, if you want to see the code for the scenario I can post it, but it's kinda messy and obtuse. But the method is this:
public void detectCollisions() {
        md = (MegaDude) getOneIntersectingObject(MegaDude.class);
        if (md != null) {
            if (!md.currentlyGettingHit() && !md.isInvincible()) {
                if (md.getX() > getX()) {
                    md.hit(false,damage);
                } else {
                    md.hit(true,damage);
                }
            }
            if (powerup) { // I made the powerups a subclass of the enemy class since they do some similar things
                                   // they are kind of like an enemy that heals instead of hurts
                health = -1; // when the health is less than zero it gets removed at the end of act();
            }
        }
    }
Now it happened right after I died, so there was no object to detect, but that means that the variable md is just null, doesn't it? I don't think it could have been trying to call this method after the eletric spark itself was removed, any code that would remove it is stuck way at the end of the act method. Anyway, it is definately not a common error, I probably played through the stage 10 times and this has only happened once.
davmac davmac

2011/12/14

#
Ok. You're not doing anything crazy like using threads or a swing ui? If not, and you manage to reproduce this reliably, please let us know. It might be a Greenfoot bug (but not one I've seen before).
kiarocks kiarocks

2011/12/14

#
I would like a look at the scenario.
AwesomeNameGuy AwesomeNameGuy

2011/12/15

#
For sure, I'll keep an eye out. I'll post an update to my scenario probably in a couple days, I just want to finish drawing graphics for the level I'm working on, and I'll include the source for those who want to see, but it's not pretty though!
kiarocks kiarocks

2011/12/15

#
I like crazy code!
You need to login to post a reply.