Segfault in glDrawArrays without CMake (How to link openGL without CMAKE?)

Hello together.

I’m using vtk 9.3.1. i build it because of project envrionemnt without cmake, but linked vtk in VS22 directly. Everything works, I used auto_init. But…

I know try to derive from vtkOpenGLPolyDataMapper and call glDrawArrays . This cannot be linked. When I link Opengl directly, it builds, but segfaults in gl calls.

Whenn I build this class in a cmake environemnt, it runs.

How can I get these gl calls in my VS environment?
Thank you very much

This is the stack trace:

ucrtbased.dll!00007ffdac510b11() Unbekannt
ucrtbased.dll!00007ffdac50f565() Unbekannt
> vtkRenderingOpenGL2-9.3d.dll!operator delete(void * block) Zeile 38 C++
vtkRenderingOpenGL2-9.3d.dll!operator delete(void * block, unsigned __int64 __formal) Zeile 32 C++
vtkRenderingOpenGL2-9.3d.dll!std::_Deallocate<16,0>(void * _Ptr, unsigned __int64 _Bytes) Zeile 268 C++
vtkRenderingOpenGL2-9.3d.dll!std::_Default_allocator_traits<std::allocator<std::_Tree_node<std::pair<enum vtkShader::Type const ,vtkShader *>,void *>>>::deallocate(std::allocator<std::_Tree_node<std::pair<enum vtkShader::Type const ,vtkShader *>,void *>> & _Al, std::_Tree_node<std::pair<enum vtkShader::Type const ,vtkShader *>,void *> * const _Ptr, const unsigned __int64 _Count) Zeile 720 C++
vtkRenderingOpenGL2-9.3d.dll!std::_Tree_node<std::pair<enum vtkShader::Type const ,vtkShader *>,void *>::_Freenode0<std::allocator<std::_Tree_node<std::pair<enum vtkShader::Type const ,vtkShader *>,void *>>>(std::allocator<std::_Tree_node<std::pair<enum vtkShader::Type const ,vtkShader *>,void *>> & _Al, std::_Tree_node<std::pair<enum vtkShader::Type const ,vtkShader *>,void *> * _Ptr) Zeile 375 C++
vtkRenderingOpenGL2-9.3d.dll!std::_Tree_node<std::pair<enum vtkShader::Type const ,vtkShader *>,void *>::_Freenode<std::allocator<std::_Tree_node<std::pair<enum vtkShader::Type const ,vtkShader *>,void *>>>(std::allocator<std::_Tree_node<std::pair<enum vtkShader::Type const ,vtkShader *>,void *>> & _Al, std::_Tree_node<std::pair<enum vtkShader::Type const ,vtkShader *>,void *> * _Ptr) Zeile 382 C++
vtkRenderingOpenGL2-9.3d.dll!std::_Tree_val<std::_Tree_simple_types<std::pair<enum vtkShader::Type const ,vtkShader *>>>::_Erase_tree<std::allocator<std::_Tree_node<std::pair<enum vtkShader::Type const ,vtkShader *>,void *>>>(std::allocator<std::_Tree_node<std::pair<enum vtkShader::Type const ,vtkShader *>,void *>> & _Al, std::_Tree_node<std::pair<enum vtkShader::Type const ,vtkShader *>,void *> * _Rootnode) Zeile 747 C++
vtkRenderingOpenGL2-9.3d.dll!std::_Tree_val<std::_Tree_simple_types<std::pair<enum vtkShader::Type const ,vtkShader *>>>::_Erase_tree<std::allocator<std::_Tree_node<std::pair<enum vtkShader::Type const ,vtkShader *>,void *>>>(std::allocator<std::_Tree_node<std::pair<enum vtkShader::Type const ,vtkShader *>,void *>> & _Al, std::_Tree_node<std::pair<enum vtkShader::Type const ,vtkShader *>,void *> * _Rootnode) Zeile 746 C++
vtkRenderingOpenGL2-9.3d.dll!std::_Tree_val<std::_Tree_simple_types<std::pair<enum vtkShader::Type const ,vtkShader *>>>::_Erase_head<std::allocator<std::_Tree_node<std::pair<enum vtkShader::Type const ,vtkShader *>,void *>>>(std::allocator<std::_Tree_node<std::pair<enum vtkShader::Type const ,vtkShader *>,void *>> & _Al) Zeile 754 C++
vtkRenderingOpenGL2-9.3d.dll!std::_Tree<std::_Tmap_traits<enum vtkShader::Type,vtkShader *,std::less,std::allocator<std::pair<enum vtkShader::Type const ,vtkShader *>>,0>>::~_Tree<std::_Tmap_traits<enum vtkShader::Type,vtkShader *,std::less,std::allocator<std::pair<enum vtkShader::Type const ,vtkShader *>>,0>>() Zeile 1075 C++
vtkRenderingOpenGL2-9.3d.dll!std::map<enum vtkShader::Type,vtkShader *,std::less,std::allocator<std::pair<enum vtkShader::Type const ,vtkShader *>>>::~map<enum vtkShader::Type,vtkShader *,std::less,std::allocator<std::pair<enum vtkShader::Type const ,vtkShader *>>>() C++
vtkRenderingOpenGL2-9.3d.dll!vtkOpenGLPolyDataMapper::ReplaceShaderRenderPass(std::map<enum vtkShader::Type,vtkShader *,std::less,std::allocator<std::pair<enum vtkShader::Type const ,vtkShader *>>> shaders, vtkRenderer * __formal, vtkActor * act, bool prePass) Zeile 587 C++
PCMA.exe!vtkOpenGLGridMapper::ReplaceShaderValues(std::map<enum vtkShader::Type,vtkShader *,std::less,std::allocator<std::pair<enum vtkShader::Type const ,vtkShader *>>> shaders, vtkRenderer * ren, vtkActor * actor) Zeile 43 C++
vtkRenderingOpenGL2-9.3d.dll!vtkOpenGLPolyDataMapper::BuildShaders(std::map<enum vtkShader::Type,vtkShader *,std::less,std::allocator<std::pair<enum vtkShader::Type const ,vtkShader *>>> shaders, vtkRenderer * ren, vtkActor * actor) Zeile 310 C++
vtkRenderingOpenGL2-9.3d.dll!vtkOpenGLPolyDataMapper::UpdateShaders(vtkOpenGLHelper & cellBO, vtkRenderer * ren, vtkActor * actor) Zeile 2605 C++
PCMA.exe!vtkOpenGLGridMapper::RenderPiece(vtkRenderer * ren, vtkActor * actor) Zeile 253 C++
vtkRenderingCore-9.3d.dll!vtkPolyDataMapper::Render(vtkRenderer * ren, vtkActor * act) Zeile 36 C++
vtkRenderingOpenGL2-9.3d.dll!vtkOpenGLActor::Render(vtkRenderer * ren, vtkMapper * mapper) Zeile 95 C++
vtkRenderingCore-9.3d.dll!vtkActor::RenderTranslucentPolygonalGeometry(vtkViewport * vp) Zeile 286 C++
vtkRenderingCore-9.3d.dll!vtkProp::RenderFilteredTranslucentPolygonalGeometry(vtkViewport * v, vtkInformation * requiredKeys) Zeile 288 C++
vtkRenderingOpenGL2-9.3d.dll!vtkDefaultPass::RenderFilteredTranslucentPolygonalGeometry(const vtkRenderState * s) Zeile 115 C++
vtkRenderingOpenGL2-9.3d.dll!vtkTranslucentPass::Render(const vtkRenderState * s) Zeile 33 C++
vtkRenderingOpenGL2-9.3d.dll!vtkOrderIndependentTranslucentPass::Render(const vtkRenderState * s) Zeile 336 C++
vtkRenderingOpenGL2-9.3d.dll!vtkOpenGLRenderer::DeviceRenderTranslucentPolygonalGeometry(vtkFrameBufferObjectBase * fbo) Zeile 552 C++
vtkRenderingOpenGL2-9.3d.dll!vtkOpenGLRenderer::UpdateGeometry(vtkFrameBufferObjectBase * fbo) Zeile 398 C++
vtkRenderingOpenGL2-9.3d.dll!vtkOpenGLRenderer::DeviceRender() Zeile 292 C++
vtkRenderingCore-9.3d.dll!vtkRenderer::Render() Zeile 374 C++
vtkRenderingCore-9.3d.dll!vtkRendererCollection::Render() Zeile 42 C++
vtkRenderingCore-9.3d.dll!vtkRenderWindow::DoStereoRender() Zeile 347 C++
vtkRenderingCore-9.3d.dll!vtkRenderWindow::Render() Zeile 306 C++
vtkRenderingOpenGL2-9.3d.dll!vtkOpenGLRenderWindow::Render() Zeile 2766 C++
PCMA.exe!Gehring::PCMA::wxVTKRenderWindowInteractor::Render() Zeile 385 C++
PCMA.exe!Gehring::PCMA::wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent & __formal) Zeile 194 C++
[Externer Code]
PCMA.exe!WinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * lpCmdLine, int nCmdShow) Zeile 19 C++
[Externer Code]

It looks a lot like you have some 32/64-bit issues or perhaps binaries are incompatible. Deriving from vtkOpenGLPolyDataMapper is generally a bad idea. As far as I recall, the mappers are created using a factory and the platform / settings determine which mapper is returned.

Hello,

When I derive VTK classes, I do like this:

In the header:

#include <vtkObjectFactory.h>
#include <vtkInteractorStyleTrackballCamera.h> //header of base class
#include <vtkSmartPointer.h>

// v3dMouseInteractor derives from a VTK class.
class v3dMouseInteractor : public vtkInteractorStyleTrackballCamera {

public:
    static v3dMouseInteractor* New(); //"constructor" of derived class
    vtkTypeMacro(v3dMouseInteractor, vtkInteractorStyleTrackballCamera)
    //                ^-----derived  goes here       ^-------base goes here

...

};

In the .cpp:

// Implementation of the New() function for the drived class.
vtkStandardNewMacro(v3dMouseInteractor);
...

I also build my VTK project sans CMake, then I have to put these in the very beginning of the OpenGL-dealing .cpps (the modules that need initialization may vary according to your needs). Module names are after their respective .dll/.so libraries.

//----------Since we're not building with CMake, we need to init the VTK modules------------------
//--------------linking with the VTK libraries is often not enough--------------------------------
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2) // VTK was built with vtkRenderingOpenGL2
VTK_MODULE_INIT(vtkInteractionStyle)
VTK_MODULE_INIT(vtkRenderingFreeType)
...
//------------------------------------------------------------------------------------------------

I hope this helps,
PC

I believe that you only include the vtkObjectFactory.h in the .cxx file