From d0a3aed5ec552fcb2499fdb48362fa26683cf6ca Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Tue, 13 Apr 2021 09:40:00 +0200
Subject: [PATCH] [de] Init vtk modules.

Fixes runtime crash.
---
 Applications/DataExplorer/DataExplorer.cmake | 1 +
 Applications/DataExplorer/main.cpp           | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/Applications/DataExplorer/DataExplorer.cmake b/Applications/DataExplorer/DataExplorer.cmake
index d5c5b2bde35..50582892906 100644
--- a/Applications/DataExplorer/DataExplorer.cmake
+++ b/Applications/DataExplorer/DataExplorer.cmake
@@ -22,6 +22,7 @@ set(APP_ICON ${SOURCE_DIR_REL}/scripts/packaging/ogs-de-icon.icns)
 
 # Create the executable
 add_executable(DataExplorer main.cpp ${SOURCES} ${UIS} ${APP_ICON} exe-icon.rc)
+target_compile_definitions(DataExplorer PUBLIC $<$<BOOL:${VTK_ADDED}>:VTK_VIA_CPM>)
 
 target_link_libraries(
     DataExplorer
diff --git a/Applications/DataExplorer/main.cpp b/Applications/DataExplorer/main.cpp
index eb33b1c2368..43fad6b622e 100644
--- a/Applications/DataExplorer/main.cpp
+++ b/Applications/DataExplorer/main.cpp
@@ -9,6 +9,15 @@
 #include "VtkVis/VtkConsoleOutputWindow.h"
 #include "mainwindow.h"
 
+// TODO: Replace this on VTK 9 upgrade, see
+// https://discourse.vtk.org/t/vtk-use-file/3645/2
+#if VTK_VIA_CPM
+#include <vtkAutoInit.h>
+VTK_MODULE_INIT(vtkInteractionStyle)
+VTK_MODULE_INIT(vtkRenderingFreeType)
+VTK_MODULE_INIT(vtkRenderingOpenGL2)
+#endif
+
 int main(int argc, char* argv[])
 {
     // needed to ensure appropriate OpenGL context is created for VTK rendering.
-- 
GitLab