this issue is quote from: https://github.com/wantnon2/3DToolKit-for-cocos2dx/issues/1
andyque commented (2014-01-20 14:59:44):
My cocos2d-x version is v2.2 and I followed your instructions step by step.
It's easy to get all stuff build and run. But after launching, it crashes.
Here is the crash code line:
CCTextureAtlas.cpp line 636.
glDrawElements(GL_TRIANGLES, (GLsizei) n6, GL_UNSIGNED_SHORT, (GLvoid) (start6sizeof(m_pIndices[0])) );
The Xcode gives me EXC_BAD_ACCESS at the above line.
It seems the memory of n data was unintentional freed before this code line was executed.
quote from: https://github.com/wantnon2/3DToolKit-for-cocos2dx/issues/1
wantnon2 commented (2014-01-20 15:41:51):
i just checked my cocos2d-x 2.2. i found i had made several bug fix to it.
here is the code around your crash location in my cocos2d-x 2.2, see if there are any difference:
//i do not know when the line below is missing, but other cocos2d-x 2.2 seem has this line [yang chao]
ccGLBindVAO(m_uVAOname);//add [yang chao]
#if CC_REBIND_INDICES_BUFFER
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]);
#endif
#if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
glDrawElements(GL_TRIANGLE_STRIP, (GLsizei) n6, GL_UNSIGNED_SHORT, (GLvoid) (start6sizeof(m_pIndices[0])) );
#else
glDrawElements(GL_TRIANGLES, (GLsizei) n6, GL_UNSIGNED_SHORT, (GLvoid) (start6sizeof(m_pIndices[0])) );
#endif // CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
#if CC_REBIND_INDICES_BUFFER
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
#endif
//to avoid glDrawElements crash, here need to unbind VAO. [yang chao]
//see:https://groups.google.com/forum/#!topic/cocos2d-js-devel/2JTlQdKD3BU
ccGLBindVAO(0);//ccGLBindVAO is a wrap of glBindVertexArray
// glBindVertexArray(0);
#else // ! CC_TEXTURE_ATLAS_USE_VAO
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
quote from: https://github.com/wantnon2/3DToolKit-for-cocos2dx/issues/1
andyque commented (2014-01-20 16:20:31):
Cool!
It works like a charm:)
Thanks.
状态更改为 已关闭
found another place should do the same fix (otherwise it may cause crash under some circumstances):
void CCParticleSystemQuad::draw()
{
...
#if CC_TEXTURE_ATLAS_USE_VAO
//
// Using VBO and VAO
//
ccGLBindVAO(m_uVAOname);
#if CC_REBIND_INDICES_BUFFER
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]);
#endif
glDrawElements(GL_TRIANGLES, (GLsizei) m_uParticleIdx*6, GL_UNSIGNED_SHORT, 0);
#if CC_REBIND_INDICES_BUFFER
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
#endif
//fix:
//to avoid glDrawElements crash, here need to unbind VAO. [yang chao]
//see:https://groups.google.com/forum/#!topic/cocos2d-js-devel/2JTlQdKD3BU
ccGLBindVAO(0);//ccGLBindVAO is a wrap of glBindVertexArray
#else
....
}
BTW: maybe there are more places need this fix in cocos2dx 2.2, when i found more i will post it here.
登录 后才可以发表评论