haxegon icon indicating copy to clipboard operation
haxegon copied to clipboard

HTML5 doesn't load static Main classes

Open TerryCavanagh opened this issue 7 years ago • 5 comments

Getting a weird bug right now where HTML5 won't run static Scene classes. This is super weird and new! Will look into it after 7drl.

TerryCavanagh avatar Mar 09 '18 18:03 TerryCavanagh

OK! As a workaround, it looks like things will behave as expected if you just put a blank constructor in your class. I guess I must have broken this when changing from new to init as the startup function.

I'm working around it for now; will fix it next week.

TerryCavanagh avatar Mar 09 '18 19:03 TerryCavanagh

from @randomnine :

if you're trying to include something from a package, you add
<haxeflag name="--macro include('package')" />
which would force it to include class in "package". eg package.Main

TerryCavanagh avatar Mar 09 '18 19:03 TerryCavanagh

Oh, weird!

<haxeflag name="--macro include('package')" />

Doesn't fix it - in fact, the generated .js file DOES include the static function from Main - it's just that Scene doesn't see them.

TerryCavanagh avatar Mar 20 '18 13:03 TerryCavanagh

Hmm, ok, not sure what's going on here right now. Gonna leave it for a while.

It doesn't seem to be a dce problem - the classes are in the .js file, and disabling dce doesn't change anything.

Also, I put together a little test haxe project, and it's not happening there. So... I'm kinda stumped! I'll try again later!

staticfunctiontest.zip

TerryCavanagh avatar Mar 20 '18 14:03 TerryCavanagh

Ok, this test in Scene.hx:

trace(Type.getClass(maininstance) == null);

On html, this is true (unless the class has a "new" function). It's false on all other targets. This is why things are going wrong for haxegon.

If I can make a test case for this, then perhaps I can submit a bug to the haxe project, and have it fixed in a later version of the compiler.

Much better, though, would to be figure out a workaround...

TerryCavanagh avatar Mar 20 '18 21:03 TerryCavanagh