I’m working on a game where I specify a class name in a text file (eg. TheEndScreen
) and the code reflectively instantiates it.
To achieve this, I use this reflection code (c/o Stack Overflow):
// Create the specified type. Must have a constructor with no args.
return Type.createInstance(Type.resolveClass(className), []);
When I run this on Neko, I get a stack dump:
$nargs
Called from /usr/lib/haxe/std/neko/_std/Type.hx line 102
Called from deengames/abook/core/Screen.hx line 299
Called from deengames/abook/core/Screen.hx line 283
Called from deengames/abook/core/Screen.hx line 273
Called from deengames/io/GestureManager.hx line 45
Called from deengames/abook/core/Screen.hx line 107
Called from flixel/FlxState.hx line 155
Called from flixel/FlxGame.hx line 700
Called from flixel/FlxGame.hx line 648
Called from flixel/FlxGame.hx line 493
Called from openfl/_legacy/events/EventDispatcher.hx line 98
Called from a C function
Called from openfl/_legacy/display/DisplayObject.hx line 161
Called from a C function
Called from openfl/_legacy/display/DisplayObjectContainer.hx line 286
Called from openfl/_legacy/display/Stage.hx line 1103
Called from openfl/_legacy/display/Stage.hx line 351
Called from openfl/_legacy/display/Stage.hx line 1084
Called from openfl/_legacy/display/Stage.hx line 430
As a work-around, I currently just create the class by hand (eg. new TheEndScreen()
) in some other place that the user won’t notice (eg. right before I destroy the splash screen).
This works, which makes me suspect that DCE is the reason behind this exception.
To work around this, I tried the following:
- Adding
@:keep
on top of my class - Adding
<haxeflag name="-dce no" />
inproject.xml
(as per other forum posts) - Adding
<haxeflag name="-dce" value="no" />
inproject.xml
(as per the lime Project XML docs)
None of this seems to resolve the crash.
I also don’t have (and can’t easily install) the debug version of Flash to see what that generates.
Any ideas?