Internal errors and native crashes..

In order to simulate an expanding object, I am swapping out the geoms of a body fairly quickly. The effect looks good, but it’s causing a variety of internal errors and crashes.

This is how I’m trying to do it:


PlaceableGeom geo = (PlaceableGeom)this.sim_body.getGeom();
space.remove(geo);
this.sim_body.removeGeom(geo);
geo.delete();

geo = new GeomSphere((float)(this.bounds.getWidth()+22)/2);
this.sim_body.addGeom(geo);
space.addBodyGeoms(this.sim_body);

It causes the following “ODE Internal Error 2” message:

Bad argument(s) (ode/src/collision_space.cpp:182)

and when that doesn’t happen, I get a message like this:


#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0317e6f1, pid=4356, tid=3724
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_01-b08 mixed mode, sharing)
# Problematic frame:
# C  [odejava.dll+0x6e6f1]
#

---------------  T H R E A D  ---------------

Current thread (0x02d62850):  JavaThread "AWT-EventQueue-0" [_thread_in_native, id=3724]

siginfo: ExceptionCode=0xc0000005, writing address 0x00000004

Registers:
EAX=0x031a13f0, EBX=0x031a0650, ECX=0x00000000, EDX=0x031b322c
ESP=0x02f8f35c, EBP=0x02f8f37c, ESI=0xffffffff, EDI=0x47b3b693
EIP=0x0317e6f1, EFLAGS=0x00010246

Top of Stack: (sp=0x02f8f35c)
0x02f8f35c:   02d62850 00000040 26bee1f8 02d91038
0x02f8f36c:   00000050 031a1534 00000000 00000000
0x02f8f37c:   02f8f3a8 0317acc3 031a0650 26bee1f8
0x02f8f38c:   0317ac94 00000040 0317ac81 00000040
0x02f8f39c:   00000000 0313e6b9 00000040 02f8f3b8
0x02f8f3ac:   031119f2 00000040 031b3140 02f8f400
0x02f8f3bc:   03173909 031b3430 00000000 00ad826f
0x02f8f3cc:   02d6290c 02f8f408 031b3160 00000000 

Instructions: (pc=0x0317e6f1)
0x0317e6e1:   04 eb 03 8b 5d 08 8b 4a 08 8b 7a 04 83 7d f8 00
0x0317e6f1:   89 79 04 8b 4a 04 8b 7a 08 89 79 08 0f 84 94 00 


Stack: [0x02f50000,0x02f90000),  sp=0x02f8f35c,  free space=252k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [odejava.dll+0x6e6f1]
C  [odejava.dll+0x6acc3]
C  [odejava.dll+0x19f2]
C  [odejava.dll+0x63909]
j  org.odejava.ode.Ode.dGeomSetBody(Lorg/odejava/ode/SWIGTYPE_p_dGeomID;Lorg/odejava/ode/SWIGTYPE_p_dBodyID;)V+8
j  org.odejava.PlaceableGeom.setBody(Lorg/odejava/Body;)V+111
j  org.odejava.Body.removeGeom(Lorg/odejava/PlaceableGeom;)V+38
j  Marble.updateSim(Lorg/odejava/World;Lorg/odejava/Space;Lorg/odejava/display/DisplayBin;)V+16
j  Sim.marbleUpdated(LSimObject;)V+13
j  MarbleStore.refresh(LSimObject;)V+34
j  MarbleStore.simObjectChange(LSimObject;Ljava/util/List;Z)V+6
j  Marble.fireChangeEvent(Z)V+34
j  Marble.resize(DD)V+52
j  FaceMarble.paint(Ljava/awt/Graphics2D;Ljava/awt/geom/Rectangle2D;)V+67
j  DrawTest$MyPanel.paintComponent(Ljava/awt/Graphics;)V+91
j  javax.swing.JComponent.paint(Ljava/awt/Graphics;)V+260
j  javax.swing.JComponent.paintWithOffscreenBuffer(Ljavax/swing/JComponent;Ljava/awt/Graphics;IIIILjava/awt/Image;)V+174
j  javax.swing.JComponent.paintDoubleBuffered(Ljavax/swing/JComponent;Ljava/awt/Component;Ljava/awt/Graphics;IIII)Z+131
j  javax.swing.JComponent._paintImmediately(IIII)V+739
j  javax.swing.JComponent.paintImmediately(IIII)V+83
j  javax.swing.RepaintManager.paintDirtyRegions()V+314
j  javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run()V+32
j  java.awt.event.InvocationEvent.dispatch()V+47
j  java.awt.EventQueue.dispatchEvent(Ljava/awt/AWTEvent;)V+26
j  java.awt.EventDispatchThread.pumpOneEventForHierarchy(ILjava/awt/Component;)Z+200
j  java.awt.EventDispatchThread.pumpEventsForHierarchy(ILjava/awt/Conditional;Ljava/awt/Component;)V+26
j  java.awt.EventDispatchThread.pumpEvents(ILjava/awt/Conditional;)V+4
j  java.awt.EventDispatchThread.pumpEvents(Ljava/awt/Conditional;)V+3
j  java.awt.EventDispatchThread.run()V+9
v  ~StubRoutines::call_stub
V  [jvm.dll+0x8176e]
V  [jvm.dll+0xd481d]
V  [jvm.dll+0x8163f]
V  [jvm.dll+0x8139c]
V  [jvm.dll+0x9c05c]
V  [jvm.dll+0xfeece]
V  [jvm.dll+0xfee9c]
C  [MSVCRT.dll+0x2a3b0]
C  [kernel32.dll+0xb50b]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  org.odejava.ode.OdeJNI.dGeomSetBody(JJ)V+0
j  org.odejava.ode.Ode.dGeomSetBody(Lorg/odejava/ode/SWIGTYPE_p_dGeomID;Lorg/odejava/ode/SWIGTYPE_p_dBodyID;)V+8
j  org.odejava.PlaceableGeom.setBody(Lorg/odejava/Body;)V+111
j  org.odejava.Body.removeGeom(Lorg/odejava/PlaceableGeom;)V+38
j  Marble.updateSim(Lorg/odejava/World;Lorg/odejava/Space;Lorg/odejava/display/DisplayBin;)V+16
j  Sim.marbleUpdated(LSimObject;)V+13
j  MarbleStore.refresh(LSimObject;)V+34
j  MarbleStore.simObjectChange(LSimObject;Ljava/util/List;Z)V+6
j  Marble.fireChangeEvent(Z)V+34
j  Marble.resize(DD)V+52
j  FaceMarble.paint(Ljava/awt/Graphics2D;Ljava/awt/geom/Rectangle2D;)V+67
j  DrawTest$MyPanel.paintComponent(Ljava/awt/Graphics;)V+91
j  javax.swing.JComponent.paint(Ljava/awt/Graphics;)V+260
j  javax.swing.JComponent.paintWithOffscreenBuffer(Ljavax/swing/JComponent;Ljava/awt/Graphics;IIIILjava/awt/Image;)V+174
j  javax.swing.JComponent.paintDoubleBuffered(Ljavax/swing/JComponent;Ljava/awt/Component;Ljava/awt/Graphics;IIII)Z+131
j  javax.swing.JComponent._paintImmediately(IIII)V+739
j  javax.swing.JComponent.paintImmediately(IIII)V+83
j  javax.swing.RepaintManager.paintDirtyRegions()V+314
j  javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run()V+32
j  java.awt.event.InvocationEvent.dispatch()V+47
j  java.awt.EventQueue.dispatchEvent(Ljava/awt/AWTEvent;)V+26
j  java.awt.EventDispatchThread.pumpOneEventForHierarchy(ILjava/awt/Component;)Z+200
j  java.awt.EventDispatchThread.pumpEventsForHierarchy(ILjava/awt/Conditional;Ljava/awt/Component;)V+26
j  java.awt.EventDispatchThread.pumpEvents(ILjava/awt/Conditional;)V+4
j  java.awt.EventDispatchThread.pumpEvents(Ljava/awt/Conditional;)V+3
j  java.awt.EventDispatchThread.run()V+9
v  ~StubRoutines::call_stub

Any ideas? I’ve tried reordering statements and such to no avail.

Try using the latest build from CVS.

I just tried that, and it seems to fix most of the problems. However, now I’m getting native exceptions (with much less frequency, though) in really strange places, like ntdll.dll. For example:


#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c9111de, pid=324, tid=4364
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_01-b08 mixed mode, sharing)
# Problematic frame:
# C  [ntdll.dll+0x111de]
#

---------------  T H R E A D  ---------------

Current thread (0x02d62870):  JavaThread "AWT-EventQueue-0" [_thread_in_native, id=4364]

siginfo: ExceptionCode=0xc0000005, reading address 0x00000000

Registers:
EAX=0x00000000, EBX=0x00030000, ECX=0x00a93df8, EDX=0x00030178
ESP=0x02f8ee70, EBP=0x02f8f090, ESI=0x00a93df0, EDI=0x00000000
EIP=0x7c9111de, EFLAGS=0x00010206

Top of Stack: (sp=0x02f8ee70)
0x02f8ee70:   02d7d6dc 00000008 00000000 00000008
0x02f8ee80:   00a694e4 00031468 00030000 02d7d6d8
0x02f8ee90:   02f8ee80 00000000 02f8f0c4 7c90ee18
0x02f8eea0:   7c910738 ffffffff 7c910732 7c9106ab
0x02f8eeb0:   7c9106eb 02d6292c 00000248 00000000
0x02f8eec0:   02f8ee9c 6d77a41d 02f8fb64 7379adb6
0x02f8eed0:   737613c0 ffffffff 73775be2 73775c9b
0x02f8eee0:   000cf068 73775cb2 737a09e8 02e10d18 

Instructions: (pc=0x7c9111de)
0x7c9111ce:   39 89 bd 0c ff ff ff 8b 46 0c 89 85 68 ff ff ff
0x7c9111de:   8b 10 3b 57 04 0f 85 8c 31 02 00 3b d1 0f 85 84 


Stack: [0x02f50000,0x02f90000),  sp=0x02f8ee70,  free space=251k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [ntdll.dll+0x111de]
C  [MSVCRT.dll+0x1c3c9]
C  [MSVCRT.dll+0x1c3e7]
C  [MSVCRT.dll+0x1c42e]
C  [awt.dll+0x36627]
C  [awt.dll+0x35caf]
C  [awt.dll+0x3887b]
J  sun.awt.image.ImagingLib.transformBI(Ljava/awt/image/BufferedImage;Ljava/awt/image/BufferedImage;[DI)I
J  sun.awt.image.ImagingLib.filter(Ljava/awt/image/BufferedImageOp;Ljava/awt/image/BufferedImage;Ljava/awt/image/BufferedImage;)Ljava/awt/image/BufferedImage;
J  java.awt.image.AffineTransformOp.filter(Ljava/awt/image/BufferedImage;Ljava/awt/image/BufferedImage;)Ljava/awt/image/BufferedImage;
J  sun.java2d.pipe.DrawImage.renderImageXform(Lsun/java2d/SunGraphics2D;Ljava/awt/Image;Ljava/awt/geom/AffineTransform;IIIIILjava/awt/Color;)V
J  sun.java2d.pipe.DrawImage.transformImage(Lsun/java2d/SunGraphics2D;Ljava/awt/Image;Ljava/awt/geom/AffineTransform;IIIIILjava/awt/Color;)V
J  sun.java2d.pipe.DrawImage.transformImage(Lsun/java2d/SunGraphics2D;Ljava/awt/Image;IILjava/awt/geom/AffineTransform;I)V
J  sun.java2d.pipe.DrawImage.transformImage(Lsun/java2d/SunGraphics2D;Ljava/awt/Image;Ljava/awt/geom/AffineTransform;Ljava/awt/image/ImageObserver;)Z
J  sun.java2d.SunGraphics2D.drawImage(Ljava/awt/Image;Ljava/awt/geom/AffineTransform;Ljava/awt/image/ImageObserver;)Z
J  FaceMarble.paint(Ljava/awt/Graphics2D;Ljava/awt/geom/Rectangle2D;)V
J  DrawTest$MyPanel.paintComponent(Ljava/awt/Graphics;)V
j  javax.swing.JComponent.paint(Ljava/awt/Graphics;)V+260
j  javax.swing.JComponent.paintWithOffscreenBuffer(Ljavax/swing/JComponent;Ljava/awt/Graphics;IIIILjava/awt/Image;)V+174
j  javax.swing.JComponent.paintDoubleBuffered(Ljavax/swing/JComponent;Ljava/awt/Component;Ljava/awt/Graphics;IIII)Z+131
J  javax.swing.JComponent._paintImmediately(IIII)V
v  ~RuntimeStub::alignment_frame_return Runtime1 stub
j  javax.swing.JComponent.paintImmediately(IIII)V+83
j  javax.swing.RepaintManager.paintDirtyRegions()V+314
j  javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run()V+32
j  java.awt.event.InvocationEvent.dispatch()V+47
j  java.awt.EventQueue.dispatchEvent(Ljava/awt/AWTEvent;)V+26
j  java.awt.EventDispatchThread.pumpOneEventForHierarchy(ILjava/awt/Component;)Z+200
j  java.awt.EventDispatchThread.pumpEventsForHierarchy(ILjava/awt/Conditional;Ljava/awt/Component;)V+26
j  java.awt.EventDispatchThread.pumpEvents(ILjava/awt/Conditional;)V+4
j  java.awt.EventDispatchThread.pumpEvents(Ljava/awt/Conditional;)V+3
j  java.awt.EventDispatchThread.run()V+9
v  ~StubRoutines::call_stub
V  [jvm.dll+0x8176e]
V  [jvm.dll+0xd481d]
V  [jvm.dll+0x8163f]
V  [jvm.dll+0x8139c]
V  [jvm.dll+0x9c05c]
V  [jvm.dll+0xfeece]
V  [jvm.dll+0xfee9c]
C  [MSVCRT.dll+0x2a3b0]
C  [kernel32.dll+0xb50b]

They don’t specifically refer to odejava anywhere, but they don’t happen without it, so I’m at a loss as to what the real problem is. Could I have miscompiled odejava?

I’m getting the same native crashes, but only when I exit one of my applications. I also grabbed the latest JOGL betas just before I started noticing the crashes, so I attributed the crashes to the JOGL betas. Is there some operation that reliably causes the crash?

That’s very strange. The thread is “AWT-EventQueue-0” as well.

A long time ago I had a problem where java would crash in the garbage collection method. I couldn’t understand why either, but apparently it is possible for the native code to corrupt some memory which may cause java to crash in the future when that memory was accessed (in this case when the GC was run). I have no idea if this is what’s happening though.

Have you tried running it on any other Operating Systems?

Will.

I think I have solved this problem in my code by moving the System.exit(0) statement to the rendering/physics thread.