[vtkusers] VTK + OSGi & RenderCreate native method

Thiébault Benoît dev at artenum.com
Fri Oct 29 10:02:16 EDT 2010


Hi everyone

as explained in this other post (http://www.vtk.org/pipermail/vtkusers/2010-October/112895.html) and in my article (http://dev.artenum.com/blog/ben/posts/osgi_vtk_and_macosx), I have embedded VTK dynamic libraries inside an OSGi bundle.

I have the same error message than Jérémie who did not embed the libraries in the JAR bundle file but passed the DYLD_LIBRARY_PATH to the external libraries directory.

However, since I used the -Xcheck:jni option, I have a more verbose error:

WARNING in native method: JNI call made with exception pending
	at vtk.vtkPanel.RenderCreate(Native Method)
	at vtk.vtkPanel.Render(vtkPanel.java:166)
	- locked <1060ffa88> (a vtk.vtkPanel)
	at vtk.vtkPanel.paint(vtkPanel.java:189)
	at sun.awt.RepaintArea.paintComponent(RepaintArea.java:276)
	at sun.awt.RepaintArea.paint(RepaintArea.java:241)
	at apple.awt.ComponentModel.handleEvent(ComponentModel.java:263)
	at java.awt.Component.dispatchEventImpl(Component.java:4790)
	at java.awt.Component.dispatchEvent(Component.java:4544)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:635)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
FATAL ERROR in native method: Bad global or local ref passed to JNI
	at vtk.vtkPanel.RenderCreate(Native Method)
	at vtk.vtkPanel.Render(vtkPanel.java:166)
	- locked <1060ffa88> (a vtk.vtkPanel)
	at vtk.vtkPanel.paint(vtkPanel.java:189)
	at sun.awt.RepaintArea.paintComponent(RepaintArea.java:276)
	at sun.awt.RepaintArea.paint(RepaintArea.java:241)
	at apple.awt.ComponentModel.handleEvent(ComponentModel.java:263)
	at java.awt.Component.dispatchEventImpl(Component.java:4790)
	at java.awt.Component.dispatchEvent(Component.java:4544)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:635)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Invalid memory access of location 0x0 rip=0x1010af1f4
./ben.sh: line 11: 23453 Abort trap              java -Xcheck:jni -jar org.eclipse.osgi_3.6.0.v20100517.jar -console

This is not a ClassLoader issue. In OSGi, each bundle has its own classloader. My VTK bundle both loads the vtk.jar and the native libraries and should thus use the same classloader to perform both.

To be sure about it, I added in the vtkNativeLibrary.java class a new method, called LoadAllNativeLibrariesForOSGi(), that performs all the System.loadLibrary calls that I previously did in my OSGi BundleActivator (this way, it is executed in the same ClassLoader that the one that loaded vtk.jar). I re-compiled VTK and ended with the same error message.

Do you have any idea what could cause this problem?
I read here http://www.vtk.org/pipermail/vtkusers/2007-February/089476.html that it could come from a compatibility issue with OSX Cocoa. The solution suggested there was to compile using Carbon instead of Cocoa. But:
- this is not a satisfactory solution, as Carbon is less and less supported by Apple
- it is not possible on the latest versions of MacOSX, as Java is 64bits only and Carbon cannot be compiled in 64bits

Any suggestion? :-)

Kind regards,

Benoît

>> De : Gerrick Bivins <gbivins at objectreservoir.com>
>> Date : 11 octobre 2010 17:31:40 HAEC
>> À : Jérémie Turbet <jet at artenum.com>
>> Cc : vtkusers at vtk.org
>> Objet : Rép : [vtkusers] VTK + OSGi & RenderCreate native method
>> 
>> Hi,
>> I haven't done osgi specifically, but have created a netbeans platform module (similar concept, see this link http://wiki.netbeans.org/OSGiAndNetBeans#NetBeans_and_OSGi) that wraps vtk. 
>> 
>> I ended up forcing the load of the required libs for my app when the module loads via the module installer (not sure what the equivalent is in osgi terms,bundle activator maybe?) similar to the technique described here for loading jogl in a netbeans application:
>> http://forums.netbeans.org/viewtopic.php?t=16272
>> 
>> I had issues on mac where it wouldn't load the libraries unless I specified the 
>> arch type of the libs matched that of the jvm. Also, had some weirdness with the suffixes of the libs (jnilib vs dylib see :http://forums.netbeans.org/ntopic16681.html) 
>> 
>> On windows or linux, things worked as expected (ie how it was described in the docs) so you may want to try your module on one of those platforms before trying on OSX.
>> 
>> biv
>> 
>> 
>> 
>> 
>> On Mon, Oct 11, 2010 at 7:29 AM, Jérémie Turbet <jet at artenum.com> wrote:
>> 	Hi all,
>> 
>> Before my question, a small description of the context: 
>>   I'm trying to create an OSGi bundle displaying some VTK stuff using Java wrapping.
>>   The service class is a simple POJO (OSGi classes and configuration are managed using iPOJO). when I test it out of OSGi environment, it works well, load libraries, and displays a beautiful 3D cone in a window. When I ask to the OSGi container to launch my service, libraries are loaded, objects are instantiated, but as soon as I ask a rendering (using vtkPanel::Render() ) I get this error "Invalid memory access of location 0x0 rip=0x10109cdcc" which looks like a null pointer exception...
>>   
>>   For a debugging purpose, I have made a copy/paste of vtkPanel class into MyVtkPanel (which is in my application package) and replace the vtkPanel by MyVtkPanel into my small test application. I expected no change in the resulting behaviour, instead I have an unsatisfied link error on RenderCreate() method.
>> This method is declared as native, but my DYLD_LIBRARY_PATH points to the VTK libs. I thought it should have found this method....
>> 
>> Does someone has an idea of why this error occurs, is there some access restriction due to the class location (which is the only change... I guess...) ?
>> 
>> to summarise:
>> vtkPanel panel = new vtkPanel()
>> panel.Render()
>> works fine
>>  
>> vtkPanel panel = new vtkPanel()
>> panel.Render()
>> leads to "Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: test.vtk.impl.MyVtkPanel.RenderCreate(Lvtk/vtkRenderWindow;)I
>> 	at test.vtk.impl.MyVtkPanel.RenderCreate(Native Method)"
>> 
>> 
>> >nm libvtkRenderingJava.dylib  | grep RenderCreate
>> 0000000000047b9b T _Java_vtk_vtkPanel_RenderCreate
>> 
>> Tested under Mac OSX snow leopard with VTK 5.40, 5.6.0 and 5.6.1
>> 
>> 	Regards,
>> 
>> 		JeT
>> 
>> PS: if someone has some experience with VTK + OSGi, some tips would be of great help. I'm a little bit stuck with it...
>> 
>> _______________________________________________
>> Powered by www.kitware.com
>> 
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>> 
>> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>> 
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>> 
>> 
>> _______________________________________________
>> Powered by www.kitware.com
>> 
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>> 
>> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>> 
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
> 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101029/ca605da8/attachment.htm>


More information about the vtkusers mailing list