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

newDepthStencilStateWithDescriptor 返回非nil 但无效的值

Open spring-zh opened this issue 5 years ago • 4 comments

  • cocos2d-x version: 4.0
  • devices test on: iphone6, ios12.4.2
  • developing environments
    • NDK version:
    • Xcode version: 11.5
    • VS version:
    • browser type and version:

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行)

spring-zh avatar Aug 27 '20 06:08 spring-zh

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 avatar Oct 26 '20 04:10 devekaam

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.

devekaam avatar Dec 04 '20 19:12 devekaam

@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.

krow40 avatar Mar 01 '21 04:03 krow40

it occurred to me too

killwithoutmercy avatar Aug 09 '23 00:08 killwithoutmercy