openfl / starling

Known as the "Cross-Platform Game Engine", Starling is a popular Stage3D framework for OpenFL and Haxe
Other
236 stars 68 forks source link

Hashlink Target - Runtime Crashes Fail on Demo #149

Closed benjamin-stern closed 10 months ago

benjamin-stern commented 4 years ago

When trying to compile the application to the Hashlink Target as soon as the application starts it crashes.

On applications where starling is loaded in delay, the Hashlink Target operates and crashes as soon as it loads up starling.

hunkydoryrepair commented 4 years ago

I've run into this as well. It seems to be failing to convert the string parameters to the proper enum types when using Reflection to make the function call to stage3D.requestContext3D (line 253 of RenderUtil.hx)

hunkydoryrepair commented 4 years ago

specifically, we have on line 253:

executeFunc(stage3D.requestContext3D, [renderMode, currentProfile]);

On most platforms, this is expanded to : stage3D.requestContext3D(renderMode, currentProfile)

renderMode and currentProfile are strings, and the stage3D.requestContext3D method takes Int based Enums. Those enums have @:from converters to convert from string to int,

but for js and HashLink this becomes: Reflect.callMethod(stage3D.requestContext3D, [renderMode, currentProfile])

Now, stage3D.requestContext3D doesn't appear to use either of the parameters, but passing a String to an Int parameter in HashLink causes an error, enforcing the correct type is passed. The compiler knows, based on the enum, how to convert, but at runtime the function data only understand the parameter should be an Int, so it cannot convert from a string.

While the parameters don't seem to be used, one possible fix is simply:

executeFunc(stage3D.requestContext3D, [0, 0])

but a better fix is probably to convert the parameters before calling. cast doesn't work so best I can think of is:

 var rm:Context3DRenderMode = renderMode;
 var p:Context3DProfile = currentProfile;
 executeFunc(stage3D.requestContext3D, [rm, p])