CameraRGBD: set VTK QSurfaceFormat before QApplication

On macOS the embedded QVTKOpenGLNativeWidget (CameraViewer's cloud view)
crashed on first paint: VTK called a null GL function pointer
(vtkOpenGLVertexArrayObject::Bind -> 0x0) because no compatible OpenGL
context was set. Set QSurfaceFormat::setDefaultFormat(
QVTKRenderWidget::defaultFormat()) before constructing QApplication, as
the main rtabmap app already does.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
matlabbe
2026-06-28 14:15:06 -07:00
co-authored by Claude Opus 4.8
parent e646b1cd79
commit 80b537b2e4
+11 -1
View File
@@ -48,6 +48,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdio.h>
#include <signal.h>
#include <QApplication>
#include <QSurfaceFormat>
#include <vtkVersionMacros.h>
#include <QVTKRenderWidget.h>
void showUsage(const char * executableName)
{
@@ -168,7 +171,6 @@ int main(int argc, char * argv[])
}
if (strcmp(argv[i], "-pcl") == 0)
{
++i;
usePCLViz = true;
continue;
}
@@ -485,6 +487,14 @@ int main(int argc, char * argv[])
}
else // Use our own visualizer
{
#if VTK_MAJOR_VERSION > 9 || (VTK_MAJOR_VERSION==9 && VTK_MINOR_VERSION >= 1)
// Needed to ensure the appropriate OpenGL context is created for VTK
// rendering (QVTKOpenGLNativeWidget). Without it the embedded VTK widget
// gets an incompatible context and VTK calls a null GL function pointer
// (crash in vtkOpenGLVertexArrayObject::Bind on first paint). Must be set
// before QApplication is constructed.
QSurfaceFormat::setDefaultFormat(QVTKRenderWidget::defaultFormat());
#endif
QApplication app(argc, argv);
rtabmap::CameraViewer cameraViewer;