我需要在我的本机应用程序中使用向量容器(它是cocos-2dx框架)
所以,我已经添加了
APP_STL:= stlport_static
到Application.mk
然后
#include <vector>
在使用vector的类的头文件中 将变量定义为
std::vector<cocos2d::CCPoint*> *m_VertexAnchors;
然后这样做
m_VertexAnchors->push_back(point);
point
这里实际上是CCPoint* point
当我运行我的应用程序时,我只看到黑屏,而不是在2-3秒后消失,没有任何消息。
logcat中的最后一条消息是(按应用程序名称过滤并使用详细级别)
04-01 13:22:57.068:D / dalvikvm(2939):GC_EXTERNAL_ALLOC释放64K,47% 自由2887K / 5379K,外部0K / 0K,暂停40ms
并且在关于加载libs的消息之前没有错误。我在主日志中没有看到任何奇怪的东西。 然后当我评论出
m_VertexAnchors->push_back(point);
该应用程序运行良好。
所以,有什么我错过的,如果没有我怎么调试这个(我使用Eclipse与sequoyah插件)
感谢任何帮助或建议,谢谢。
答案 0 :(得分:0)
在使用m_vertexAnchors
之前,您必须正确初始化它:
m_VertexAnchors = new std::vector<cocos2d::CCPoint*>();
在不再需要时,您必须记得delete
。
如果可以避免动态分配vector
,则将其声明为:
std::vector<cocos2d::CCPoint*> m_VertexAnchors;
并使用它:
m_VertexAnchors.push_back(point);