Hello,
I created an empty scene with empty layer, and on tapping that layer I replacing current scene with another one. When I doing that, Visual Studio triggering a breakpoint at dbgheap.c line 1376, which is:
_RPT3(_CRT_ERROR, "HEAP CORRUPTION DETECTED: after %hs block (#%d) at 0x%p.\n" "CRT detected that the application wrote to memory after end of heap buffer.\n", szBlockUseName[_BLOCK_TYPE(pHead->nBlockUse)], pHead->lRequest, (BYTE *) pbData(pHead));
Here my code:
AppDelegate.h
@
#ifndef APP_DELEGATE_H
#define APP_DELEGATE_H
#include “cocos2d.h”
#include “CCApplication.h”
/***
`brief The cocos2d Application.
The reason for implement as private inheritance is to hide some interface call by CCDirector.
*/
class AppDelegate : private cocos2d::CCApplication
{
public:
AppDelegate();
virtual ~AppDelegate();
/**
`brief Implement for initialize OpenGL instance, set source path, etc…
**/
virtual bool initInstance();
/**
brief Implement CCDirector and CCScene init code here.
return true Initialize success, app continue.
`return false Initialize failed, app terminate.
*/
virtual bool applicationDidFinishLaunching();
/**
`brief The function be called when the application enter background
`param the pointer of the application
*/
virtual void applicationDidEnterBackground();
/**
`brief The function be called when the application enter foreground
`param the pointer of the application
*/
virtual void applicationWillEnterForeground();
virtual void applicationViewStateChanged(int newState, int oldState){};
};
#endif // APP_DELEGATE_H
`
AppDelegate.cpp
`#include “AppDelegate.h”
#include “SimpleAudioEngine.h”
#include “BeginScene.h”
#include “CCEGLView.h”
USING_NS_CC;
AppDelegate::AppDelegate()
{
}
AppDelegate::~AppDelegate()
{
// SimpleAudioEngine::end();
}
bool AppDelegate::initInstance()
{
bool bRet = false;
do
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN8_METRO)
// fix bug: 16bit aligned
void* buff=_aligned_malloc(sizeof(CCEGLView),16);
CCEGLView* mainView = new (buff) CCEGLView();
mainView->Create();
mainView->setDesignResolution(2048, 1536); //todo: look to this
#endif // CC_PLATFORM_WIN8_METRO
bRet = true;
} while (0);
return bRet;
}
bool AppDelegate::applicationDidFinishLaunching()
{
// initialize director
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView());
// enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
// pDirector->enableRetinaDisplay(true);
// turn on display FPS
pDirector->setDisplayFPS(false);
//pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
// set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60);
CocosDenshion::SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(1.0);
// create a scene. it's an autorelease object
CCScene *pScene = BeginScene::scene();
// run
pDirector->runWithScene(pScene);
return true;
}
// This function will be called when the app is inactive. When comes a phone call,it’s be invoked too
void AppDelegate::applicationDidEnterBackground()
{
CCDirector::sharedDirector()->pause();
}
// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
CCDirector::sharedDirector()->resume();
}
`
BeginScene.h
`#ifndef BEGIN_SCENE_H
#define BEGIN_SCENE_H
#include “cocos2d.h”
#include “BeginLayer.h”
class BeginScene : public cocos2d::CCScene
{
public:
BeginScene():_layer(NULL) {};
~BeginScene();
bool init();
static cocos2d::CCScene* scene();
CC_SYNTHESIZE_READONLY(BeginLayer*, _layer, Layer);
};
#endif // BEGIN_SCENE_H`
BeginScene.cpp
`#include “BeginScene.h”
using namespace cocos2d;
bool BeginScene::init()
{
if( CCScene::init() )
{
this->_layer = BeginLayer::node();
this->_layer->retain();
this->addChild(_layer);
return true;
}
else
{
return false;
}
}
CCScene* BeginScene::scene()
{
BeginScene * scene = NULL;
do
{
// ‘scene’ is an autorelease object
scene = (BeginScene*)CCScene::node();
CC_BREAK_IF(! scene);
scene->init();
} while (0);
// return the scene
return scene;
}
BeginScene::~BeginScene()
{
if (_layer)
{
_layer->release();
_layer = NULL;
}
}
`
BeginLayer.h
`#include “cocos2d.h”
class BeginLayer : public cocos2d::CCLayerColor
{
public:
BeginLayer() {};
virtual ~BeginLayer();
bool init();
LAYER_NODE_FUNC(BeginLayer);
void registerWithTouchDispatcher();
private:
void ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent* event);
};`
BeginLayer.cpp
`#include “SimpleAudioEngine.h”
#include “BeginLayer.h”
#include “CreatureSelectionScene.h”
using namespace cocos2d;
bool BeginLayer::init()
{
CCLayerColor::initWithColor( ccc4f(255,255,255,255) );
CCSize size = CCDirector::sharedDirector()->getWinSize();
this->setIsTouchEnabled(true);
return true;
}
void BeginLayer::ccTouchesEnded(CCSet* touches, CCEvent* event)
{
CCScene *pScene = CreatureSelectionScene::scene();
CCDirector::sharedDirector()->replaceScene(pScene);
}
void BeginLayer::registerWithTouchDispatcher()
{
CCTouchDispatcher::sharedDispatcher()->addStandardDelegate(this,0);
}
BeginLayer::~BeginLayer()
{
//nothing right now
}`
I will appreciate any help, this issue very bothering me.
Thanks