Exception after object removed from PhysicsWorld

I add several objects to the PhysicsWorld.  Later I remove some of them when they "cease to exist" … when I go to add a new object (with the same name as one of the removed objects from before) I get the following exception:  Is the name causing my problem or is this a bug with the PhysicsWorld?



Thanks!



Aug 30, 2005 11:58:03 AM com.jmex.physics.PhysicsWorld addObject

INFO: Physics Object (Room2) has been added to the PhysicsWorld

java.lang.NullPointerException

at com.jmex.physics.PhysicsWorld.iterateContacts(PhysicsWorld.java:415)

at com.jmex.physics.PhysicsWorld.update(PhysicsWorld.java:376)

at com.brweber2.lang.gui.VisualGame.simpleUpdate(VisualGame.java:202)

at com.brweber2.lang.gui.SimpleVisualGame.update(SimpleVisualGame.java:103)

at com.jme.app.BaseGame.start(Unknown Source)

at com.brweber2.lang.gui.RunGui.main(RunGui.java:16)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:324)

at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)

Well, personally I've never tried to remove anything from my PhysicsWorld but you might consider just disabling it instead just in case you might want to re-use it in the future.  It's always better to re-use than re-create. :slight_smile:



Someone else may have some more experience in this area though.



darkfrog

Sigh



I thought I'd fixed all the problems related to re-adding objects a long time ago :frowning:



In Marble Fun I use removeAllObjects() at the end of each level, and then I add objects (often with equal names) at start of the next – seems to work fine. Could you please try that as well?

Per,



I caught this exception (it is thrown once in update() ).  Since the exception is only thrown once, I'm wondering if some object is simply not threadsafe?  Maybe as you are removing it another collision is accessing the object.  At any rate, I'm catching the exception for right now and everything seems to be working, well sort of. When I add things back my player object falls forever b/c the floor doesn't get added fast enough.  Its actually pretty funny to watch.  I'll try to debug the code and see if I can't find something that works so you can add it if you'd like.



Instead of remove all objects, I'm calling cleanup() and initGame() for each new level so I'm getting a new PhysicsWorld per level.  I'll try removeAllObjects… hopefully that will have the same effect.



Thanks.

You might try disabling the physics object before removing it.  That should solve the problem if it has to do with a collision occuring while it is being removed, right?



darkfrog

How do you disable a PhysicsObject?  I looked for such a thing in the API but I can't find it.  Could you post a code snippet? 



Thanks!

Ugh, I'll try to post something later tonight, I'm at work right now.  I believe it's something like po.setEnabled(false);  If you look at the BallThrower example it does that in order to be able to re-use balls instead of creating new ones every time you fire.  If it's not setEnabled then you can find your answer there.



Thanks,



darkfrog