Hi, I took a look at your code.
It looks good. Since the *.h headers from OSG and VPB DLLs are not intended for java JNI invocation, I see that your code has built is own DLL which in turn uses the OSG runtimes. I am taking this similar approach -- as follow... Since I want to do what osgdem.exe does but want to make that accessible from a java application, I wrote a C DLL on Windows that is invoked by my java class. When that DLL has all the includes and DLL lib imported linked to it (same build dependency as osgdem.exe -- but it is a DLL instead of a EXE), the java class can invoke that function in that DLL -- i put some test code in that DLL. Then I copied most of the code from osgdem.cpp into the main function of my DLL. I re-initialize the arguments etc from my entry point so that it mimics osgdem.cpp as much as possible -- at least at this version. Now, when I invoke my DLL which should do the same essential thing that osgdem.exe does, it encounters a java hotspot exception access violation. here is the content of that log file it is generated by jvm. (i hide the name of the company and myself to protect the privacy) # # A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x5ca957aa, pid=2036, tid=5660 # # JRE version: 6.0_32-b05 # Java VM: Java HotSpot(TM) Client VM (20.7-b02 mixed mode windows-x86 ) # Problematic frame: # C [MSVCR100D.dll+0x1157aa] # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the bug. # --------------- T H R E A D --------------- Current thread (0x0211a800): JavaThread "main" [_thread_in_native, id=5660, stack(0x00220000,0x00270000)] siginfo: ExceptionCode=0xc0000005, reading address 0xccccccc0 Registers: EAX=0xccccccac, EBX=0x44b618c8, ECX=0xccccccac, EDX=0x00000004 ESP=0x0026e788, EBP=0x0026e7b4, ESI=0x0026ea8c, EDI=0x0026e898 EIP=0x5ca957aa, EFLAGS=0x00010286 Top of Stack: (sp=0x0026e788) 0x0026e788: 4fc8e4ec 0026e898 0026ea8c 44b618c8 0x0026e798: ccccccac fffffffe 0026e33c 0026ea78 0x0026e7a8: 5ca99320 13430fa0 00000000 0026e898 0x0026e7b8: 5e7d271c cccccccc 0026e98c 0026ea8c 0x0026e7c8: 44b618c8 cccccccc cccccccc cccccccc 0x0026e7d8: cccccccc cccccccc cccccccc cccccccc 0x0026e7e8: cccccccc cccccccc cccccccc cccccccc 0x0026e7f8: cccccccc cccccccc cccccccc cccccccc Instructions: (pc=0x5ca957aa) 0x5ca9578a: 00 00 00 6a 04 e8 5c 3f f3 ff 83 c4 04 c7 45 fc 0x5ca9579a: 00 00 00 00 8b 45 08 83 e8 20 89 45 e4 8b 4d e4 0x5ca957aa: 8b 51 14 81 e2 ff ff 00 00 83 fa 04 74 41 8b 45 0x5ca957ba: e4 83 78 14 01 74 38 8b 4d e4 8b 51 14 81 e2 ff Register to memory mapping: EAX=0xccccccac is an unknown value EBX=0x44b618c8 is an oop {method} - klass: {other class} ECX=0xccccccac is an unknown value EDX=0x00000004 is an unknown value ESP=0x0026e788 is pointing into the stack for thread: 0x0211a800 EBP=0x0026e7b4 is pointing into the stack for thread: 0x0211a800 ESI=0x0026ea8c is pointing into the stack for thread: 0x0211a800 EDI=0x0026e898 is pointing into the stack for thread: 0x0211a800 Stack: [0x00220000,0x00270000], sp=0x0026e788, free space=313k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) C [MSVCR100D.dll+0x1157aa] operator delete+0x5a C [libosggen.dll+0x2271c] std::allocator<char>::deallocate+0x2c C [libosggen.dll+0x208f5] std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Tidy+0x75 C [libosggen.dll+0x197d5] std::basic_string<char,std::char_traits<char>,std::allocator<char> >::~basic_string<char,std::char_traits<char>,std::allocator<char> >+0x55 C [libosggen.dll+0x173a9] StartOsgDem+0x1ec9 C [libosggen.dll+0x29244] Java_foo_osgjni_core_GeneratorOSGImpl_startOsgDem+0xe4 j com.foo.osgjni.core.GeneratorOSGImpl.startOsgDem(DDLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z+0 j com.foo.osgjni.core.GeneratorOSGImpl.start(Ljava/io/File;Ljava/io/File;Ljava/io/File;Lcom/foo/osgjni/core/IOSGHandler;)Z+24 j com.foo.osgjni.core.GeneratorOSGImplTest.main([Ljava/lang/String;)V+67 v ~StubRoutines::call_stub V [jvm.dll+0xfad4b] V [jvm.dll+0x18c421] V [jvm.dll+0xfadcd] V [jvm.dll+0x95836] V [jvm.dll+0x9d778] V [jvm.dll+0xaf22b] C [javaw.exe+0x2155] C [javaw.exe+0x8614] C [kernel32.dll+0x1339a] BaseThreadInitThunk+0x12 C [ntdll.dll+0x39ed2] RtlInitializeExceptionChain+0x63 C [ntdll.dll+0x39ea5] RtlInitializeExceptionChain+0x36 Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) j com.foo.osgjni.core.GeneratorOSGImpl.startOsgDem(DDLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z+0 j com.foo.osgjni.core.GeneratorOSGImpl.start(Ljava/io/File;Ljava/io/File;Ljava/io/File;Lcom/foo/osgjni/core/IOSGHandler;)Z+24 j com.foo.osgjni.core.GeneratorOSGImplTest.main([Ljava/lang/String;)V+67 v ~StubRoutines::call_stub --------------- P R O C E S S --------------- Java Threads: ( => current thread ) 0x02991400 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=2704, stack(0x4acf0000,0x4ad40000)] 0x02982000 JavaThread "C1 CompilerThread0" daemon [_thread_blocked, id=4108, stack(0x4ac60000,0x4acb0000)] 0x02981000 JavaThread "Attach Listener" daemon [_thread_blocked, id=3516, stack(0x4abd0000,0x4ac20000)] 0x0297e000 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=6104, stack(0x4ab40000,0x4ab90000)] 0x0294e000 JavaThread "Finalizer" daemon [_thread_blocked, id=4320, stack(0x02120000,0x02170000)] 0x02949800 JavaThread "Reference Handler" daemon [_thread_blocked, id=5636, stack(0x00820000,0x00870000)] =>0x0211a800 JavaThread "main" [_thread_in_native, id=5660, stack(0x00220000,0x00270000)] Other Threads: 0x02944400 VMThread [stack: 0x00580000,0x005d0000] [id=5916] 0x02992c00 WatcherThread [stack: 0x4ad80000,0x4add0000] [id=2540] VM state:not at safepoint (normal execution) VM Mutex/Monitor currently owned by a thread: None Heap def new generation total 157248K, used 2795K [0x049b0000, 0x0f450000, 0x19f00000) eden space 139776K, 2% used [0x049b0000, 0x04c6ae28, 0x0d230000) from space 17472K, 0% used [0x0d230000, 0x0d230000, 0x0e340000) to space 17472K, 0% used [0x0e340000, 0x0e340000, 0x0f450000) tenured generation total 349568K, used 0K [0x19f00000, 0x2f460000, 0x449b0000) the space 349568K, 0% used [0x19f00000, 0x19f00000, 0x19f00200, 0x2f460000) compacting perm gen total 12288K, used 1736K [0x449b0000, 0x455b0000, 0x489b0000) the space 12288K, 14% used [0x449b0000, 0x44b620d8, 0x44b62200, 0x455b0000) No shared spaces configured. Code Cache [0x029b0000, 0x02a20000, 0x049b0000) total_blobs=122 nmethods=7 adapters=60 free_code_cache=33102592 largest_free_block=0 Dynamic libraries: 0x00400000 - 0x00425000 C:\DEV\BIN\Java\jdk1.6.0_32\bin\javaw.exe 0x77570000 - 0x776f0000 C:\Windows\SysWOW64\ntdll.dll 0x75f90000 - 0x760a0000 C:\Windows\syswow64\kernel32.dll 0x75120000 - 0x75166000 C:\Windows\syswow64\KERNELBASE.dll 0x74c00000 - 0x74c71000 C:\Windows\SysWOW64\SYSFER.DLL 0x75260000 - 0x75300000 C:\Windows\syswow64\ADVAPI32.dll 0x76c20000 - 0x76ccc000 C:\Windows\syswow64\msvcrt.dll 0x76ad0000 - 0x76ae9000 C:\Windows\SysWOW64\sechost.dll 0x760a0000 - 0x76190000 C:\Windows\syswow64\RPCRT4.dll 0x750c0000 - 0x75120000 C:\Windows\syswow64\SspiCli.dll 0x750b0000 - 0x750bc000 C:\Windows\syswow64\CRYPTBASE.dll 0x76d50000 - 0x76e50000 C:\Windows\syswow64\USER32.dll 0x76e50000 - 0x76ee0000 C:\Windows\syswow64\GDI32.dll 0x767a0000 - 0x767aa000 C:\Windows\syswow64\LPK.dll 0x761c0000 - 0x7625d000 C:\Windows\syswow64\USP10.dll 0x76530000 - 0x76590000 C:\Windows\system32\IMM32.DLL 0x76af0000 - 0x76bbc000 C:\Windows\syswow64\MSCTF.dll 0x7c340000 - 0x7c396000 C:\DEV\BIN\Java\jdk1.6.0_32\jre\bin\msvcr71.dll 0x6d8c0000 - 0x6db6f000 C:\DEV\BIN\Java\jdk1.6.0_32\jre\bin\client\jvm.dll 0x74820000 - 0x74852000 C:\Windows\system32\WINMM.dll 0x736b0000 - 0x736fc000 C:\Windows\system32\apphelp.dll 0x6d870000 - 0x6d87c000 C:\DEV\BIN\Java\jdk1.6.0_32\jre\bin\verify.dll 0x6d3d0000 - 0x6d3ef000 C:\DEV\BIN\Java\jdk1.6.0_32\jre\bin\java.dll 0x6d8b0000 - 0x6d8bf000 C:\DEV\BIN\Java\jdk1.6.0_32\jre\bin\zip.dll 0x5e7b0000 - 0x5e7f7000 C:\DEV\src\test\Debug\libosggen.dll 0x5e160000 - 0x5e6c9000 C:\Program Files\VIRTUALPLANETBUILDER\bin\vpb.dll 0x751c0000 - 0x751f5000 C:\Windows\syswow64\WS2_32.dll 0x75f50000 - 0x75f56000 C:\Windows\syswow64\NSI.dll 0x5df60000 - 0x5e156000 C:\Program Files\OpenSceneGraph\bin\osg80-osg.dll 0x5df50000 - 0x5df5a000 C:\Program Files\OpenSceneGraph\bin\ot12-OpenThreads.dll 0x74e10000 - 0x74ecf000 C:\Windows\system32\MSVCR100.dll 0x6ee80000 - 0x6eee9000 C:\Windows\system32\MSVCP100.dll 0x5de80000 - 0x5df48000 C:\Windows\system32\OPENGL32.dll 0x5de50000 - 0x5de72000 C:\Windows\system32\GLU32.dll 0x4afd0000 - 0x4b0b7000 C:\Windows\system32\DDRAW.dll 0x6e9b0000 - 0x6e9b6000 C:\Windows\system32\DCIMAN32.dll 0x76260000 - 0x763fd000 C:\Windows\syswow64\SETUPAPI.dll 0x75f60000 - 0x75f87000 C:\Windows\syswow64\CFGMGR32.dll 0x76f80000 - 0x7700f000 C:\Windows\syswow64\OLEAUT32.dll 0x77010000 - 0x7716c000 C:\Windows\syswow64\ole32.dll 0x751a0000 - 0x751b2000 C:\Windows\syswow64\DEVOBJ.dll 0x71250000 - 0x71263000 C:\Windows\system32\dwmapi.dll 0x5dd30000 - 0x5de43000 C:\Program Files\OpenSceneGraph\bin\osg80-osgUtil.dll 0x5dca0000 - 0x5dd0d000 C:\Program Files\OpenSceneGraph\bin\osg80-osgSim.dll 0x5d900000 - 0x5d943000 C:\Program Files\OpenSceneGraph\bin\osg80-osgText.dll 0x5cf40000 - 0x5cff5000 C:\Program Files\OpenSceneGraph\bin\osg80-osgDB.dll 0x4b0c0000 - 0x4b0d8000 C:\projects\OpenSceneGraph-3.0.1\3rdParty\bin\zlib1.dll 0x74b50000 - 0x74bf3000 C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_50934f2ebcb7eb57\MSVCR90.dll 0x5ce60000 - 0x5ce91000 C:\Program Files\OpenSceneGraph\bin\osg80-osgTerrain.dll 0x5ce30000 - 0x5ce5a000 C:\Program Files\OpenSceneGraph\bin\osg80-osgFX.dll 0x5cda0000 - 0x5ce24000 C:\Program Files\OpenSceneGraph\bin\osg80-osgViewer.dll 0x5cd60000 - 0x5cd9e000 C:\Program Files\OpenSceneGraph\bin\osg80-osgGA.dll 0x5cb00000 - 0x5cbb7000 C:\Windows\system32\MSVCP100D.dll 0x5c980000 - 0x5caf2000 C:\Windows\system32\MSVCR100D.dll 0x5dc80000 - 0x5dc9d000 C:\Program Files\OpenSceneGraph\bin\osgPlugins-3.0.1\osgdb_osg.dll 0x76400000 - 0x76405000 C:\Windows\system32\PSAPI.DLL VM Arguments: jvm_args: -Xcheck:jni -Xms512m -Xmx1024m -Dfile.encoding=Cp1252 java_command: com.foo.osgjni.core.GeneratorOSGImplTest Launcher Type: SUN_STANDARD Environment Variables: JAVA_HOME=C:\DEV\BIN\Java\jdk1.6.0_32 CLASSPATH=.;C:\Program Files (x86)\QuickTime\QTSystem\QTJava.zip PATH=C:/DEV/BIN/Java/jdk1.6.0_32/bin/../jre/bin/client;C:/DEV/BIN/Java/jdk1.6.0_32/bin/../jre/bin;C:/DEV/BIN/Java/jdk1.6.0_32/bin/../jre/lib/i386;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\DMIX;C:\DEV\BIN\apache-ant-1.8.2\bin;C:\Program Files (x86)\QuickTime\QTSystem\;C:\DEV\BIN\apache-maven-3.0.3\bin;C:\DEV\BIN\Java\jdk1.6.0_32\bin;C:\DEV\BIN\Java\jdk1.6.0_32\jre\bin;C:\MinGW\bin;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Windows\Microsoft.NET\Framework\v4.0.30319;C:\Program Files\TortoiseSVN\bin;C:\DEV\BIN\Geoinformatica\bin;OSGHOME\bin;OSGHOME\lib;OSGHOME;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\DMIX;C:\DEV\BIN\apache-ant-1.8.2\bin;C:\Program Files (x86)\QuickTime\QTSystem\;C:\DEV\BIN\apache-maven-3.0.3\bin;C:\DEV\BIN\Java\jdk1.6.0_32\bin;C:\DEV\BIN\Java\jdk1.6.0_32\jre\bin;C:\MinGW\bin;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Windows\Microsoft.NET\Framework\v4.0.30319;C:\Program Files\TortoiseSVN\bin;OSGHOME\bin;OSGHOME\lib;OSGHOME;C:\Program Files\OpenSceneGraph\bin;C:\projects\OpenSceneGraph-3.0.1\3rdParty\bin;C:\Program Files\VIRTUALPLANETBUILDER\bin;C:\DEV\BIN\eclipse-indigo-32bit; USERNAME=foo OS=Windows_NT PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 37 Stepping 5, GenuineIntel --------------- S Y S T E M --------------- OS: Windows 7 , 64 bit Build 7601 Service Pack 1 CPU:total 4 (2 cores per cpu, 2 threads per core) family 6 model 37 stepping 5, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, ht Memory: 4k page, physical 4052376k(1527824k free), swap 8102904k(4747124k free) vm_info: Java HotSpot(TM) Client VM (20.7-b02) for windows-x86 JRE (1.6.0_32-b05), built on Apr 5 2012 13:50:34 by "java_re" with MS VC++ 7.1 (VS2003) time: Tue May 08 17:15:35 2012 elapsed time: 0 seconds On Fri, May 4, 2012 at 4:02 PM, Rafa Gaitan <[email protected]> wrote: > Hi Sean, > > We have made lot of JNI stuff in osgVirtualPlanets. Is a the GIS > library for gvSIG3D that we developed. > > svn co https://devel.gvsig.org/svn/osgvp/trunk > > The wrappers are inside wrappers directory. Is not exactly what are > you looking for, but maybe you find inspiration in the code. > > Cheers, > Rafa. > > > 2012/5/5 Sean K <[email protected]>: >> I am looking to build a Java wrapper with JNI around the code which >> basically exists inside of osgdem.cpp. >> >> The bulk of that code resides in vpb.dll and osgDB.dll. >> >> Anybody tried this? I am guessing others have already done this. >> >> I also want to send back the console output back to the java caller >> via a java callback >> >> basically, >> >> if I wrote a JNI class named OsgDem.java >> >> I would write code my OsgDemTest.java like this: >> >> class MyOsgHandler implements OsgHander { >> >> @Override >> void OnStatus (String output) { >> System.out.println(output); >> } >> >> @Override >> void OnEnd (boolean success, String resultMsg) { >> if (success) { >> System.out.println("good"); >> } else { >> System.out.println("bad"); >> } >> } >> } >> >> @Test >> public void testOsgdem() { >> .... >> Properties global = new Properties(); >> >> global.load("osgdem.properties"); >> OsgDem generator = new OsgDem(global); >> generator.start(handler, inputTerrainPath, >> inputTexturePath, outputFilePath); >> >> } >> >> >> Anybody have any JNI code that I can start with to build my OsdDem? >> _______________________________________________ >> osg-users mailing list >> [email protected] >> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > > > -- > Rafael Gaitán Linares > CTO at Mirage Technologies S.L - http://www.mirage-tech.com > gvSIG3D Developer - http://gvsig3d.blogspot.com > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

