cocos / cocos-engine

Cocos simplifies game creation and distribution with Cocos Creator, a free, open-source, cross-platform game engine. Empowering millions of developers to create high-performance, engaging 2D/3D games and instant web entertainment.
https://www.cocos.com/en/creator
Other
8.21k stars 1.94k forks source link

在模拟器预览中连续多次调用device.copyTextureToBuffers方法, 参数不变, 得到的像素信息不一致. #16171

Open zhao-dixun opened 1 year ago

zhao-dixun commented 1 year ago

Cocos Creator version

3.8.0

System information

macos 13.4.1 Editor 模拟器预览方式下启动

Issue description

在模拟器预览中同一代码位置连续多次调用device.copyTextureToBuffers方法, 传入参数不变, 但得到的像素信息不一致.

Relevant error log output

injectWebAssembly ...
src/cocos-js/deprecated-d3200041.js:810 Init Base: 3.646027088165283 ms
src/cocos-js/index-ddde6256.js:650 Failed to set shading scale, pipelineSceneData is invalid.
warn @ src/cocos-js/index-ddde6256.js:650
src/cocos-js/index-ddde6256.js:650 Read json failed: path: /Applications/CocosCreator/Creator/3.8.0/CocosCreator.app/Contents/Resources/resources/3d/engine/native/simulator/Release/SimulatorApp-Mac.app/Contents/Resources/gamecaches/cacheList.json message: Unexpected end of JSON input
warn @ src/cocos-js/index-ddde6256.js:650
src/cocos-js/deprecated-d3200041.js:840 Init Infrastructure: 3.0918259620666504 ms
src/cocos-js/deprecated-d3200041.js:871 Init SubSystem: 368.74774193763733 ms
src/cocos-js/deprecated-d3200041.js:876 Cocos Creator v3.8.0
src/cocos-js/deprecated-d3200041.js:905 Init Project: 104.9889669418335 ms
HitColor.ts:45 --------------device.copyTextureToBuffers---------------
HitColor.ts:47 x: 120 y: 361 buffer: 126,213,22,255
HitColor.ts:49 x: 120 y: 361 buffer: 0,0,0,0
HitColor.ts:51 x: 120 y: 361 buffer: 0,0,0,0
HitColor.ts:53 x: 120 y: 361 buffer: 0,0,0,0
HitColor.ts:45 --------------device.copyTextureToBuffers---------------
HitColor.ts:47 x: 120 y: 361 buffer: 126,213,22,255
HitColor.ts:49 x: 120 y: 361 buffer: 0,0,128,191
HitColor.ts:51 x: 120 y: 361 buffer: 0,0,128,191
HitColor.ts:53 x: 120 y: 361 buffer: 0,0,128,63
HitColor.ts:45 --------------device.copyTextureToBuffers---------------
HitColor.ts:47 x: 120 y: 361 buffer: 126,213,22,255
HitColor.ts:49 x: 120 y: 361 buffer: 0,0,128,191
HitColor.ts:51 x: 120 y: 361 buffer: 0,0,128,191
HitColor.ts:53 x: 120 y: 361 buffer: 0,0,128,63
HitColor.ts:45 --------------device.copyTextureToBuffers---------------
HitColor.ts:47 x: 120 y: 361 buffer: 126,213,22,255
HitColor.ts:49 x: 120 y: 361 buffer: 0,0,0,0
HitColor.ts:51 x: 120 y: 361 buffer: 0,0,0,0
HitColor.ts:53 x: 120 y: 361 buffer: 0,0,0,0
HitColor.ts:45 --------------device.copyTextureToBuffers---------------
HitColor.ts:47 x: 120 y: 361 buffer: 126,213,22,255
HitColor.ts:49 x: 120 y: 361 buffer: 0,0,0,0
HitColor.ts:51 x: 120 y: 361 buffer: 0,0,0,0
HitColor.ts:53 x: 120 y: 361 buffer: 0,0,0,0

No response

Steps to reproduce

被拷贝的texture 为 sprite.spriteFrame.texture

const gfxTexture = texture.getGFXTexture();
const buffer = new Uint8Array(4);
const region = new cc.gfx.BufferTextureCopy();
region.texOffset.x = x;
region.texOffset.y = y;
region.texExtent.width = 1;
region.texExtent.height = 1;

x,y为像素矩阵内的随机一个像素点.

cc.director.root?.device.copyTextureToBuffers(gfxTexture, [buffer], [region]);
console.log(`x: ${x} y: ${y} buffer: ${buffer}`);
cc.director.root?.device.copyTextureToBuffers(gfxTexture, [buffer], [region]);
console.log(`x: ${x} y: ${y} buffer: ${buffer}`);
cc.director.root?.device.copyTextureToBuffers(gfxTexture, [buffer], [region]);
console.log(`x: ${x} y: ${y} buffer: ${buffer}`);
cc.director.root?.device.copyTextureToBuffers(gfxTexture, [buffer], [region]);
console.log(`x: ${x} y: ${y} buffer: ${buffer}`);

Minimal reproduction project

No response

yuwang00 commented 2 months ago

@dumganhar 我们也遇到了同样的问题,请问你们有没有新的进展,如有需要我们可以提供demo

star-e commented 2 months ago

@yuwang00 Sure. You may provide a demo, so we can investigate how this happens. 可以提供一个demo,这样我们查起来更对症一些。