diff --git a/Common/CreateFile.cpp b/Common/CreateFile.cpp
index c83066c564f0990bfe08696055df4c7164c14fcf..475a8fd5fe7d33086a5761275e6f9949f2622442 100644
--- a/Common/CreateFile.cpp
+++ b/Common/CreateFile.cpp
@@ -461,10 +461,10 @@ void CreateOutputFile(std::string fileName, int format)
       }
       int numViews = (int)opt_post_nb_views(0, GMSH_GET, 0), numSteps = 0;
 
-      // FIXME: this does not handle empty time steps!
       for(int i = 0; i < numViews; i++){
         if(opt_view_visible(i, GMSH_GET, 0))
-          numSteps = std::max(numSteps, (int)opt_view_nb_timestep(i, GMSH_GET, 0));
+          numSteps = std::max(numSteps,
+                              (int)opt_view_nb_non_empty_timestep(i, GMSH_GET, 0));
       }
       std::vector<std::string> frames;
       for(int i = 0; i < (CTX::instance()->post.animCycle ? numViews : numSteps); i++){
diff --git a/Common/Options.cpp b/Common/Options.cpp
index 341765d31b36e5e3eb732a099fad2e4ad5e80eea..931c14bf60cf88242b54ac795567063e59c931a5 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -6525,6 +6525,20 @@ double opt_view_nb_timestep(OPT_ARGS_NUM)
 #endif
 }
 
+double opt_view_nb_non_empty_timestep(OPT_ARGS_NUM)
+{
+#if defined(HAVE_POST)
+  GET_VIEW(0.);
+  if(!data) return 0;
+  int n = 0;
+  for(unsigned int i = 0; i < data->getNumTimeSteps(); i++)
+    if(data->hasTimeStep(i)) n++;
+  return n;
+#else
+  return 0.;
+#endif
+}
+
 double opt_view_timestep(OPT_ARGS_NUM)
 {
 #if defined(HAVE_POST)
diff --git a/Common/Options.h b/Common/Options.h
index 9db8fcb1defbbabebc79584e87e2840efe369616..1f13d6f411fe6365be60eb35cd7af16bb2fef2c1 100644
--- a/Common/Options.h
+++ b/Common/Options.h
@@ -617,6 +617,7 @@ double opt_post_plugins(OPT_ARGS_NUM);
 double opt_post_nb_views(OPT_ARGS_NUM);
 double opt_post_file_format(OPT_ARGS_NUM);
 double opt_view_nb_timestep(OPT_ARGS_NUM);
+double opt_view_nb_non_empty_timestep(OPT_ARGS_NUM);
 double opt_view_timestep(OPT_ARGS_NUM);
 double opt_view_min(OPT_ARGS_NUM);
 double opt_view_max(OPT_ARGS_NUM);