Help Need Game crashes on a strange reason.

Hello,
I am making a platformer game. And i have a game crash i can’t solve. I am making my game in Visual Studio 2012. I currently have player and control code. When i run my game everything is working fine for a while but then it crashes and VS gives me error on this line in main.cpp.

return CCApplication::sharedApplication()>run;
This is my output in VS
OpenGL version = 4.1.11247 Compatibility Profile Context
Ready for GLSL
Ready for OpenGL 2.0
‘TheJourney.exe’ : Loaded ‘C:64\ole32.dll’. Cannot find or open the PDB file.
‘TheJourney.exe’ : Unloaded ‘C:64\ole32.dll’
>

cocos2d.x.version: 2.2.0
cocos2d.x.compiled_with_profiler: false
cocos2d.x.compiled_with_gl_state_cache: true
gl.vendor: ATI Technologies Inc.
gl.renderer: AMD Radeon HD 7450
gl.version: 4.1.11247 Compatibility Profile Context
gl.max_texture_size: 16384
gl.max_texture_units: 32
gl.supports_PVRTC: false
gl.supports_NPOT: true
gl.supports_BGRA8888: false
gl.supports_discard_framebuffer: false
gl.supports_vertex_array_object: true

GameManager: Loading Game
LOADING
ControlLayer initialized
DONE
>
First-chance exception at 0x0F8851A7 in TheJourney.exe: 0xC0000005: Access violation reading location 0x00000018.
Unhandled exception at 0x0F8851A7 in TheJourney.exe: 0xC0000005: Access violation reading location 0x00000018.
And this is more information about the crash from VS in a screenshot
http://imgur.com/TmyDkHu
But i tried to find my problem by commenting out some lines and the game didnt crashed when i removed this line:
action = CCAnimate::create);
but then my player doesn’t play walking animation anymore.
My loadPlistForAnimationWithName method.
CCAnimation * GameObject::loadPlistForAnimationWithName
{
CCAnimation animationToReturn = NULL;
>
std::string fullFileName = pListName
“.plist”;
std::string pathFile = “Plists/”fullFileName;
>
//CCLOG);
const char
f=pathFile.c_str;
//CCLOG);
>
CCDictionary plistDictionary = CCDictionary::createWithContentsOfFileThreadSafe;
>
if {
CCLOG (“Error reading plist: %s”, f);
return NULL; // No Plist Dictionary or file found
}
>
CCDictionary
animationSettings = static_cast<CCDictionary*>);
if {
CCLOG (“Could not locate AnimationWithName:%s”,animationName.c_str());
return NULL;
}
>
float animationDelay = animationSettings
>valueForKey(“delay”)>floatValue;
>
animationToReturn = CCAnimation::create;
animationToReturn
>setDelayPerUnit(animationDelay);
>
string animationFramePrefix = animationSettings->valueForKey(“filenamePrefix”)>m_sString;
string animationFrames = animationSettings
>valueForKey(“animationFrames”)->m_sString;
>
char strArr=new char[animationFrames.size1];
strArr[animationFrames.size]=0;
memcpy,animationFrames.size);
>
const char* p;
for ; p; p = strtok)
{
string frameName = animationFramePrefix+p
“.png”;
>
CCSpriteFrame
sprite = CCSpriteFrameCache::sharedSpriteFrameCache()>spriteFrameByName);
animationToReturn
>addSpriteFrame(sprite);
}
return animationToReturn;
}

Please can someone help me with this problem?
If you need more information reply i will send it.
Thanks

I only can give suggestion to debug:

Try to put CCAssert(action != 0) after you call action = CCAnimate::create(this->loadPlistForAnimationWithName(“walkingAnim”,“Player”)); to make sure action is not 0.

I see memory leak in this line:
char *strArr=new char[animationFrames.size()+1]; // you never call delete to strArr.

Inside your function loadPlistForAnimationWithName, try to comment out all codes, make sure it works, then uncomment the line one by one and see if it still works.

If you’re familiar with memory window, try to check the memory each time you assign variable. ex: memcpy(strArr,animationFrames.c_str(),animationFrames.size()); why don’t you use strcpy in this line instead of memcpy?I guess it’s safer.

You don’t seem to be using CCFileUtils. Use that for your paths.

adhika kamaludin wrote:

I only can give suggestion to debug:
>
Try to put CCAssert(action != 0) after you call action = CCAnimate::create(this->loadPlistForAnimationWithName(“walkingAnim”,“Player”)); to make sure action is not 0.
>
I see memory leak in this line:
char *strArr=new char[animationFrames.size()+1]; // you never call delete to strArr.
>
Inside your function loadPlistForAnimationWithName, try to comment out all codes, make sure it works, then uncomment the line one by one and see if it still works.
>
If you’re familiar with memory window, try to check the memory each time you assign variable. ex: memcpy(strArr,animationFrames.c_str(),animationFrames.size()); why don’t you use strcpy in this line instead of memcpy?I guess it’s safer.

Thanks for a Quick answer i will try to fix my issue with your suggestions. Thanks
Cory Trese also thanks for your answer i will use it.

adhika kamaludin wrote:

I only can give suggestion to debug:
>
Try to put CCAssert(action != 0) after you call action = CCAnimate::create(this~~>loadPlistForAnimationWithName); to make sure action is not 0.
>
I see memory leak in this line:
char *strArr=new char[animationFrames.size+1]; // you never call delete to strArr.
>
Inside your function loadPlistForAnimationWithName, try to comment out all codes, make sure it works, then uncomment the line one by one and see if it still works.
>
If you’re familiar with memory window, try to check the memory each time you assign variable. ex: memcpy,animationFrames.size); why don’t you use strcpy in this line instead of memcpy?I guess it’s safer.
Sorry but one more question. Is there a way to retain a animation because i tried to place this into my player.h “CCAnimation *idleAnimation;” and called loadPlistForAnimationWithName to add a animation to it and the i used~~>retain() but it gave me a null pointer.

In your function loadPlistForAnimationWithName, you’re returning an object from this line: animationToReturn = CCAnimation::create(); I don’t think you need to retain. See http://www.cocos2d-x.org/wiki/Reference_Count_and_AutoReleasePool_in_Cocos2d-x for details. There is a part where you don’t need to retain. If your loadPlistForAnimationWithName return null, it’s possibly your pListDictionary or animationSetting is null so you get null pointer.

I also encountered the same problem.

adhika kamaludin wrote:

In your function loadPlistForAnimationWithName, you’re returning an object from this line: animationToReturn = CCAnimation::create(); I don’t think you need to retain. See http://www.cocos2d-x.org/wiki/Reference_Count_and_AutoReleasePool_in_Cocos2d-x for details. There is a part where you don’t need to retain. If your loadPlistForAnimationWithName return null, it’s possibly your pListDictionary or animationSetting is null so you get null pointer.

Thank you.
I figured out the problem is not in my loadPlistForAnimationWithName beacuese when i uncomment it the game doesn’t crash. The error is in CCAnimate::create. The game crashes because of this method. The CCAnimation i have is fine. Could it be a bug? Because it does work for a while the method is playing and then it crashes after a while.