cocos creator 3.7.4下 RenderTexture.readPixels()在安卓14上报错

cocos creator 3.7.4下调用this.screenShotRT.readPixels()时在安卓14上报错:
[ERROR] file /Applications/Cocos/Creator/3.7.4/CocosCreator.app/Contents/Resources/resources/3d/engine/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp: line 3205
[ERROR]: glReadPixels(region.texOffset.x, region.texOffset.y, region.texExtent.width, region.texExtent.height, glFormat, glType, copyDst) returned GL error: 0x506

在安卓10和苹果手机上没报错。我渲染的UI是在屏幕之外。我需要把渲染的ui保存下来并分享出去。我尝试把渲染UI放到屏幕内也不行。不知是怎么回事

在start方法的下一帧设置gfx.ColorAttachment参数就可以了

protected start() {
if(sys.platform == sys.Platform.ANDROID) {
this._bgNode.setScale(v3(1,-1,1));
}

    this.scheduleOnce(()=>{
        if(sys.platform == sys.Platform.ANDROID) {
            const gfxAPI = director.root.pipeline.device.gfxAPI;

            this.screenShotRT = new RenderTexture();    

            const colorAttachment = new gfx.ColorAttachment(
                gfx.Format.RGBA8,      // 颜色格式
                gfx.SampleCount.ONE,    // 采样数
                gfx.LoadOp.CLEAR,      // 加载操作:清除
                gfx.StoreOp.STORE,     // 存储操作:保存
                null,                  // 通用屏障(可选)
                false                  // 是否使用通用布局
            );

            const passInfo = new gfx.RenderPassInfo(
                [colorAttachment],             // 颜色附件数组
                null
            );

            this.screenShotRT.reset({
                name: 'CustomRenderTexture',
                width:750,
                height:1650,
                passInfo:passInfo
            });

            this._camera.targetTexture = this.screenShotRT
            this._camera.clearFlags = gfx.ClearFlagBit.COLOR;
            this._camera.clearColor = new Color(0, 0, 0, 0); 
        }
    });
}

screenShotAndSave(shareScene: WXScene) {
this.scheduleOnce(()=>{
let pixelData = this.screenShotRT.readPixels();

});
}

1赞