[0]_calculateCacheRect函数有bug

_calculateCacheRect函数有bug,导致带发光滤镜的html文本,反复从舞台上添加和删除时getSelfBounds获取的显示区域原始值被修改,
计算显示区域边的越来越大,显存和内存会一直增加,目前看了下,只有HTMLDivElement调用了setSelfBounds的接口,所有只有这个控件有这个问题。
 
下面是个人修改的代码,使用一个临时变量处理getSelfBounds获得的数据;自测了下没啥问题。(ps laya1应该也有这个问题。)
 
 reset() {
            this.releaseContext();
            this.releaseFilterCache();
            this.cacheAs = "none";
            this.enableCanvasRender = false;
            this.userSetCache = "none";
            this.cacheForFilters = false;
            this.staticCache = false;
            this.reCache = true;
            this.mask = null;
            this.maskParent = null;
            this.filterCache = null;
            this.filters = null;
            this.hasGlowFilter = false;
            //getSelfBound拿到的Bounds会被直接修改;
            //用一个临时变量处理
            if(!this.tempRect){
                this.tempRect = Rectangle.create();
            }
            if (this.cacheRect)
                this.cacheRect.recover();
            this.cacheRect = null;
            return this;
        }
 
_calculateCacheRect(sprite, tCacheType, x, y) {
            var _cacheStyle = sprite._cacheStyle;
            if (!_cacheStyle.cacheRect)
                _cacheStyle.cacheRect = Rectangle.create();
            var tRec;
            if (tCacheType === "bitmap") {
                //用sprite.getSelfBounds(),原先的值会被修改;导致设置了selfBounds的对象,
                //宽高越来越大;用一个临时对象处理相关数据;
                this.tempRect.copyFrom(sprite.getSelfBounds());
                tRec = this.tempRect;
                tRec.width = tRec.width + CacheStyle.CANVAS_EXTEND_EDGE * 2;
                tRec.height = tRec.height + CacheStyle.CANVAS_EXTEND_EDGE * 2;
                tRec.x = tRec.x - sprite.pivotX;
                tRec.y = tRec.y - sprite.pivotY;
                tRec.x = tRec.x - CacheStyle.CANVAS_EXTEND_EDGE;
                tRec.y = tRec.y - CacheStyle.CANVAS_EXTEND_EDGE;
                tRec.x = Math.floor(tRec.x + x) - x;
                tRec.y = Math.floor(tRec.y + y) - y;
                tRec.width = Math.floor(tRec.width);
                tRec.height = Math.floor(tRec.height);
                _cacheStyle.cacheRect.copyFrom(tRec);
            }
            else {
                _cacheStyle.cacheRect.setTo(-sprite._style.pivotX, -sprite._style.pivotY, 1, 1);
            }
            tRec = _cacheStyle.cacheRect;
            if (sprite._style.scrollRect) {
                var scrollRect = sprite._style.scrollRect;
                tRec.x -= scrollRect.x;
                tRec.y -= scrollRect.y;
            }
            CacheStyle._scaleInfo.setTo(1, 1);
            return CacheStyle._scaleInfo;
        }
    }
QQ图片20210615155003.png
已邀请:

Laya_XS

赞同来自:

谢谢反馈问题,我们按你描述的情况写case测试下。

要回复问题请先

商务合作
商务合作