FLTK logo

[branch-1.3] f091b18 - macOS: Fix a timer inconsistency and prevent a crash

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Library      Forums      Links      Apps     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[branch-1.3] f091b18 - macOS: Fix a timer inconsistency and prevent a crash "Albrecht Schlosser" Jul 25, 2021  
 
commit f091b18adfd12e4d91a5da40e379de2f8421d49d
Author:     Albrecht Schlosser <albrechts.fltk@online.de>
AuthorDate: Sun Jul 25 14:53:28 2021 +0200
Commit:     Albrecht Schlosser <albrechts.fltk@online.de>
CommitDate: Sun Jul 25 14:53:28 2021 +0200

    macOS: Fix a timer inconsistency and prevent a crash
    
    Calling Fl::repeat_timeout() instead of Fl::add_timeout() to create
    a timer would crash on macOS but fall back to Fl::add_timeout() on
    Windows and Unix/Linux. Although this is documented as "undefined
    behavior" a crash should always be avoided and the fallback is now
    consistent on all major platforms.
    
    Backported from 1.4: 87475c20d6cc81912e58f21369b101271d4732f6

 src/Fl_cocoa.mm | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git src/Fl_cocoa.mm src/Fl_cocoa.mm
index 152b3e8..606d624 100644
--- src/Fl_cocoa.mm
+++ src/Fl_cocoa.mm
@@ -1,9 +1,7 @@
 //
-// "$Id$"
-//
 // MacOS-Cocoa specific code for the Fast Light Tool Kit (FLTK).
 //
-// Copyright 1998-2020 by Bill Spitzak and others.
+// Copyright 1998-2021 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -613,6 +611,10 @@ void Fl::add_timeout(double time, Fl_Timeout_Handler cb, void* data)
 
 void Fl::repeat_timeout(double time, Fl_Timeout_Handler cb, void* data)
 {
+  if (!current_timer) {
+    add_timeout(time, cb, data);
+    return;
+  }
   // k = how many times 'time' seconds after the last scheduled timeout until the future
   double k = ceil( (CFAbsoluteTimeGetCurrent() - current_timer->next_timeout) / time);
   if (k < 1) k = 1;
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2025 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.