Skip to content

Commit

Permalink
Fix haxe 4.2 update loop (#932)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanrishatum authored Feb 28, 2021
1 parent a733910 commit fc66fab
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions hxd/System.hl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class System {
#if !usesys
static var sentinel : hl.UI.Sentinel;
#end
#if ( target.threaded && (haxe_ver >= 4.2) )
static var mainThread : sys.thread.Thread;
#end

// -- HL
static var currentNativeCursor : hxd.Cursor = Default;
Expand Down Expand Up @@ -132,10 +135,26 @@ class System {
#if hxtelemetry
var hxt = new hxtelemetry.HxTelemetry();
#end
#if ( target.threaded && (haxe_ver >= 4.2) && heaps_unsafe_events)
var eventRecycle = [];
#end
while( true ) {
try {
hl.Api.setErrorHandler(reportError); // set exception trap

#if ( target.threaded && (haxe_ver >= 4.2) )
// Due to how 4.2+ timers work, instead of MainLoop, thread events have to be updated.
// Unsafe events rely on internal implementation of EventLoop, but utilize the recycling feature
// which in turn provides better optimization.
#if heaps_unsafe_events
@:privateAccess mainThread.events.__progress(Sys.time(), eventRecycle);
#else
mainThread.events.progress();
#end
#else
@:privateAccess haxe.MainLoop.tick();
#end

if( !mainLoop() ) break;
} catch( e : Dynamic ) {
hl.Api.setErrorHandler(null);
Expand Down Expand Up @@ -402,6 +421,9 @@ class System {
sentinel = new hl.UI.Sentinel(30, function() throw "Program timeout (infinite loop?)");
haxe.MainLoop.add(timeoutTick, -1) #if (haxe_ver >= 4) .isBlocking = false #end;
#end
#if ( target.threaded && (haxe_ver >= 4.2) )
mainThread = sys.thread.Thread.current();
#end
}

#if (hlsdl || hldx)
Expand Down

0 comments on commit fc66fab

Please sign in to comment.