Browse Source

imediately cancel previous event in EventLoop upon MainLoop.add (fixes #10329)

Aleksandr Kuzmenko 4 years ago
parent
commit
c6373a6cb6

+ 1 - 1
extra/CHANGES.txt

@@ -3,7 +3,7 @@
 	Bugfixes:
 
 	all : fixed errors on final vars modification with `+=`, `*=` etc operations (#10325)
-	all : fixed hanging of MainLoop.add on threaded targets (#10308)
+	all : fixed hanging of MainLoop.add on threaded targets (#10308, #10329)
 	js : fixed IntMap for keys greater than 2^31 (#10316)
 	js : workaround to fix sourcemaps on Firefox in Windows (#10217)
 	hl : add clipboard support in hl 1.12 (#10320)

+ 3 - 3
std/haxe/MainLoop.hx

@@ -110,11 +110,11 @@ class MainLoop {
 	static function injectIntoEventLoop(waitMs:Int) {
 		#if (target.threaded && !cppia)
 			mutex.acquire();
+			if(eventLoopHandler != null)
+				mainThread.events.cancel(eventLoopHandler);
 			eventLoopHandler = mainThread.events.repeat(
 				() -> {
-					if(eventLoopHandler != null) {
-						mainThread.events.cancel(eventLoopHandler);
-					}
+					mainThread.events.cancel(eventLoopHandler);
 					var wait = tick();
 					if(hasEvents()) {
 						injectIntoEventLoop(Std.int(wait * 1000));

+ 14 - 0
tests/misc/compiler_loops/projects/Issue10329/Main.hx

@@ -0,0 +1,14 @@
+import haxe.MainLoop;
+
+class Main {
+	static function main() {
+		var e1 = null;
+		var e2 = null;
+		e1 = MainLoop.add(() -> {
+			e1.stop();
+		});
+		e2 = MainLoop.add(() -> {
+			e2.stop();
+		});
+	}
+}

+ 2 - 0
tests/misc/compiler_loops/projects/Issue10329/compile.hxml

@@ -0,0 +1,2 @@
+--main Main
+--interp