From 0d0bd1168bb96ded8dfe5ab3ca60588dec5d2949 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 28 Apr 2022 12:58:58 +0200 Subject: [PATCH] Mesh: handle exceptions when running FreeCAD in headless mode --- src/Mod/Mesh/Gui/AppMeshGui.cpp | 5 ++++- src/Mod/MeshPart/Gui/MeshFlatteningCommand.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Mod/Mesh/Gui/AppMeshGui.cpp b/src/Mod/Mesh/Gui/AppMeshGui.cpp index d06e3d6f0a..9f8ab0a3be 100644 --- a/src/Mod/Mesh/Gui/AppMeshGui.cpp +++ b/src/Mod/Mesh/Gui/AppMeshGui.cpp @@ -27,6 +27,7 @@ # include # include # include +# include #endif #include @@ -147,7 +148,9 @@ PyMOD_INIT_FUNC(MeshGui) // instantiating the commands CreateMeshCommands(); - (void)new MeshGui::CleanupHandler; + if (qApp) { + (void)new MeshGui::CleanupHandler; + } // try to instantiate flat-mesh commands try{ diff --git a/src/Mod/MeshPart/Gui/MeshFlatteningCommand.py b/src/Mod/MeshPart/Gui/MeshFlatteningCommand.py index 3b4a910de4..86eb8b8fbe 100644 --- a/src/Mod/MeshPart/Gui/MeshFlatteningCommand.py +++ b/src/Mod/MeshPart/Gui/MeshFlatteningCommand.py @@ -117,3 +117,6 @@ try: except ImportError: App.Console.PrintLog("flatmesh-commands are not available\n") App.Console.PrintLog("flatmesh needs pybind11 as build dependency\n") +except AttributeError: + # Can happen when running FreeCAD in headless mode + pass