[odejava] Geom.removeFromSpace

Will/Jani,

I’m getting an exception from odejava.dll when trying to remove a Geom from a space:

An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x5E16D99
Function=dSpaceAdd+0x9
Library=C:\wip\lib\odejava.dll

Current Java thread:
        at org.odejava.ode.OdeJNI.dSpaceAdd(Native Method)
        at org.odejava.ode.Ode.dSpaceAdd(Ode.java:441)
        at org.odejava.Geom.removeFromSpace(Geom.java:357)
        at org.odejava.Space.remove(Space.java:155)
        at org.bennedum.tank.Universe.remove(Universe.java:214)
        at org.bennedum.tank.ProjectileManager.stop(ProjectileManager.java:110)
        at org.bennedum.tank.ProjectileManager.stepFrame(ProjectileManager.java:53)
        at org.bennedum.tank.Universe.stepFrame(Universe.java:283)
        at org.bennedum.tank.Universe$FrameBehavior.processStimulus(Universe.java:346)
        at javax.media.j3d.BehaviorScheduler.doWork(BehaviorScheduler.java:172)
        - locked <0x11a343f0> (a javax.media.j3d.BehaviorRetained)
        - locked <0x11a343f0> (a javax.media.j3d.BehaviorRetained)
        at javax.media.j3d.J3dThread.run(J3dThread.java:250)

I didn’t include all the other garbage output, but I can if anyone thinks it’s useful.

The code from Geom.java is:

      protected void removeFromSpace () {
            assert spaceId != Space.SPACEID_ZERO: "This geom is already not in any Space";
            
            Ode.dSpaceRemove(spaceId, geomId);
            spaceId = Space.SPACEID_ZERO;
            Ode.dSpaceAdd(spaceId, geomId);

      }

Is the SPACEID_ZERO defined by ODE or is it something peculiar to odejava? If it’s specific to odejava, then I don’t think you should be trying to add a geom to that space in ODE. But maybe I’m wrong?

I seem to recall that I had this problem once before, but I can’t figure out what I did.

-Tab

the code does work - the zero space is defined in ODE. I have tested it and it worked for me.

This is a good feature as it means you don’t have to keep recreating Geom’s.

The bug is a bug in Odejava/ODE on the native side. Try increasing your heap size (-Xms128M -Xmx256M) if you have enough RAM.

Native bugs are a bitch as unlike with java you don’t get a nice stack trace. In this case we at least know that ‘org.odejava.ode.OdeJNI.dSpaceAdd’ is at fault. Maybe Jani could take a look at it.

Will.

I’ll try to increase the mem, but I doubt it will help. I haven’t changed my code, only updated and rebuilt odejava from cvs yesterday. I’ll let you know…

-Tab

Increasing memory didn’t fix it :frowning:

I’ve commented out the dSpaceAdd call and things work correctly. Are you sure adding a Geom to Space with a zero I is allowed in ODE? I’m not sure why it’s even necessary after the dSpaceRemove call after reading the ODE docs.

-Tab

perhaps you are right.

The zero space is used when creating an object not initially in a space. This is so you can create a geom and add it to space later which is important. You can’t do this with bodies and it is a bit of a pain.

But, it sounds like that line can be removed without affecting this feature.

I’ve made this change - lets see how it goes.

Will.