3 Star 4 Fork 2

杨超 (wantnon) / the-3DToolKit-for-cocos2dx

 / 详情

The program crashes after launch. EXC_BAD_ACCESS error!!!

已完成
拥有者
创建于  
2014-04-13 01:58

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.

评论 (4)

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.

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(1)
C++
1
https://gitee.com/wantnon2/the-3DToolKit-for-cocos2dx.git
git@gitee.com:wantnon2/the-3DToolKit-for-cocos2dx.git
wantnon2
the-3DToolKit-for-cocos2dx
the-3DToolKit-for-cocos2dx

搜索帮助