cocos2d-x 给函数接口生命周期添加检测函数,用于调试程序时检测错误。
2013-08-23 12:20
609 查看
cocos2d-x 游戏开发时,遇到崩溃往往需要自己一步一步的慢慢调试,这种方法比较费时间,我们可以采用在开发时给函数的入口处添加生命周期检测函数。这样可以从控制台打印信息看出程序出问题时所在函数。(如果是采用 "autorelease()" 处理的内存,会在当前帧执行过后才释放内存,这时候出现内存用次方法还是不能看出。。有人有更好的解决方法可以留言~~);
该类声明后只需要在需要检测的函数中,调用宏
FUNCTION_LIFE_LOG
就行。
如:
bool
AppDelegate::applicationDidFinishLaunching()
{
FUNCTION_LIFE_LOG
//打印函数周期
// initialize director
CCDirector *pDirector =
CCDirector::sharedDirector();
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
// turn on display FPS
pDirector->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 /
60);
// create a scene. it's an autorelease object
CCScene *pScene =
HelloWorld::scene();
// run
pDirector->runWithScene(pScene);
return
true;
}
会在进入函数时 打印
applicationDidFinishLaunching BEGIN!!!
在离开函数以后(return true; 之后)
打印
applicationDidFinishLaunching END!!!
// // FunctionLifeLog.h // TouchSprite // // Created by LangYi on 13-8-23. // // #ifndef __TouchSprite__FunctionLifeLog__ #define __TouchSprite__FunctionLifeLog__ #include "cocos2d.h" class FunctionLifeLog:public cocos2d::CCObject { public: inline FunctionLifeLog() { m_strMsg = cocos2d::CCString::create(""); } inline FunctionLifeLog(const char* msg) { m_strMsg = cocos2d::CCString::create(msg); cocos2d::CCLog("%s BEGIN!!!",m_strMsg->getCString()); } inline ~FunctionLifeLog() { cocos2d::CCLog("%s END!!!",m_strMsg->getCString()); } private: cocos2d::CCString* m_strMsg; }; #define FUNCTION_LIFE_LOG FunctionLifeLog(__FUNCTION__); #endif /* defined(__TouchSprite__FunctionLifeLog__) */
该类声明后只需要在需要检测的函数中,调用宏
FUNCTION_LIFE_LOG
就行。
如:
bool
AppDelegate::applicationDidFinishLaunching()
{
FUNCTION_LIFE_LOG
//打印函数周期
// initialize director
CCDirector *pDirector =
CCDirector::sharedDirector();
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
// turn on display FPS
pDirector->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 /
60);
// create a scene. it's an autorelease object
CCScene *pScene =
HelloWorld::scene();
// run
pDirector->runWithScene(pScene);
return
true;
}
会在进入函数时 打印
applicationDidFinishLaunching BEGIN!!!
在离开函数以后(return true; 之后)
打印
applicationDidFinishLaunching END!!!
相关文章推荐
- 在XCode4中添加程序调试错误信息和公司名注释
- Java 中的 int 与 Integer 用于 List<Integer> 时,以及通过打印变量检测程序运行和函数调用次数计数
- 写了一个将VxWorks的shell打印输出到指定内存中的接口,可广泛用于CLI下的调试函数显示以及故障自动捕获等功能,稍作修改可以适合其它嵌入式OS
- # include <errno.h >查看错误代码errno是调试程序的一个重要方法。当Linux C API函数发生异常时,一般会将errno变量赋值一个整数,不同的值表示不同的含义,可以通过查看
- 在XCode4中添加程序调试错误信息
- gdb core dump调试程序错误
- c语言中如何添加计时函数,统计程序执行的时间
- HTTP 错误 404.3 - Not Found 由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序。如果应下载文件,请添加 MIME 映射。
- 我常用的自定义函数之p 用于打印数据,调试代码很方便
- 添加第三方类库造成的linker command failed with exit code 1 (use -v to see invocation)的错误调试
- 错误 类型“ESRI.ArcGIS.esriSystem.ISupportErrorInfo”在未被引用的程序集中定义。必须添加对程序集“ESRI.ArcGIS.System
- C/C++程序调试的函数
- 本地调试WCF程序出现错误:AddressAccessDeniedException: HTTP could not register URL
- 基于VS与IIS程序调试,银行支付接口调试操作
- 安装Visual Studio.net 2003总是会收到“一个安装程序检测到另一个程序需要重新启动计算机”的错误消息
- Cocos2d-x Eclipse下程序运行产生错误Effect initCheck() returned -1
- 调试Release发布版程序的Crash错误
- 给MFC程序添加运行时调试窗口
- VS使用进程调试出现“没有正确安装调试器。请运行安装程序安装或修复调试器”的错误,解决方法。
- Qt调用DLL动态库接口函数程序崩掉