1.修正gles版本过低时会崩溃的问题

2.修正unscheduleAllSelectors()中遍历哈希表导致崩溃的问题
This commit is contained in:
RongHong 2011-06-03 15:22:50 +08:00
parent a5c9b8631c
commit a13e8ae859
10 changed files with 156 additions and 6 deletions

View File

@ -436,11 +436,15 @@ void CCScheduler::unscheduleUpdateForTarget(const SelectorProtocol *pTarget)
void CCScheduler::unscheduleAllSelectors(void)
{
// Custom Selectors
tHashSelectorEntry *pElement;
tHashSelectorEntry *pElement = NULL;
tHashSelectorEntry *pNextElement = NULL;
for (pElement = m_pHashForSelectors; pElement != NULL;)
{
// pElement may be removed in unscheduleAllSelectorsForTarget
pNextElement = (tHashSelectorEntry *)pElement->hh.next;
unscheduleAllSelectorsForTarget(pElement->target);
pElement = (tHashSelectorEntry *)pElement->hh.next;
pElement = pNextElement;
}
// Updates selectors

View File

@ -30,4 +30,26 @@ const char* cocos2dVersion()
{
return "cocos2d v0.99.5";
}
eGLESVersion getGlesVersion()
{
std::string strVersion((char *)glGetString(GL_VERSION));
if (strVersion.find("1.0") != -1)
{
return GLES_VER_1_0;
}
else if (strVersion.find("1.1") != -1)
{
return GLES_VER_1_1;
}
else if (strVersion.find("2.0") != -1)
{
return GLES_VER_2_0;
}
return GLES_VER_INVALID;
}
}//namespace cocos2d

View File

@ -33,12 +33,28 @@ namespace cocos2d
: m_fbo(0)
, m_oldFBO(0)
{
m_eGlesVersion = getGlesVersion();
// If the gles version is lower than GLES_VER_1_0,
// all the functions in CCGrabber return directly.
if (m_eGlesVersion <= GLES_VER_1_0)
{
return ;
}
// generate FBO
ccglGenFramebuffers(1, &m_fbo);
}
void CCGrabber::grab(cocos2d::CCTexture2D *pTexture)
{
// If the gles version is lower than GLES_VER_1_0,
// all the functions in CCGrabber return directly.
if (m_eGlesVersion <= GLES_VER_1_0)
{
return ;
}
glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &m_oldFBO);
// bind
@ -60,6 +76,13 @@ namespace cocos2d
void CCGrabber::beforeRender(cocos2d::CCTexture2D *pTexture)
{
// If the gles version is lower than GLES_VER_1_0,
// all the functions in CCGrabber return directly.
if (m_eGlesVersion <= GLES_VER_1_0)
{
return ;
}
glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &m_oldFBO);
ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_fbo);
@ -78,12 +101,26 @@ namespace cocos2d
void CCGrabber::afterRender(cocos2d::CCTexture2D *pTexture)
{
// If the gles version is lower than GLES_VER_1_0,
// all the functions in CCGrabber return directly.
if (m_eGlesVersion <= GLES_VER_1_0)
{
return ;
}
ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_oldFBO);
glColorMask(true, true, true, true); // #631
}
CCGrabber::~CCGrabber()
{
// If the gles version is lower than GLES_VER_1_0,
// all the functions in CCGrabber return directly.
if (m_eGlesVersion <= GLES_VER_1_0)
{
return ;
}
CCLOGINFO("cocos2d: deallocing %p", this);
ccglDeleteFramebuffers(1, &m_fbo);
}

View File

@ -25,6 +25,7 @@ THE SOFTWARE.
#ifndef __EFFECTS_CCGRABBER_H__
#define __EFFECTS_CCGRABBER_H__
#include "cocos2d.h"
#include "CCObject.h"
#include "CCGL.h"
@ -46,6 +47,8 @@ namespace cocos2d
protected:
GLuint m_fbo;
GLint m_oldFBO;
eGLESVersion m_eGlesVersion;
};
} // end of namespace cocos2d

View File

@ -120,6 +120,17 @@ THE SOFTWARE.
namespace cocos2d {
const char* cocos2dVersion();
enum eGLESVersion
{
GLES_VER_INVALID,
GLES_VER_1_0,
GLES_VER_1_1,
GLES_VER_2_0
};
eGLESVersion CC_DLL getGlesVersion();
}//namespace cocos2d
#endif // __COCOS2D_H__

View File

@ -1114,6 +1114,12 @@ void CCTransitionCrossFade::onEnter()
// create the first render texture for inScene
CCRenderTexture* inTexture = CCRenderTexture::renderTextureWithWidthAndHeight((int)size.width, (int)size.height);
if (NULL == inTexture)
{
return;
}
inTexture->getSprite()->setAnchorPoint( ccp(0.5f,0.5f) );
inTexture->setPosition( ccp(size.width/2, size.height/2) );
inTexture->setAnchorPoint( ccp(0.5f,0.5f) );

View File

@ -62,6 +62,12 @@ void CCTransitionRadialCCW::onEnter()
// create the second render texture for outScene
CCRenderTexture *outTexture = CCRenderTexture::renderTextureWithWidthAndHeight((int)size.width, (int)size.height);
if (NULL == outTexture)
{
return;
}
outTexture->getSprite()->setAnchorPoint(ccp(0.5f,0.5f));
outTexture->setPosition(ccp(size.width/2, size.height/2));
outTexture->setAnchorPoint(ccp(0.5f,0.5f));

View File

@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "cocos2d.h"
#include "CCRenderTexture.h"
#include "CCDirector.h"
#include "platform/platform.h"
@ -84,8 +85,16 @@ CCRenderTexture * CCRenderTexture::renderTextureWithWidthAndHeight(int w, int h)
CC_SAFE_DELETE(pRet)
return NULL;
}
bool CCRenderTexture::initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat)
{
// If the gles version is lower than GLES_VER_1_0,
// some extended gles functions can't be implemented, so return false directly.
if (getGlesVersion() <= GLES_VER_1_0)
{
return false;
}
bool bRet = false;
do
{

View File

@ -1,3 +1,4 @@
#include "cocos2d.h"
#include "RenderTextureTest.h"
static int sceneIdx = -1;
@ -115,11 +116,24 @@ std::string RenderTextureTestDemo::subtitle()
}
RenderTextureTest::RenderTextureTest()
: m_brush(NULL)
{
if (cocos2d::getGlesVersion() <= GLES_VER_1_0)
{
CCMessageBox("The Opengl ES version is lower than 1.1, and the test may not run correctly.", "Cocos2d-x Hint");
return;
}
CCSize s = CCDirector::sharedDirector()->getWinSize();
// create a render texture, this is what we're going to draw into
m_target = CCRenderTexture::renderTextureWithWidthAndHeight(s.width, s.height);
if (NULL == m_target)
{
return;
}
m_target->setPosition(ccp(s.width/2, s.height/2));
// note that the render texture is a cocosnode, and contains a sprite of it's texture for convience,
@ -138,7 +152,11 @@ RenderTextureTest::RenderTextureTest()
RenderTextureTest::~RenderTextureTest()
{
m_brush->release();
if (NULL != m_brush)
{
m_brush->release();
m_brush = NULL;
}
}
void RenderTextureTest::ccTouchesMoved(CCSet* touches, CCEvent* event)
@ -203,6 +221,11 @@ RenderTextureIssue937::RenderTextureIssue937()
/* A2 & B2 setup */
CCRenderTexture *rend = CCRenderTexture::renderTextureWithWidthAndHeight(32, 64);
if (NULL == rend)
{
return;
}
// It's possible to modify the RenderTexture blending function by
// [[rend sprite] setBlendFunc:(ccBlendFunc) {GL_ONE, GL_ONE_MINUS_SRC_ALPHA}];

View File

@ -212,10 +212,39 @@ CCTransitionScene* createTransition(int nIndex, ccTime t, CCScene* s)
case 22: return CCTransitionSlideInR::transitionWithDuration(t, s);
case 23: return CCTransitionSlideInT::transitionWithDuration(t, s);
case 24: return CCTransitionSlideInB::transitionWithDuration(t, s);
case 25:
{
if (getGlesVersion() <= GLES_VER_1_0)
{
CCMessageBox("The Opengl ES version is lower than 1.1, and TransitionCrossFade may not run correctly, it is ignored.", "Cocos2d-x Hint");
return NULL;
}
return CCTransitionCrossFade::transitionWithDuration(t,s);
}
break;
case 26:
{
if (getGlesVersion() <= GLES_VER_1_0)
{
CCMessageBox("The Opengl ES version is lower than 1.1, and TransitionRadialCCW may not run correctly, it is ignored.", "Cocos2d-x Hint");
return NULL;
}
case 25: return CCTransitionCrossFade::transitionWithDuration(t,s);
case 26: return CCTransitionRadialCCW::transitionWithDuration(t,s);
case 27: return CCTransitionRadialCW::transitionWithDuration(t,s);
return CCTransitionRadialCCW::transitionWithDuration(t,s);
}
break;
case 27:
{
if (getGlesVersion() <= GLES_VER_1_0)
{
CCMessageBox("The Opengl ES version is lower than 1.1, and TransitionRadialCW may not run correctly, it is ignored.", "Cocos2d-x Hint");
return NULL;
}
return CCTransitionRadialCW::transitionWithDuration(t,s);
}
break;
case 28: return PageTransitionForward::transitionWithDuration(t, s);
case 29: return PageTransitionBackward::transitionWithDuration(t, s);
case 30: return CCTransitionFadeTR::transitionWithDuration(t, s);