[vtkusers] AWT + SWT + Event Loops (was Re: VTK6 and Java Cone Example 5)

Sebastien Jourdain sebastien.jourdain at kitware.com
Wed Aug 14 12:42:57 EDT 2013


Hi Ric,

I work mostly in C++ with ParaView, but I've used VTK in the past with Java
and multi-threading without much trouble. But once again, I'm not talking
about SWT, just pure Swing/AWT.
My question related to the crash was on the AWT/Swing example not SWT.

Seb


On Wed, Aug 14, 2013 at 11:53 AM, rkwright <rkwright at geofx.com> wrote:

> Seb,
>
> Yes, the crash is the same. Sometimes it isn't even at close time - the
> app will hang then crash.  When I have been able to pause inside and look
> or get a look at the stack it is buried way down in SWT or some inner
> message loop in VTK.  I strongly suspect that it is some threading issue
> between VTK and SWT.  You mentioned that VTK is not thread–safe while
> Eclipse and SWT use LOTS of threads.  Like you say, if you stick with VTK
> alone (in ObjectiveC and/or C++) it is fine.
>
> So if I want to write in Java and use Eclipse I a few choices:
>
>    - Give up on using Java and Eclipse, just use Xcode and Objective C/C++
>    - Carefully use VTK, avoiding any danger spots (e.g. Interactors) but
>    I won't know what to avoid until I get there
>    - Abandon trying to use VTK and go back to my VTK equivalent which is
>    far more primitive.
>
> My problem is that I don't want to fight the tools.  I don’t WANT to write
> rendering systems, etc.  Been there, done that (I've written parts 2
> PostScript interpreters, was part of the SVG Viewer team at Adobe,
> Illustrator, etc.).  I'm looking for a system I can just use and not have
> to fix or work around.  It may be that the message is stop fighting and
> accept using Xcode.  Is that what you work in?  Xcode and Objective C/C++?
>
> Thanks
> Ric
>
>
> From: "Sebastien Jourdain-2 [via VTK]" <[hidden email]<http://user/SendEmail.jtp?type=node&node=5722740&i=0>
> >
> Date: Wednesday, August 14, 2013 10:41 AM
>
> To: Ric Wright <[hidden email]<http://user/SendEmail.jtp?type=node&node=5722740&i=1>
> >
> Subject: Re: AWT + SWT + Event Loops (was Re: VTK6 and Java Cone Example
> 5)
>
> Hi Ric,
>
> I have no experience with SWT, so I can't really help you here, but I can
> ensure you that VTK works just fine on Mac OS X with Java 6 and
> interaction. In fact, I never had any crash at close time.
>
> Does the sample code from the vtk.jar crash in the same manner at close
> time ?
>
> Seb
>
>
> On Wed, Aug 14, 2013 at 11:08 AM, rkwright <[hidden email]<http://user/SendEmail.jtp?type=node&node=5722739&i=0>
> > wrote:
>
>> Sebastien,
>>
>> (BTW, thank you *very* much for your patience in answering my questions
>> in such timely fashion).
>>
>> I didn't see the SWT option when I built VTK the first time.  However, I
>> took a break and quickly built an Eclipse plugin using the code in
>> wrapping/java/vtk/rendering.  I created a view based on the
>> swtConeRenderer.java code, substituting the parent SWT composite passed to
>> the ViewPart creation step, passing that composite to the constructor of
>> vtkSwtComponent.  It ALMOST works except that it creates a wholly new
>> window outside the actual Eclipse view.  And that view works, complete with
>> mouse-wheel scaling.  BUT, when I close that view …  it crashes Eclipse,
>> *exactly* as it does in the other demo I put together using the SWT_AWT
>> bridge. Same message, same crash in Eclipse.  Clearly, something goes
>> horribly awry down in the bowels of the native code in SWT.
>>
>> So I will continue to experiment with VTK but avoid anything to do with
>> interactors.  But I return to my earlier question: Am I likely to run into
>> similar problems or is it largely or wholly in the interactors that VTK
>> starts/handles its own event loops?  So far the only problems I have seen
>> are when interactors are involved (though my experience is rather limited,
>> of course).
>>
>> Thanks
>> Ric
>>
>>
>> From: "Sebastien Jourdain-2 [via VTK]" <[hidden email]<http://user/SendEmail.jtp?type=node&node=5722738&i=0>
>> >
>> Date: Wednesday, August 14, 2013 9:53 AM
>>
>> To: Ric Wright <[hidden email]<http://user/SendEmail.jtp?type=node&node=5722738&i=1>
>> >
>> Subject: Re: AWT + SWT + Event Loops (was Re: VTK6 and Java Cone Example
>> 5)
>>
>> You need to build VTK with the SWT component ON. Moreover, vtkRenderWIndowInteractor
>> does not spawn a new event loop as VTK is NOT thread safe.
>>
>>
>> On Wed, Aug 14, 2013 at 10:31 AM, rkwright <[hidden email]<http://user/SendEmail.jtp?type=node&node=5722733&i=0>
>> > wrote:
>>
>>> I have been working through the samples in the jar. The only failure so
>>> far is the vtkRenderWindowInteractor.
>>>
>>> I was not aware of a SWT component in VTK.  I see a Java file
>>> vtkSwtComponent.java but it isn't clear to me that it is going to solve my
>>> problems.   There are two issues I see:
>>>
>>>    - vtkSwtComponent appears to use the SWT OpenGL canvas widget.  This
>>>    is largely unsupported in SWT and was half-broken last time I looked at it.
>>>     I gave up on it long ago and turned to JOGL embedding in SWT via the
>>>    bridge (which works for me at present)
>>>    - It's not clear how this would solve the other issue
>>>    where vtkRenderWIndowInteractor spawns its own event loop and that causes
>>>    problems with SWT – or does vtkRenderWIndowInteractor not use any AWT
>>>    utilities or methods?
>>>
>>> I'll experiment with the vtkSwtComponent (I see one simple example file,
>>> swtConeRendering.java) and see if that helps. Though there is no SWT
>>> support in vtk.jar so I'll guess I'll have to include the SWT files
>>> directly in my project.
>>>
>>> Thanks for your advice.
>>>
>>> Ric
>>>
>>> BTW, I am running Apple's Java 1.6.0_51-b11-457-11M4509. 64 bit
>>>
>>> From: "Sebastien Jourdain-2 [via VTK]" <[hidden email]<http://user/SendEmail.jtp?type=node&node=5722724&i=0>
>>> >
>>> Date: Wednesday, August 14, 2013 8:42 AM
>>> To: Ric Wright <[hidden email]<http://user/SendEmail.jtp?type=node&node=5722724&i=1>
>>> >
>>> Subject: Re: AWT + SWT + Event Loops (was Re: VTK6 and Java Cone
>>> Example 5)
>>>
>>> Just read the sample codes that are provided in the vtk.jar or in the
>>> Source code under Wrapping/Java/vtk/sample, they should be pretty strait
>>> forward.
>>> Moreover, VTK do provide a SWT component for rendering if you build it,
>>> so you shouldn't have any event loop issue...
>>>
>>> Seb
>>>
>>>
>>> On Wed, Aug 14, 2013 at 9:30 AM, Ric Wright <[hidden email]<http://user/SendEmail.jtp?type=node&node=5722710&i=0>
>>> > wrote:
>>>
>>>> So did some more spelunking and it looks like this is just a basic
>>>> incompatibility for SWT and AWT – in the specific case where AWT is trying
>>>> to start their own event loop once SWT has started.  Previously, in my
>>>> other work, I handled events on my own – I didn't ask or expect AWT to
>>>> start or manage it's own events. I used AWT basically to host the OpenGL
>>>> canvas (based on JOGL).  But when one invokes the vtkRenderWIndowInteractor
>>>> an event loop IS spawned and the causes various weird problems.
>>>>
>>>> There is a fairly long summary of some of the issues here:
>>>>
>>>> http://marc.info/?l=openjdk-awt-dev&m=135818602009136&w=2
>>>>
>>>> So the question that comes to my mind is how dependent is the rest of
>>>> VTK on starting its own event loops?  I.e. Can I use the rest of VTK and
>>>> its pipeline to perform graphics, manage datasets, etc.  I am willing to
>>>> give up the Interactor and its mimicking of trackball if everything else is
>>>> likely to work.  But if spawning its own event loop(s) is intrinsic to how
>>>> most of VTK works then I'm probably dead in the water.
>>>>
>>>> Thoughts or suggestions?
>>>>
>>>> Thanks
>>>> Ric
>>>>
>>>>
>>>> From: Ric Wright <[hidden email]<http://user/SendEmail.jtp?type=node&node=5722710&i=1>
>>>> >
>>>>
>>>> Date: Tuesday, August 13, 2013 12:59 PM
>>>> To: Sebastien Jourdain <[hidden email]<http://user/SendEmail.jtp?type=node&node=5722710&i=2>
>>>> >
>>>> Cc: Sean McBride <[hidden email]<http://user/SendEmail.jtp?type=node&node=5722710&i=3>>,
>>>> vtkusers <[hidden email]<http://user/SendEmail.jtp?type=node&node=5722710&i=4>
>>>> >
>>>>
>>>> Subject: Re: [vtkusers] VTK6 and Java Cone Example 5
>>>>
>>>> An update on this.  I ported over some of my other Eclipse work and
>>>> adapted it to VTK.  It is pushed to my account on github and there is a
>>>> writeup here:  http://rkwright.github.io/geofx-pages/vtkview.html.
>>>>  There are 3 articles in there.  The latest rev of the code is here:
>>>> https://github.com/rkwright/vtkscene in the develop branch.
>>>>
>>>> Mostly, it works great.  However, when I tried the fifth cone example,
>>>> which has the problematic vtkRenderWindowInteractor, I ran into similar
>>>> problems as before.  I instantiated it with a valid vtkPanel.RenderWindow
>>>> but it still goes off into the ozone, sometimes crashing the native
>>>> vtkOpenGL dylib.
>>>>
>>>> I'm going to skip the interactor for now and move on to see if I run
>>>> into more problems. If not, I can probably live without that widget but the
>>>> problems there might be symptomatic of deeper problems on OSX 64 bit
>>>> systems.
>>>>
>>>> Any further suggestions would be welcome.
>>>>
>>>> Thanks
>>>> Ric
>>>>
>>>>
>>>> From: Sebastien Jourdain <[hidden email]<http://user/SendEmail.jtp?type=node&node=5722710&i=5>
>>>> >
>>>>
>>>> Date: Tuesday, August 6, 2013 8:56 AM
>>>> To: Ric Wright <[hidden email]<http://user/SendEmail.jtp?type=node&node=5722710&i=6>
>>>> >
>>>> Cc: Sean McBride <[hidden email]<http://user/SendEmail.jtp?type=node&node=5722710&i=7>>,
>>>> vtkusers <[hidden email]<http://user/SendEmail.jtp?type=node&node=5722710&i=8>
>>>> >
>>>>
>>>> Subject: Re: [vtkusers] VTK6 and Java Cone Example 5
>>>>
>>>> In Java you should use the Java specific classes anyway like
>>>> vtkPanel/vtkCanvas or the new version of them used in the vtk.sample
>>>> package of the vtk.jar...
>>>>
>>>> The purpose of those example was to show the possible match between the
>>>> different languages...
>>>>
>>>> Nothing more I believe,
>>>>
>>>> Seb
>>>>
>>>>
>>>> On Tue, Aug 6, 2013 at 8:52 AM, Ric Wright <[hidden email]<http://user/SendEmail.jtp?type=node&node=5722710&i=9>
>>>> > wrote:
>>>>
>>>>> Ah, OK.  Well, I don't know what to do here.  Is this happening to
>>>>> others?
>>>>>  Should I file a bug?  Just try to work around it by not using
>>>>> RenderWindowInteractors (sounds kind of lame).  Or?
>>>>>
>>>>> Suggestions?
>>>>>
>>>>> Thanks
>>>>> Ric
>>>>>
>>>>>
>>>>> On 8/5/13 4:15 PM, "Sean McBride" <[hidden email]<http://user/SendEmail.jtp?type=node&node=5722710&i=10>>
>>>>> wrote:
>>>>>
>>>>> >On Mon, 5 Aug 2013 16:10:55 -0500, Ric Wright said:
>>>>> >
>>>>> >>Well, a little playing around didn't seem to help, but I am frankly
>>>>> not
>>>>> >>an
>>>>> >>expert on threads.  However, it seems to me that the source of the
>>>>> >>problem
>>>>> >>is that the vtkRenderWindowInteractor gets initialized then the
>>>>> start()
>>>>> >>method creates an event loop that is monitored by the
>>>>> >>vtkRenderWindowInteractor.  I suspect that start() method spawns a
>>>>> new
>>>>> >>thread to listen to the events and it is the spawning of that thread
>>>>> that
>>>>> >>causes the exception.
>>>>> >
>>>>> >VTK's Cocoa classes never create any threads.
>>>>> >
>>>>> >Cheers,
>>>>> >
>>>>> >--
>>>>> >____________________________________________________________
>>>>> >Sean McBride, B. Eng                 [hidden email]<http://user/SendEmail.jtp?type=node&node=5722710&i=11>
>>>>>
>>>>> >Rogue Research                        www.rogue-research.com
>>>>> >Mac Software Developer              Montréal, Québec, Canada
>>>>> >
>>>>> >
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>> _______________________________________________
>>> 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
>>>
>>>
>>> ------------------------------
>>>  If you reply to this email, your message will be added to the
>>> discussion below:
>>>
>>> http://vtk.1045678.n5.nabble.com/VTK6-and-Java-Examples-tp5722474p5722710.html
>>>  To unsubscribe from VTK6 and Java Examples, click here.
>>> NAML<http://vtk.1045678.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>>
>>> ------------------------------
>>> View this message in context: Re: AWT + SWT + Event Loops (was Re: VTK6
>>> and Java Cone Example 5)<http://vtk.1045678.n5.nabble.com/VTK6-and-Java-Examples-tp5722474p5722724.html>
>>> Sent from the VTK - Users mailing list archive<http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html>at Nabble.com.
>>>
>>> _______________________________________________
>>> 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
>>
>>
>> ------------------------------
>>  If you reply to this email, your message will be added to the
>> discussion below:
>>
>> http://vtk.1045678.n5.nabble.com/VTK6-and-Java-Examples-tp5722474p5722733.html
>>  To unsubscribe from VTK6 and Java Examples, click here.
>> NAML<http://vtk.1045678.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>> ------------------------------
>> View this message in context: Re: AWT + SWT + Event Loops (was Re: VTK6
>> and Java Cone Example 5)<http://vtk.1045678.n5.nabble.com/VTK6-and-Java-Examples-tp5722474p5722738.html>
>> Sent from the VTK - Users mailing list archive<http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html>at Nabble.com.
>>
>> _______________________________________________
>> 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
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://vtk.1045678.n5.nabble.com/VTK6-and-Java-Examples-tp5722474p5722739.html
>  To unsubscribe from VTK6 and Java Examples, click here.
> NAML<http://vtk.1045678.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
> ------------------------------
> View this message in context: Re: AWT + SWT + Event Loops (was Re: VTK6
> and Java Cone Example 5)<http://vtk.1045678.n5.nabble.com/VTK6-and-Java-Examples-tp5722474p5722740.html>
> Sent from the VTK - Users mailing list archive<http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html>at Nabble.com.
>
> _______________________________________________
> 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/20130814/d616185f/attachment.htm>


More information about the vtkusers mailing list