[vtkusers] Running into problems with M$ dlls, VTK and objectfactories!!!

Carsten Kübler kuebler at ira.uka.de
Thu Aug 9 12:01:33 EDT 2001


Hej,

I made a object factory to combine vtk and qt. Now we got a problem
under NT4.0.
My object factory replaces vtkRenderWindow, vtkRenderWindowInteractor,
etc....
and VTK (3.2) is build as one vtkdll.dll (no changes)

The problem:
We create a vtkRenderWindow and add vtkCubeSource.
If we try to pick the cube (pressing 'p') we got a memory heap error.
The same programm on an SGI works fine and the same programm under NT
without my objectfactory
works fine, too.

The reason is, we can't execute renderer->GetZ(150, 400); under NT.

Here is the code from vtkRenderer:

     float vtkRenderer::GetZ (int x, int y)
     {
       float *zPtr;
       float z;

       zPtr = this->RenderWindow->GetZbufferData (x, y, x, y);
       if (zPtr)
         {
         z = *zPtr;
         delete [] zPtr;
         }
       else
         {
         z = 1.0;
         }
       return z;
     }

and the corresponding method of my QGLWindow (its a one to one copy from
vtkopenglrenderwindow resp. vtkwin32renderwindow):

     float *vtkQGLRenderWindow::GetZbufferData( int x1, int y1, int
     x2, int y2  )
     {
       int             y_low, y_hi;
       int             x_low, x_hi;
       int             width, height;
       float           *z_data = NULL;

       // set the current window
       this->MakeCurrent();

       if (y1 < y2)
         {
         y_low = y1;
         y_hi  = y2;
         }
       else
         {
         y_low = y2;
         y_hi  = y1;
         }

       if (x1 < x2)
         {
         x_low = x1;
         x_hi  = x2;
         }
       else
         {
         x_low = x2;
         x_hi  = x1;
         }

       width =  abs(x2 - x1)+1;
       height = abs(y2 - y1)+1;

       z_data = new float[width*height];

       // Turn of texturing in case it is on - some drivers have a
     problem
       // getting / setting pixels with texturing enabled.
       glDisable( GL_TEXTURE_2D );

       glPixelStorei( GL_PACK_ALIGNMENT, 1 );
       glReadPixels( x_low, y_low,
       width, height,
       GL_DEPTH_COMPONENT, GL_FLOAT,
       z_data );

       return z_data;
     }

Why can't we execute "renderer->GetZ (150, 400);"?

The renderwindow was created in the application and the renderer is
created in the vtkdll.dll.
The renderwindow allocates memory "z_data = new float[width*height]" but
the renderer
isn't allowed to free the memory "delete [] zPtr;". My solution was that
I add a method NewMemory
in the vtkObjectFactory which allocates memory on the heap of the dll
and recompile vtkdll.dll.

     char *vtkObjectFactory::NewMemory(int size)
     {
       return new char[size];
     }

I had to remove all memory allocations by:

     #ifdef _WIN32
       z_data =
     (float*)vtkObjectFactory::NewMemory(sizeof(float)*width*height);

     #else
       z_data = new float[width*height];
     #endif

Now all works fine, but I had to create my own VTKdll.dll...


My questions:

   * Is there a way to allocate memory which can be freed from an other
     dll?
   * Is there a similar problem with shared libraries on SGIs?
   * Is there a solution without changing code from vtk3.2?

Carsten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20010809/dcb69860/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kuebler.vcf
Type: text/x-vcard
Size: 424 bytes
Desc: Card for Carsten Kübler
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20010809/dcb69860/attachment.vcf>


More information about the vtkusers mailing list