cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.24k stars 7.05k forks source link

newDepthStencilStateWithDescriptor 返回非nil 但无效的值 #20572

Open spring-zh opened 4 years ago

spring-zh commented 4 years ago

Steps to Reproduce:

  1. 调式运行demo进入 36: Node Physics3D(6 : Physics3D Terrain)
  2. 快速点击屏幕发射方块,偶现 newDepthStencilStateWithDescriptor 返回非nil 但无效的值 (DepthStencilStateMTL.mm 127行), 导致CommandBufferMTL::prepareDrawing() -> [_mtlRenderEncoder setDepthStencilState:_mtlDepthStencilState];奔溃 (CommandBufferMTL.mm 408行)
devekaam commented 4 years ago

I have the same issue. I think this crash is produced only when the App is run via Xcode. So, If Metal API Validation is unchecked in Xcode (Product>Scheme>Edit Scheme>Run>Diagnostics>Metal API Validation), this crash never happen.

So, I don't know this should be fixed or not.

devekaam commented 3 years ago

this crash never happen.

Sorry, some old devices, such as iPad mini 2nd, still crash even if the Metal API Validation is unchecked.

To avoid this crash, I edited "DepthStencilStateMTL.mm" like below as it's mentioned here https://github.com/cocos2d/cocos2d-x/issues/20453#issuecomment-643107153

DepthStencilStateMTL::~DepthStencilStateMTL()
{
    //[_mtlDepthStencilState release];
    _mtlDepthStencilState = nil;
}

then crash never happenes.

krow40 commented 3 years ago

@devekaam in my testing removing [_mtlDepthStencilState release]; caused a memory leak (confirmed in Instruments). The underlying cause of the crash was elsewhere, in my code not in Cocos2d-x, and running with Guard Malloc pinpointed it.

killwithoutmercy commented 1 year ago

it occurred to me too