[Odejava] Native crash with contact feedback

I’ve running Odejava for some time now for my uni project simulations. Lately I’ve had to add collisions, and things aren’t working. I use Windows XP, and haven’t tested it on other operating systems. I use the latest CVS and the 2004-10-30 binaries.

Anywhere between the 2000th (sometimes less) and 6000th (usual around 3000th) step I get a native crash. It happens everytime, but one of usualy 4 native methods are to blame (taken from hs_err_pidxxxx.log) from org.odejava.ode.OdeJNI.
delete_floatArray()
new_dContact()
new_dSurfaceParameters()
new_dJointFeedback()

The delete_floatArray() happens most often. I’m using the low level api since I need to actually create the contact joint and also I need feedback from it after the simulation does its step.

I use JavaCollision.collide() and BulkContact to iterate over each collision to create the contacts and their feedback joints. This is where I need to create native (swig) arrays to copy data from BulkCollision into the dContactGeom etc. I put the native arrays in a list, so that I can later delete them after the simulation is stepped. I also delete the contact feedback joints after each step.

Note: I’ve just tested it without creating feedback joints for the contact joints, and there is no problem. Any ideas?

This is how I create the feedback joints for contacts:

SWIGTYPE_p_dJointID jid = Ode.dJointCreateContact(world.getId(), javaCollision.getContactGroupId(), contact);
Ode.dJointAttach(jid, b1ID, b2ID);

dJointFeedback odeFeedback = new dJointFeedback();
JointFeedback jointFeedback = new JointFeedback(odeFeedback);
Ode.dJointSetFeedback(jid, odeFeedback);

where “contact” is the dContact i created, “b1ID” and “b2ID” are the two body IDs involved in the collision (the collision is between the robot’s foot and the ground so one of the IDs is Ode.getBODYID_ZERO()).

I really need feedback for the contact joints because I’m using them for pressure sensors on my robot. I need to know the amount of force at each contact. Is there any other way this could be achieved without the use of contact feedback joints? Up until the crash, the feedback joints seems to work well, ie, they have what seems to be correct force values.

This is only an initial post, incase the problem is obvious from what is written. Otherwise I could go into more details such as posting a hs_err_pidxxxx.log file etc.

Edit: Problem fixed, see reply #4.

any luck?

Lets see the entire stacktrace.

Have you compared the behaviour on other operating systems?

Will.

No luck so far. I’ve recoded my contact sensors to on/off switches for the time being, so that contact feedback isn’t used. Anyway here is the stack trace with contact feedback enabled, and the most occuring error with the “delete_floatArray” method.

#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x10057622, pid=2508, tid=4020
#
# Java VM: Java HotSpot(TM) Server VM (1.5.0-b64 mixed mode)
# Problematic frame:
# C  [odejava.dll+0x57622]
#

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

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

siginfo: ExceptionCode=0xc0000005, writing address 0x3891b839

Registers:
EAX=0x0b5d0cf0, EBX=0x00000120, ECX=0x3891b831, EDX=0x0b5fd11c
ESP=0x0b5cf850, EBP=0x0b5cf870, ESI=0x00000003, EDI=0x0b5fd2dc
EIP=0x10057622, EFLAGS=0x00010202

Top of Stack: (sp=0x0b5cf850)
0x0b5cf850:   00000000 0b5fd120 0b5cf8b0 00000001
0x0b5cf860:   0b5d1440 00000020 00000100 00000011
0x0b5cf870:   0b16ce30 1005477c 0b5d0650 0000000f
0x0b5cf880:   02c50210 10054176 0b5fd120 1004d44a
0x0b5cf890:   0b5fd120 1004d31a 0b5fd120 00be7bf2
0x0b5cf8a0:   0b16185c 0b5cf8b0 0b5fd120 00000000
0x0b5cf8b0:   0730e4e0 02c50210 02ad08a8 00000000
0x0b5cf8c0:   0b1617a0 00000000 034c6f60 00bfb360 

Instructions: (pc=0x10057622)
0x10057612:   13 04 89 79 04 8b 4c 13 04 8b 7c 13 08 03 5d f8
0x10057622:   89 79 08 89 5d f4 8b fb c1 ff 04 4f 83 ff 3f 76 


Stack: [0x0b590000,0x0b5d0000),  sp=0x0b5cf850,  free space=254k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [odejava.dll+0x57622]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J  org.odejava.ode.OdeJNI.delete_floatArray(J)V
J  simmech.OdeSimulator$SimulatorHandler.simulatorStepped(Lsimulator/SimulatorEvent;)V
J  simulator.Simulator.fireSimulatorStepped()V
J  java.awt.EventDispatchThread.pumpOneEventForHierarchy(ILjava/awt/Component;)Z
v  ~I2CAdapter
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

---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )
  0x0b040c48 JavaThread "TimerQueue" daemon [_thread_blocked, id=1768]
  0x000363a0 JavaThread "DestroyJavaVM" [_thread_blocked, id=3732]
  0x0b1b7008 JavaThread "Thread-3" daemon [_thread_in_Java, id=3440]
=>0x0b1617a0 JavaThread "AWT-EventQueue-0" [_thread_in_native, id=4020]
  0x0ae3cd18 JavaThread "AWT-Shutdown" [_thread_blocked, id=2720]
  0x0b12faa8 JavaThread "Thread-2" [_thread_blocked, id=2888]
  0x0b109c78 JavaThread "Java2D Disposer" daemon [_thread_blocked, id=3908]
  0x0ae406d8 JavaThread "AWT-Windows" daemon [_thread_in_native, id=3168]
  0x00abf688 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=3044]
  0x00abe388 JavaThread "CompilerThread1" daemon [_thread_blocked, id=3064]
  0x00abd528 JavaThread "CompilerThread0" daemon [_thread_blocked, id=812]
  0x00abc558 JavaThread "AdapterThread" daemon [_thread_blocked, id=592]
  0x00abb910 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=2212]
  0x00ab2fb8 JavaThread "Finalizer" daemon [_thread_blocked, id=1056]
  0x00ab2328 JavaThread "Reference Handler" daemon [_thread_blocked, id=1816]

Other Threads:
  0x00ab01e8 VMThread [id=2024]
  0x00ac0860 WatcherThread [id=3952]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap
 def new generation   total 1664K, used 164K [0x02ad0000, 0x02c90000, 0x031e0000)
  eden space 1536K,   2% used [0x02ad0000, 0x02ad9240, 0x02c50000)
  from space 128K,  99% used [0x02c50000, 0x02c6fff8, 0x02c70000)
  to   space 128K,   0% used [0x02c70000, 0x02c70000, 0x02c90000)
 tenured generation   total 13792K, used 9002K [0x031e0000, 0x03f58000, 0x06ad0000)
   the space 13792K,  65% used [0x031e0000, 0x03aaa988, 0x03aaaa00, 0x03f58000)
 compacting perm gen  total 16384K, used 15816K [0x06ad0000, 0x07ad0000, 0x0aad0000)
   the space 16384K,  96% used [0x06ad0000, 0x07a423e0, 0x07a42400, 0x07ad0000)
No shared spaces configured.

Dynamic libraries:
0x00400000 - 0x0040c000       C:\java\jre\bin\java.exe
0x77f50000 - 0x77ff7000       C:\WINDOWS\System32\ntdll.dll
0x77e60000 - 0x77f46000       C:\WINDOWS\system32\kernel32.dll
0x77dd0000 - 0x77e5d000       C:\WINDOWS\system32\ADVAPI32.dll
0x78000000 - 0x78087000       C:\WINDOWS\system32\RPCRT4.dll
0x77c10000 - 0x77c63000       C:\WINDOWS\system32\MSVCRT.dll
0x6d840000 - 0x6dba7000       C:\java\jre\bin\server\jvm.dll
0x77d40000 - 0x77dd0000       C:\WINDOWS\system32\USER32.dll
0x7f000000 - 0x7f041000       C:\WINDOWS\system32\GDI32.dll
0x76b40000 - 0x76b6c000       C:\WINDOWS\System32\WINMM.dll
0x6d280000 - 0x6d288000       C:\java\jre\bin\hpi.dll
0x76bf0000 - 0x76bfb000       C:\WINDOWS\System32\PSAPI.DLL
0x6d610000 - 0x6d61c000       C:\java\jre\bin\verify.dll
0x6d300000 - 0x6d31d000       C:\java\jre\bin\java.dll
0x6d630000 - 0x6d63f000       C:\java\jre\bin\zip.dll
0x6d000000 - 0x6d166000       C:\java\jre\bin\awt.dll
0x73000000 - 0x73023000       C:\WINDOWS\System32\WINSPOOL.DRV
0x76390000 - 0x763ac000       C:\WINDOWS\System32\IMM32.dll
0x4fec0000 - 0x4fff6000       C:\WINDOWS\system32\ole32.dll
0x5ad70000 - 0x5ada4000       C:\WINDOWS\System32\uxtheme.dll
0x51000000 - 0x51050000       C:\WINDOWS\System32\ddraw.dll
0x73bc0000 - 0x73bc6000       C:\WINDOWS\System32\DCIMAN32.dll
0x5c000000 - 0x5c0c8000       C:\WINDOWS\System32\D3DIM700.DLL
0x74720000 - 0x74764000       C:\WINDOWS\System32\MSCTF.dll
0x7cd00000 - 0x7d512000       C:\WINDOWS\system32\shell32.dll
0x70a70000 - 0x70ad6000       C:\WINDOWS\system32\SHLWAPI.dll
0x71950000 - 0x71a34000       C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.1612_x-ww_7c379b08\comctl32.dll
0x77340000 - 0x773cb000       C:\WINDOWS\system32\comctl32.dll
0x6d240000 - 0x6d27d000       C:\java\jre\bin\fontmanager.dll
0x6d4c0000 - 0x6d4d3000       C:\java\jre\bin\net.dll
0x71ab0000 - 0x71ac5000       C:\WINDOWS\System32\WS2_32.dll
0x71aa0000 - 0x71aa8000       C:\WINDOWS\System32\WS2HELP.dll
0x6d4e0000 - 0x6d4e9000       C:\java\jre\bin\nio.dll
0x10000000 - 0x10070000       C:\java\jre\bin\odejava.dll
0x6d360000 - 0x6d366000       C:\java\jre\bin\jawt.dll
0x0b810000 - 0x0b870000       C:\java\jre\bin\jogl.dll
0x5ed00000 - 0x5edc6000       C:\WINDOWS\System32\OPENGL32.dll
0x68b20000 - 0x68b3e000       C:\WINDOWS\System32\GLU32.dll
0x6d190000 - 0x6d1bf000       C:\java\jre\bin\cmm.dll
0x6d3c0000 - 0x6d3df000       C:\java\jre\bin\jpeg.dll
0x605d0000 - 0x605d8000       C:\WINDOWS\System32\mslbui.dll
0x69000000 - 0x6950b000       C:\WINDOWS\System32\atioglxx.dll
0x71c20000 - 0x71c6e000       C:\WINDOWS\System32\netapi32.dll
0x71b20000 - 0x71b31000       C:\WINDOWS\system32\MPR.dll
0x75f60000 - 0x75f66000       C:\WINDOWS\System32\drprov.dll
0x71c10000 - 0x71c1d000       C:\WINDOWS\System32\ntlanman.dll
0x71cd0000 - 0x71ce6000       C:\WINDOWS\System32\NETUI0.dll
0x71c90000 - 0x71ccc000       C:\WINDOWS\System32\NETUI1.dll
0x71c80000 - 0x71c86000       C:\WINDOWS\System32\NETRAP.dll
0x71bf0000 - 0x71c01000       C:\WINDOWS\System32\SAMLIB.dll
0x75f70000 - 0x75f79000       C:\WINDOWS\System32\davclnt.dll
0x76670000 - 0x76757000       C:\WINDOWS\System32\SETUPAPI.dll
0x75f40000 - 0x75f5f000       C:\WINDOWS\system32\appHelp.dll
0x7c890000 - 0x7c911000       C:\WINDOWS\System32\CLBCATQ.DLL
0x77120000 - 0x771ab000       C:\WINDOWS\system32\OLEAUT32.dll
0x77050000 - 0x77115000       C:\WINDOWS\System32\COMRes.dll
0x77c00000 - 0x77c07000       C:\WINDOWS\system32\VERSION.dll
0x76980000 - 0x76987000       C:\WINDOWS\System32\LINKINFO.dll
0x76990000 - 0x769b4000       C:\WINDOWS\System32\ntshrui.dll
0x76b20000 - 0x76b35000       C:\WINDOWS\System32\ATL.DLL
0x75a70000 - 0x75b15000       C:\WINDOWS\system32\USERENV.dll
0x6d1c0000 - 0x6d1e3000       C:\java\jre\bin\dcpr.dll

VM Arguments:
jvm_args: -Dsun.java2d.opengl=false
java_command: simmech.test.Biped3BodyOdeXithTest

Environment Variables:
CLASSPATH=.;.;C:\PROGRA~1\JMF21~1.1E\lib\sound.jar;C:\PROGRA~1\JMF21~1.1E\lib\jmf.jar;C:\PROGRA~1\JMF21~1.1E\lib; d°mystemroot\java\classes;.
PATH=C:\java\bin;C:\texmf\miktex\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;"C:\Program Files\UnxUtils\usr\local\wbin";C:\PROGRA~1\COMMON~1\ULEADS~1\Mpeg;C:\MATLAB7\bin\win32;;C:\Program Files\Common Files\GTK\2.0\bin
USERNAME=Lukasz Wiklendt
OS=Windows_NT
PROCESSOR_IDENTIFIER=x86 Family 6 Model 8 Stepping 1, AuthenticAMD


---------------  S Y S T E M  ---------------

OS: Windows XP Build 2600 Service Pack 1

CPU:total 1 family 6, cmov, cx8, fxsr, mmx, sse

Memory: 4k page, physical 1048052k(428712k free), swap 2520500k(2007440k free)

vm_info: Java HotSpot(TM) Server VM (1.5.0-b64) for windows-x86, built on Sep 15 2004 02:42:57 by "java_re" with MS VC++ 6.0

I haven’t tried it on other os’es, I would need to completely rebuild my machine into dual boot for that. I’ll try coding up a minimal program need to get this error with contact feedback, something small enough to post in its entirety.

Sounds like it could be a stack size problem. Have you tried increasing the Java stack size using -Xss? I use a stack size of 2M which greatly increases the number of objects I can put into my environment before a native crash.

[quote]Sounds like it could be a stack size problem. Have you tried increasing the Java stack size using -Xss? I use a stack size of 2M which greatly increases the number of objects I can put into my environment before a native crash.
[/quote]
Yeah, I’ve tried up to 20M stack size, and the problem still occured without change, ie after same amount of steps. I don’t have many objects at all. Just a flat ground, and a simple 3 link biped, ie. left and right legs and a hip.

But, I’ve solved the problem ;D, thanks to the many objects and stack size idea. I had a really stupid bug in my program :-[. For my contact sensor I only needed one feedback, but with the event-based contact notification I set up, my event listener created a contact feedback joint per contact, but only saved to deleted the last one.

So the lesson contribution for this community: these types of errors are symptoms of not explicitly deleting all contact feedbacks.