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.

Home Page:https://www.cocos.com/en/cocos2d-x

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[METAL] [iOS] Random crash when setting up MetalBuffers

IcemarkUK opened this issue · comments

  • cocos2d-x version: v4
  • devices test on: iPad mini (5th gen), iPhoneX, iPhone 13 Pro, iPad (8th gen)
  • developing environments
    • NDK version: N/A
    • Xcode version: 13.2.1 (13C100)
    • VS version: N/A
    • browser type and version: N/A

Steps to Reproduce:

Random crash while app running. There appears to no pattern.
Appears to an issue with setting up Metal Buffer mainly shows itself on Text but the included DrawNode version looks the same.

The following crashes have occurred multiple times on multiple devices and all seem similar in nature.

mach_msg_trap + 8
mach_msg + 76 (mach_msg.c:119)
io_connect_method + 440
IOConnectCallMethod + 236 (IOKitLib.c:2270)
IOGPUResourceCreate + 224 (IOGPUResourceRef.c:141)
[IOGPUMetalResource initWithDevice:options:args:argsSize:] + 408 (IOGPUMetalResource.m:324)
[IOGPUMetalBuffer initWithPrimaryBuffer:heapIndex:bufferIndex:bufferOffset:length:args:argsSize:] + 276 (IOGPUMetalBuffer.m:286)
[AGXBuffer(Internal) initWithDevice:length:options:isSuballocDisabled:resourceInArgs:pinnedGPULocation:] + 260 (agxa_buffer_util.h:67)
[AGXBuffer initWithDevice:length:options:isSuballocDisabled:pinnedGPULocation:] + 40 (agxa_buffer.mm:187)
cocos2d::backend::BufferMTL::BufferMTL(id<MTLDevice>, unsigned long, cocos2d::backend::BufferType, cocos2d::backend::BufferUsage) (in midnight) + 168
cocos2d::backend::DeviceMTL::newBuffer(unsigned long, cocos2d::backend::BufferType, cocos2d::backend::BufferUsage) (in midnight) + 100
cocos2d::CustomCommand::createIndexBuffer(cocos2d::backend::IndexFormat, unsigned long, cocos2d::backend::BufferUsage) (in midnight) + 124
cocos2d::CustomCommand::createIndexBuffer(cocos2d::backend::IndexFormat, unsigned long, cocos2d::backend::BufferUsage) (in midnight) + 124
cocos2d::Label::updateEffectUniforms(cocos2d::Label::BatchCommand&, cocos2d::TextureAtlas*, cocos2d::Renderer*, cocos2d::Mat4 const&) (in midnight) + 564
cocos2d::Label::draw(cocos2d::Renderer*, cocos2d::Mat4 const&, unsigned int) (in midnight) + 1260
cocos2d::Label::visit(cocos2d::Renderer*, cocos2d::Mat4 const&, unsigned int) (in midnight) + 616
cocos2d::Node::visit(cocos2d::Renderer*, cocos2d::Mat4 const&, unsigned int) (in midnight) + 416
cocos2d::ProtectedNode::visit(cocos2d::Renderer*, cocos2d::Mat4 const&, unsigned int) (in midnight) + 580
cocos2d::ui::Layout::stencilClippingVisit(cocos2d::Renderer*, cocos2d::Mat4 const&, unsigned int) (in midnight) + 720
cocos2d::Node::visit(cocos2d::Renderer*, cocos2d::Mat4 const&, unsigned int) (in midnight) + 416
cocos2d::TransitionCrossFade::onEnter() (in midnight) + 340
cocos2d::Director::setNextScene() (in midnight) + 260
cocos2d::Director::drawScene() (in midnight) + 192
cocos2d::Director::mainLoop() (in midnight) + 148

This looks similar but crashes before getting to the metal buffer. Code makes me thin that the index buffer is missing which might be linked to the above crash.

cocos2d::CustomCommand::updateIndexBuffer(void**, unsigned long) (in midnight) + 8*
cocos2d::Label::updateBuffer(cocos2d::TextureAtlas* *, cocos2d::CustomCommand&) (in midnight) + 160
cocos2d::Label::updateEffectUniforms(cocos2d::Label::BatchCommand&, cocos2d::TextureAtlas**, cocos2d::Renderer* *, cocos2d::Mat4 const&) (in midnight) + 72
cocos2d::Label::draw(cocos2d::Renderer**, cocos2d::Mat4 const&, unsigned int) (in midnight) + 1260*
cocos2d::Label::visit(cocos2d::Renderer* *, cocos2d::Mat4 const&, unsigned int) (in midnight) + 616
cocos2d::Node::visit(cocos2d::Renderer**, cocos2d::Mat4 const&, unsigned int) (in midnight) + 416*
cocos2d::Scene::render(cocos2d::Renderer* *, cocos2d::Mat4 const&, cocos2d::Mat4 const**) (in midnight) + 400*
cocos2d::Director::drawScene() (in midnight) + 396*
cocos2d::Director::mainLoop() (in midnight) + 148*
mach_msg_trap + 8
mach_msg + 76 (mach_msg.c:119)
io_connect_method + 440
IOConnectCallMethod + 236 (IOKitLib.c:2270)
IOGPUResourceCreate + 224 (IOGPUResourceRef.c:141)
[IOGPUMetalResource initWithDevice:options:args:argsSize:] + 408 (IOGPUMetalResource.m:324)
[IOGPUMetalBuffer initWithPrimaryBuffer:heapIndex:bufferIndex:bufferOffset:length:args:argsSize:] + 276 (IOGPUMetalBuffer.m:286)
[AGXBuffer(Internal) initWithDevice:length:options:isSuballocDisabled:resourceInArgs:pinnedGPULocation:] + 260 (agxa_buffer_util.h:67)
[AGXBuffer initWithDevice:length:options:isSuballocDisabled:pinnedGPULocation:] + 40 (agxa_buffer.mm:187)
cocos2d::backend::BufferMTL::BufferMTL(id<MTLDevice>, unsigned long, cocos2d::backend::BufferType, cocos2d::backend::BufferUsage) (in midnight) + 332
cocos2d::backend::DeviceMTL::newBuffer(unsigned long, cocos2d::backend::BufferType, cocos2d::backend::BufferUsage) (in midnight) + 100
cocos2d::CustomCommand::createVertexBuffer(unsigned long, unsigned long, cocos2d::backend::BufferUsage) (in midnight) + 96
cocos2d::DrawNode::init() (in midnight) + 136
cocos2d::DrawNode::create(float) (in midnight) + 88
uisinglelord::init() (in midnight) (uisinglelord.cpp:54)
uisinglelord::createWithLord(unsigned int) (in midnight) (uisinglelord.cpp:71)
panel_select::getCharacters() (in midnight) (panel_select.cpp:219)
panel_select::init() (in midnight) (panel_select.cpp:92)
panelmanager::getPanel(panelmode_t) (in midnight) (panelmanager.cpp:106)
panelmanager::setPanelMode(panelmode_t, transition_t, bool) (in midnight) (panelmanager.cpp:68)
moonring::showPage(panelmode_t, unsigned int) (in midnight) (moonring.cpp:139)
panel_look::OnNotification(cocos2d::Ref*) (in midnight) (panel_look.cpp:0)
cocos2d::ui::Widget::releaseUpEvent() (in midnight) + 140

我遇到了同样的报错,经过一星期的测试,可以很轻易的复现这个崩溃,但是我不知道怎么解决。

20220312134051

if判断是false,导致createVertexBuffer没有被执行,导致的后面使用了一个已经被delete的指针
1