From dbc2624f6a14cb3e64e657c6373295f3368eec49 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Mon, 2 Mar 2015 18:02:53 +0000
Subject: [PATCH] fix crash when trying to export brep/step and there's no
 internal occ model

---
 Geo/GModelIO_OCC.cpp | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/Geo/GModelIO_OCC.cpp b/Geo/GModelIO_OCC.cpp
index e73d44d4ea..083cc34661 100644
--- a/Geo/GModelIO_OCC.cpp
+++ b/Geo/GModelIO_OCC.cpp
@@ -1053,26 +1053,27 @@ int GModel::readOCCIGES(const std::string &fn)
 
 int GModel::writeOCCBREP(const std::string &fn)
 {
-  _occ_internals->buildShapeFromGModel(this);
-
   if(!_occ_internals){
     Msg::Error("No OpenCASCADE model found");
     return 0;
   }
-  else
+  else{
+    _occ_internals->buildShapeFromGModel(this);
     _occ_internals->writeBREP(fn.c_str());
+  }
   return 1;
 }
 
 int GModel::writeOCCSTEP(const std::string &fn)
 {
-  _occ_internals->buildShapeFromGModel(this);
   if(!_occ_internals){
     Msg::Error("No OpenCASCADE model found");
     return 0;
   }
-  else
+  else{
+    _occ_internals->buildShapeFromGModel(this);
     _occ_internals->writeSTEP(fn.c_str());
+  }
   return 1;
 }
 
-- 
GitLab