[vtkusers] MakeCurrent Problems with .NET

Andrew Dolgert ajd27 at cornell.edu
Fri May 28 09:20:29 EDT 2004


According to the documentation for wglMakeCurrent(), calls from multiple
threads to the render window using the same rendering context are allowed to
fail.  It is a kindness of the NVidia driver that it permits more than one
thread to use the same rendering context concurrently.

The sure-fire way to fix your code is to ensure only a single thread
renders.  This may require putting a worker thread between your GUI and VTK.
Supposedly, even this is not guaranteed to work in later versions of .NET
because there is no guarantee that a logical thread in .NET always
corresponds to the same Win32 thread.  For current releases, they are always
the same Win32 thread.

Because the render window contains a single rendering context as an instance
member, the quickest way to fix the code may be to have a thread release its
rendering context when it finishes rendering so that the next thread can
take it.  This is done by having the thread call wglMakeCurrent(NULL,NULL).
Only the thread that owns the context can release its context.  No other
thread can take it away.  A comment in the code warns this may be slow, but
it's worth a try.

Another way to change the render window code to fix the problem would be to
put an array of rendering contexts in the render window and choose one
depending on the calling thread.  This still wouldn't permit two threads to
render at the same time, just two threads to render at different times in
their own rendering contexts.  While the logic of MakeCurrent() looks simple
enough, it seems from the newsgroup that it took a while to get right, so
one would have to take care with increasing its complexity.

Drew Dolgert


> -----Original Message-----
> From: vtkusers-bounces at vtk.org 
> [mailto:vtkusers-bounces at vtk.org] On Behalf Of de Boer Ingo
> Sent: Friday, May 28, 2004 2:12 AM
> To: Drew Skillman; vtkusers at vtk.org
> Subject: RE: [vtkusers] MakeCurrent Problems with .NET
> 
> 
> Hi Drew...
> 
> > Direct calls to MakeCurrent() fail as well.  Initial single 
> threaded 
> > prototype of code worked fine with Windows MFC.
> I have experienced the same and concluded that it is because 
> of my graphics card. An MDI application with overlapping 
> windows crashes in MakeCurrent() with ATI Radeon cards with 
> Catalyst 4.x . But with NVidia GeForce it works perfect...
> 
> I haven't found a solution myself...
> 
> greets
>   Ingo
> 
> ---
> Dr.-Ing. Ingo H. de Boer
> 
> Polytec GmbH
> Polytec-Platz 1-7, 76337 Waldbronn, Germany
> phone: ++49 7243 604 106
> fax  : ++49 7243 604 255
>  
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at: 
> <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
> 
> 
> 




More information about the vtkusers mailing list