From 05f32daa027cb26f60d63bab6f2a2c17696ef919 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@uliege.be>
Date: Sun, 22 May 2022 09:40:04 +0200
Subject: [PATCH] sanity checks

---
 tutorials/c++/t8.cpp   |  9 +++++++--
 tutorials/c++/t9.cpp   |  5 +++++
 tutorials/python/t8.py | 12 ++++++++----
 tutorials/python/t9.py |  4 ++++
 4 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/tutorials/c++/t8.cpp b/tutorials/c++/t8.cpp
index 3823bf98f2..6225373924 100644
--- a/tutorials/c++/t8.cpp
+++ b/tutorials/c++/t8.cpp
@@ -75,10 +75,15 @@ int main(int argc, char **argv)
   // If we were to follow the geo example blindly, we would read the number of
   // views from the relevant option value, and use the gmsh::option::setNumber()
   // and gmsh::option::setString() functions. A nicer way is to use
-  // gmsh::view::getTags() and to use the gmsh::view::setNumber() and
-  // gmsh::view::setString() functions.
+  // gmsh::view::getTags() and to use the gmsh::view::option::setNumber() and
+  // gmsh::view::option::setString() functions.
   std::vector<int> v;
   gmsh::view::getTags(v);
+  if(v.size() != 4) {
+    gmsh::logger::write("Wrong number of views!", "error");
+    gmsh::finalize();
+    return 1;
+  }
 
   gmsh::view::option::setNumber(v[0], "IntervalsType", 2);
   gmsh::view::option::setNumber(v[0], "OffsetZ", 0.05);
diff --git a/tutorials/c++/t9.cpp b/tutorials/c++/t9.cpp
index 146d71e63c..f2bafeb6ee 100644
--- a/tutorials/c++/t9.cpp
+++ b/tutorials/c++/t9.cpp
@@ -35,6 +35,11 @@ int main(int argc, char **argv)
 
   std::vector<int> v;
   gmsh::view::getTags(v);
+  if(v.size() != 1) {
+    gmsh::logger::write("Wrong number of views!", "error");
+    gmsh::finalize();
+    return 1;
+  }
 
   // We then set some options for the `Isosurface' plugin (which extracts an
   // isosurface from a 3D scalar view), and run it:
diff --git a/tutorials/python/t8.py b/tutorials/python/t8.py
index 321ff2794f..69cf5e8fea 100644
--- a/tutorials/python/t8.py
+++ b/tutorials/python/t8.py
@@ -70,11 +70,15 @@ if '-nopopup' not in sys.argv:
 # We also set some options for each post-processing view:
 
 # If we were to follow the geo example blindly, we would read the number of
-# views from the relevant option value, and use the gmsh.option.setNumber()
-# and gmsh.option.setString() functions. A nicer way is to use
-# gmsh.view.getTags() and to use the gmsh.view.setNumber() and
-# gmsh.view.setString() functions.
+# views from the relevant option value, and use the gmsh.option.setNumber() and
+# gmsh.option.setString() functions. A nicer way is to use gmsh.view.getTags()
+# and to use the gmsh.view.option.setNumber() and gmsh.view.option.setString()
+# functions.
 v = gmsh.view.getTags()
+if len(v) != 4:
+    gmsh.logger.write("Wrong number of views!", "error")
+    gmsh.finalize()
+    exit()
 
 # We set some options for each post-processing view:
 gmsh.view.option.setNumber(v[0], "IntervalsType", 2)
diff --git a/tutorials/python/t9.py b/tutorials/python/t9.py
index 2ac7f5017f..0974b64661 100644
--- a/tutorials/python/t9.py
+++ b/tutorials/python/t9.py
@@ -25,6 +25,10 @@ gmsh.initialize()
 path = os.path.dirname(os.path.abspath(__file__))
 gmsh.merge(os.path.join(path, os.pardir, 'view3.pos'))
 v = gmsh.view.getTags()
+if len(v) != 1:
+    gmsh.logger.write("Wrong number of views!", "error")
+    gmsh.finalize()
+    exit()
 
 # We then set some options for the `Isosurface' plugin (which extracts an
 # isosurface from a 3D scalar view), and run it:
-- 
GitLab