FLTK logo

[master] 87475c2 - 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 Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 87475c2 - macOS: Fix a timer inconsistency and prevent a crash "Albrecht Schlosser" Jul 07, 2021  
 
commit 87475c20d6cc81912e58f21369b101271d4732f6
Author:     Albrecht Schlosser <albrechts.fltk@online.de>
AuthorDate: Wed Jul 7 15:35:14 2021 +0200
Commit:     Albrecht Schlosser <albrechts.fltk@online.de>
CommitDate: Wed Jul 7 15:35:14 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.
    
    In the future this may be documented as the standard behavior.

 src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx | 4 ++++
 1 file changed, 4 insertions(+)

diff --git src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
index 1838a73..2caf174 100644
--- src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
+++ src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
@@ -518,6 +518,10 @@ void Fl_Cocoa_Screen_Driver::add_timeout(double time, Fl_Timeout_Handler cb, voi
 
 void Fl_Cocoa_Screen_Driver::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-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.