From 6318abf42e16e0967576bca5e460ebcc34f1f0bc Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Mon, 3 Apr 2017 23:17:02 +0200
Subject: [PATCH] prevent crash if no string to draw

---
 Fltk/drawContextFltkCairo.cpp         | 1 +
 Fltk/drawContextFltkStringTexture.cpp | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/Fltk/drawContextFltkCairo.cpp b/Fltk/drawContextFltkCairo.cpp
index 84f393e5d5..9e6595c091 100644
--- a/Fltk/drawContextFltkCairo.cpp
+++ b/Fltk/drawContextFltkCairo.cpp
@@ -56,6 +56,7 @@ class drawContextFltkCairo::queueString {
 
   void flush()
   {
+    if(_elements.empty()) return;
     cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_A8, _totalWidth, _maxHeight);
     cairo_t *cr = cairo_create(surface);
     int pos = 0;
diff --git a/Fltk/drawContextFltkStringTexture.cpp b/Fltk/drawContextFltkStringTexture.cpp
index b855305835..fc4ebb51ca 100644
--- a/Fltk/drawContextFltkStringTexture.cpp
+++ b/Fltk/drawContextFltkStringTexture.cpp
@@ -45,7 +45,6 @@ class drawContextFltkStringTexture::queueString {
   void flush()
   {
     if(_elements.empty()) return;
-
     //1000 should be _totalWidth but it does not work
     int w = 1000, h = _maxHeight;
     Fl_Offscreen offscreen = fl_create_offscreen(w, h);
-- 
GitLab