hxcpp-debugger icon indicating copy to clipboard operation
hxcpp-debugger copied to clipboard

Thread still showing as running after termination

Open Gama11 opened this issue 5 years ago • 2 comments

When running the following code (thanks for the code example @gepatto) and pressing Space to open a file dialog, a second thread appears in the callstack view:

package;

import lime.ui.FileDialogType;
import lime.ui.FileDialog;
import openfl.events.Event;
import openfl.net.URLRequest;
import openfl.display.Loader;
import openfl.display.Sprite;
import openfl.ui.Keyboard;
import openfl.events.KeyboardEvent;

class Main extends Sprite {
	var dialogOpen:Bool = false;
	var l:Loader;

	public function new() {
		super();
		stage.addEventListener(KeyboardEvent.KEY_DOWN, stage_keydown);
	}

	function loadComplete(e:Event) {}

	function stage_keydown(e:KeyboardEvent) {
		switch (e.keyCode) {
			case Keyboard.SPACE:
				selectImage();
			case Keyboard.DELETE:
				if (l != null) {
					l.unload();
					removeChild(l);
					l = null;
				}
		}
	};

	function selectImage() {
		#if !js
		if (dialogOpen)
			return; // prevent multiple dialogs
		if (l == null) {
			l = new Loader();
			l.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
			addChild(l);
		} else {
			l.unload();
		}
		var dOpen = new FileDialog();
		dOpen.onSelect.add(function(path:String) {
			l.load(new URLRequest(path));
			dialogOpen = false;
		});
		dialogOpen = true;
		dOpen.browse(FileDialogType.OPEN);
		#end
	}
}

When the file dialog is closed, the thread should terminate, but the UI doesn't seem to update. I added some traces and found the following order of events:

threadStart {
	threadId : 0
}
threadStart {
	threadId : 2
}
threadExit {
	threadId : -1
}

So it looks like we don't get a valid thread ID on exit. Possibly a bug in hcxpp (@nulld)?

Gama11 avatar Aug 26 '19 13:08 Gama11

HXCPP issue at https://github.com/HaxeFoundation/hxcpp/issues/845.

Gama11 avatar Aug 26 '19 13:08 Gama11

Looks like we receive THREAD_TERMINATED event from cpp.vm.Debugger with threadNumber :-1. So it's a bug or undocumented behaviour: https://api.haxe.org/cpp/vm/Debugger.html#setEventNotificationHandler

nulld avatar Aug 26 '19 13:08 nulld