OpenFl/Starling mask strange behavior with -final build


I found strange things with masks.

var mcScrollView - is empty Sprite from GUI constructor (see on picture)

var visibleRect = new Rectangle(0, 0, 530, 350);
var mcContainer = new Sprite();


var quad:Quad = new Quad(visibleRect.width, visibleRect.height);
quad.x = visibleRect.x;
quad.y = visibleRect.y;
mcScrollView.mask = quad;

mcContainer.addChild(new FaqSlot());
mcContainer.addChild(new FaqSlot());
mcContainer.addChild(new FaqSlot());
code to implement scrolling content (I change _mcContainer.y)

All works as expected for openfl build html5 -debug:

But for openfl build html5 -final --no-traces I see strange position and size of masking:

Like visibleRect = new Rectangle(0, -30, 400, 280);

Do you have any ideas?)

That’s… interesting :slight_smile:

You are running on Starling 2.7 ? (if you use the “current-as3-starling” branch on my repo please specify so that I know where to look)

1 Like

There’s probably some kind of reflection being used. Either in your project’s code or in Starling’s code. Reflection often doesn’t work well with -final, since -final enables more aggressive dead code elimination (dce).

I remember that I had to put in a decent amount of work to get Feathers UI working with -final because Actuate.tween() isn’t compatible with -final, and I had to switch to Actuate.update() instead, to force my code to be more strongly typed. There’s probably a similar issue with Starling’s Tween class, since it uses reflection, but that may not necessarily be the cause of the issue at hand. I only mention this because the mask appears to be used for scrolling, and scrolling is often animated.



It happens independ of scrolling.

I have the same problem. I need tween class field (set property).
With -debug all right. There are many updates per second and finally property turn into right value.
With -final there are only one or two updates and property turn into custom value. It is strange. I add onComplete() to manually set property at the end of tween.

Actuate.update() use tween() inside. So what difference for this case?

What can you recommend? I think I need -final for production version.

Actuate.update() accepts a function, rather than an anonymous structure, so the compiler is aware of exactly which properties are being animated, and they won’t be removed by dce.

Actuate.update((scrollY:Float) -> {
	scroller.scrollY = scrollY;
}, duration, [scroller.scrollY], [targetScrollY], true);

It might make sense to add something similar to Tween or Juggler in Starling.

There is also -release. If I had to guess, most people use -release because of the extra work required for -final to work.

1 Like

I don’t understand why but Actuate.update() helps in my case) Thanks!

I think -final is minify version of -release. So it is less weight and more secure for production.

You could try with -release and -minify. I think that this will avoid the full DCE of -final, while still minifying the release output.

openfl build html5 -release -minify
1 Like

if you can, please explain how it helps ? You mean using it or looking at the code ? I’m quite busy currently but I’d like to help make Starling as “perfect” as possible.

Also, have you tried reproducing your mask issue outside of your game ?

@Matse thx!

About Actuate.tween
Actuate is not part of Starling. So there are no complaints to Starling)

I have

public var count(get, set):Int;
function set_count(value:Int):Int
function get_count():Int

I replace
Actuate.tween(this, _duration, {count: newValue});
Actuate.update(set_count, _duration, [count], [newValue]);

About mask
Only now I noticed, that problem present on remote server. And no problem with local Visual Studio “Live Server”. And -final -release -debug flags do not affect on this!
Browser is the same. It is magic!)


Thx! But .js file size has doubled) I think size difference is because of I don’t use all of lime|OpenFL|Starling classes in my project. Not only DCE. So I prefer -final for now. But I will keep in mind -release -minify

I mean, it’s totally fine to use -final. Ideally, you should want to use -final, but I understand when some developers prefer not to put in the extra effort that is sometimes required. The main thing to remember with -final is that you must ensure that you aren’t using reflection on Haxe classes (either explicitly with the Reflect class, or sometimes implicitly with the Dynamic type).