cocos2d-x icon indicating copy to clipboard operation
cocos2d-x copied to clipboard

when i press power button, MTLDebugCommandBuffer error

Open stray0652 opened this issue 4 years ago • 1 comments

  • cocos2d-x version: 4.0
  • devices test on: iPhone 7, iOS 10

hi. i'm upgrading my app to cocos2d-x v4 because apple deprecated OpenGLES. It is good but when i testing on iOS 10, Xcode give error message [/BuildRoot/Library/Caches/com.apple.xbs/Sources/Metal/Metal-85.83/ToolsLayers/Debug/MTLDebugCommandBuffer.mm:469: failed assertion `No rendertargets set in RenderPassDescriptor.']

this error show when i press power button. when i press home button, it is work. but just press power button and screen off, then error.

i'm trying uncheck 'Metal API Validation' but still not work.

what should i do?

stray0652 avatar Apr 15 '21 07:04 stray0652

It's not a fundamental solution, but I found a solution to prevent the error from occurring

renderer/backend/metal/CommandBufferMTL.mm

in CommandBufferMTL::getRenderCommandEncoder() ... auto mtlDescriptor = toMTLRenderPassDescriptor(renderPassDescriptor); _renderTargetWidth = (unsigned int)mtlDescriptor.colorAttachments[0].texture.width; _renderTargetHeight = (unsigned int)mtlDescriptor.colorAttachments[0].texture.height; ++ if(mtlDescriptor.colorAttachments[0].texture == NULL) ++ { ++ return _mtlRenderEncoder; ++ } id<MTLRenderCommandEncoder> mtlRenderEncoder = [_mtlCommandBuffer renderCommandEncoderWithDescriptor:mtlDescriptor]; [mtlRenderEncoder retain]; ...

and

in CommandBufferMTL::endFrame() [_mtlRenderEncoder endEncoding]; [_mtlRenderEncoder release]; _mtlRenderEncoder = nil;

++ if(DeviceMTL::getCurrentDrawable() != nil) ++ { [_mtlCommandBuffer presentDrawable:DeviceMTL::getCurrentDrawable()]; ++ } _drawableTexture = DeviceMTL::getCurrentDrawable().texture; [_mtlCommandBuffer addCompletedHandler:^(id<MTLCommandBuffer> commandBuffer) { ...

I hope this helps someone.

stray0652 avatar Apr 28 '21 05:04 stray0652