Sprites get bigger (and other things with higher zorder) when adding nodes (webgl mode only)

issue environment:

cocos2d-x v3.16
cocos2d-x v3.17  
javascript
chrome

This is really a weird issue, it’s very easy to reproduce:

  1. Create an empty project
cocos new Demo -p com.xxx.xxx -l js -d .
  1. And then modify the app.js a little bit:
var HelloWorldLayer = cc.Layer.extend({
    ctor:function () {
        this._super();
        //
        var helloLabel = new cc.LabelTTF("Hello World", "Arial", 38);
        helloLabel.x = cc.winSize.width / 2;
        helloLabel.y = cc.winSize.height * 0.8;
        this.addChild(helloLabel);

        var self = this;
        this.schedule(function() {
            cc.log("sprite");
            for (var i = 0; i < 50; i++) {
                var node = new cc.Sprite(res.HelloWorld_png);
                node.setPosition(cc.winSize.width * 0.5, cc.winSize.height * 0.5);
                self.addChild(node);
            }
        }, 0.05, 10, 1);

        return true;
    }
});

As you can see, the only thing I do in the layer is create a timer and add some sprites.

I am not sure if the issue will occurs if I change the number of sprites I create each schedule callback to a smaller value , I choose 50 here because the bigger the number is the obvious you will see the issue.

Now run the demo, you will see the sprite added in the center of the layer will get bigger and bigger.

https://discuss.cocos2d-x.org/uploads/default/original/3X/9/5/95a11241bdac2e565e6a88f6c1eb2d2dda4edb4e.mov

And then, if I change the zorder of the label to a value that is higher then the sprite:

 this.addChild(helloLabel, 2);

And then you will see the label is also getting bigger and bigger :

https://discuss.cocos2d-x.org/uploads/default/original/3X/e/b/ebb47fc0b1ae04d3017c82d1f627d94b9a372400.mov

And I also tried this demo in canvas mode but it appears that the issue only occurs in webgl mode.

You can download the demo here :

In one of my project, I am having trouble with this issue when I add some sprites and some other objects in the scene get scaled and offset …

I really want to know the cause of the issue and how to fix it, any advice will be appreciated, thanks :slight_smile: