| [ Return to Bugs & Features | Roadmap 1.3 | SVN ⇄ GIT ]
STR #3387
Application: | FLTK Library |
Status: | 1 - Closed w/Resolution |
Priority: | 4 - High, e.g. key functionality not working |
Scope: | 2 - Specific to an operating system |
Subsystem: | MacOS |
Summary: | Bug of timer implementation on macosx |
Version: | 1.3.4 |
Created By: | redmaple |
Assigned To: | manolo |
Fix Version: | 1.4-current (SVN: v12306) |
Update Notification: | |
Trouble Report Files:
Trouble Report Comments:
|
#1 | redmaple 21:50 Jun 21, 2017 |
| There is a bug in the implementation of timer with macosx cocoa library.
Application built with FLTK 1.3.4 on OS X will crash if Fl::add_timeout is called repeatedly more than a certain number of times(8 times). For example, the following code will crash on a mac OS X system.
void MyTimerProc(void* arg) { }
for (int i = 0; i < 100; ++i) { DataInfo* info = new DataInfo(); // other initialization here... Fl::add_timeout(MyTimerProc, info); }
In fact there are two problems here. 1) The global variable 'current_timer' is not updated if MacTimeout array is reallocated inside 'realloc_timers' function.
2) A pointer to MacTimeout is used as 'info' field of CFRunLoopTimerContext when calling CFRunLoopTimerCreate, and as same as the above, the pointer will be invalidated by the 'realloc_timers' function. So an index number of MacTimeout instead of pointer shall be used as info field of CFRunLoopTimerContext.
I fixed the above problems in my environment and I attach the diff hope that it will be helpful. | |
|
#2 | manolo 08:26 Jun 26, 2017 |
| r12271 of FLTK 1.4 branch should fix this bug.
@redmaple: thanks for the patch. Please, review and test the new code committed at r12271, and report if there's still any bug.
It's no longer possible to change the FLTK 1.3 branch, so the fix is in the new 1.4 branch that is completely source compatible with 1.3 on MacOS X. | |
|
#3 | redmaple 21:50 Jul 04, 2017 |
| I reviewed the fix of r12271, and I think the problem is not completely fixed.
As I mentioned in the first post, there were two problems there, and you fixed the second in r12271, the first problem remains open.
Consider the case that you may call Fl::add_timeout many times inside a timer callback, which causes the function 'realloc_timers' be called, and realloc_timers invalidates the 'current_timer' global variable. And the invalidated 'current_timer' is used after the timer callback returns, this may crash your app.
So, the following code shall be added before you free the old timer array. //.... if (current_timer) { MacTimeout* newCurrent = new_timers + (current_timer - mac_timers); current_timer = newCurrent; } MacTimeout* delete_me = mac_timers; // insert the above code before this line // ....omitted | |
|
#4 | manolo 05:05 Jul 11, 2017 |
| Fixed in Subversion repository.
Thanks for the detailed reply. | |
[ Return to Bugs & Features ]
|
| |