Skip to content

Commit

Permalink
Final change from grestful, try..catch added to wrapper to ensure rem…
Browse files Browse the repository at this point in the history
…oveRoot is called
  • Loading branch information
gnunn1 committed Nov 28, 2015
1 parent 7ac567e commit 8bc3a80
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions source/gtk/threads.d
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,22 @@ void threadsAddIdleDelegate(T, parameterTuple...)(T theDelegate, parameterTuple
void* delegatePointer = null;

auto wrapperDelegate = (parameterTuple parameters) {
bool ret = theDelegate(parameters);
bool callAgainNextIdleCycle = false;

if (!ret)
try
{
callAgainNextIdleCycle = theDelegate(parameters);
}

catch (Exception e)
{
// Catch exceptions here as otherwise, memory may never be freed below.
}

if (!callAgainNextIdleCycle)
core.memory.GC.removeRoot(delegatePointer);

return ret;
return callAgainNextIdleCycle;
};

delegatePointer = cast(void*) new DelegatePointer!(T, parameterTuple)(wrapperDelegate, parameters);
Expand Down

0 comments on commit 8bc3a80

Please sign in to comment.