summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2022-03-20 08:09:34 +0100
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2022-03-20 08:09:34 +0100
commitf5628aa66de0173f4fc145586a8c83e66e32f160 (patch)
tree9378c61789b0ac3f85cd9ff5854540b02321ebce
parent733ffed6308a63c5f7975bf2e5807b29faf2c77a (diff)
Fix issue #413: Commit 29d9e31 creates memory handling problem under macOS.
-rw-r--r--src/Fl.cxx23
-rw-r--r--src/Fl_System_Driver.H4
-rw-r--r--src/Fl_System_Driver.cxx40
-rw-r--r--src/Fl_cocoa.mm3
-rw-r--r--src/Fl_win32.cxx2
-rw-r--r--src/drivers/Unix/Fl_Unix_System_Driver.cxx1
6 files changed, 47 insertions, 26 deletions
diff --git a/src/Fl.cxx b/src/Fl.cxx
index 28fc04c5f..f77a88363 100644
--- a/src/Fl.cxx
+++ b/src/Fl.cxx
@@ -479,29 +479,6 @@ void Fl::run_idle() {
occurs (this will happen on X11 if a signal happens).
*/
double Fl::wait(double time_to_wait) {
-
- // platform independent part:
-
- // delete all widgets that were listed during callbacks
- do_widget_deletion();
-
- Fl_Timeout::do_timeouts(); // execute timer callbacks
-
- Fl::run_checks();
-
- Fl::run_idle();
-
- // the idle function may turn off idle, we can then wait,
- // or it leaves Fl::idle active and we set time_to_wait to 0
- if (Fl::idle) {
- time_to_wait = 0.0;
- } else {
- // limit time by next timer interval
- time_to_wait = Fl_Timeout::time_to_wait(time_to_wait);
- }
-
- // platform dependent part:
-
return system_driver()->wait(time_to_wait);
}
diff --git a/src/Fl_System_Driver.H b/src/Fl_System_Driver.H
index e010212fe..779167b69 100644
--- a/src/Fl_System_Driver.H
+++ b/src/Fl_System_Driver.H
@@ -2,7 +2,7 @@
// A base class for platform specific system calls
// for the Fast Light Tool Kit (FLTK).
//
-// Copyright 2010-2021 by Bill Spitzak and others.
+// Copyright 2010-2022 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
@@ -241,7 +241,7 @@ public:
virtual Fl_Sys_Menu_Bar_Driver *sys_menu_bar_driver() { return NULL; }
virtual void lock_ring() {}
virtual void unlock_ring() {}
- virtual double wait(double) { return 0.0; } // must override
+ virtual double wait(double); // must override
virtual int ready() { return 0; } // must override
};
diff --git a/src/Fl_System_Driver.cxx b/src/Fl_System_Driver.cxx
index 45927ae2b..f207ed8b8 100644
--- a/src/Fl_System_Driver.cxx
+++ b/src/Fl_System_Driver.cxx
@@ -1,7 +1,7 @@
//
// A base class for platform specific system calls.
//
-// Copyright 1998-2016 by Bill Spitzak and others.
+// Copyright 1998-2022 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
@@ -22,6 +22,7 @@
#include "Fl_System_Driver.H"
#include <FL/Fl.H>
+#include "Fl_Timeout.h"
#include <FL/Fl_File_Icon.H>
#include <FL/fl_utf8.h>
#include <stdlib.h>
@@ -503,6 +504,43 @@ void Fl_System_Driver::gettime(time_t *sec, int *usec) {
}
/**
+ Execute platform independent parts of Fl::wait(double).
+
+ Platform drivers \b MUST override this virtual method to do
+ their own stuff and call this base class method to run
+ the platform independent wait functions.
+
+ Overriden methods will typically call this method early and perform
+ platform-specific operations after that in order to work with the
+ \p time_to_wait value possibly modified by this method.
+ However, some platform drivers may need to do extra stuff before
+ calling this method, for instance setting up a memory pool on macOS.
+
+ \param[in] time_to_wait max time to wait
+
+ \return new (max) time to wait after elapsing timeouts
+*/
+double Fl_System_Driver::wait(double time_to_wait) {
+
+ // delete all widgets that were listed during callbacks
+ Fl::do_widget_deletion();
+
+ Fl_Timeout::do_timeouts();
+ Fl::run_checks();
+ Fl::run_idle();
+
+ // the idle function may turn off idle, we can then wait,
+ // or it leaves Fl::idle active and we set time_to_wait to 0
+ if (Fl::idle) {
+ time_to_wait = 0.0;
+ } else {
+ // limit time by next timer interval
+ time_to_wait = Fl_Timeout::time_to_wait(time_to_wait);
+ }
+ return time_to_wait;
+}
+
+/**
\}
\endcond
*/
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index cf992dd17..2c7fe9e81 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -792,6 +792,9 @@ double Fl_Darwin_System_Driver::wait(double time_to_wait)
drain_dropped_files_list();
}
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ time_to_wait = Fl_System_Driver::wait(time_to_wait);
+
if (fl_mac_os_version < 101100) NSDisableScreenUpdates(); // 10.3 Makes updates to all windows appear as a single event
Fl::flush();
if (fl_mac_os_version < 101100) NSEnableScreenUpdates(); // 10.3
diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx
index 7f2e1f98e..51d122aeb 100644
--- a/src/Fl_win32.cxx
+++ b/src/Fl_win32.cxx
@@ -417,6 +417,8 @@ static void process_awake_handler_requests(void) {
// always returns 1.
double Fl_WinAPI_System_Driver::wait(double time_to_wait) {
+ time_to_wait = Fl_System_Driver::wait(time_to_wait);
+
int have_message = 0;
if (nfds) {
diff --git a/src/drivers/Unix/Fl_Unix_System_Driver.cxx b/src/drivers/Unix/Fl_Unix_System_Driver.cxx
index b564df5a5..3951e3eda 100644
--- a/src/drivers/Unix/Fl_Unix_System_Driver.cxx
+++ b/src/drivers/Unix/Fl_Unix_System_Driver.cxx
@@ -837,6 +837,7 @@ int Fl_Unix_System_Driver::poll_or_select() {
double Fl_Unix_System_Driver::wait(double time_to_wait)
{
+ time_to_wait = Fl_System_Driver::wait(time_to_wait);
if (time_to_wait <= 0.0) {
// do flush second so that the results of events are visible:
int ret = this->poll_or_select_with_delay(0.0);