Android, native app can't start when I use std::vector::push_back()

692 views Asked by At


I need to use the vector container in my native application (it's cocos-2dx framework) So, I've added

APP_STL := stlport_static

to Application.mk Then

#include <vector>

in header file for the class which uses vector Define the variable as

std::vector<cocos2d::CCPoint*> *m_VertexAnchors;

And then do this

m_VertexAnchors->push_back(point);

point here is actually CCPoint* point And when I run my app I just see the black screen than it disappears after 2-3 sec without any message. The last message in logcat is (filter by application name and with verbose level)

04-01 13:22:57.068: D/dalvikvm(2939): GC_EXTERNAL_ALLOC freed 64K, 47% free 2887K/5379K, external 0K/0K, paused 40ms

and there are no errors before just messages about loading libs. And I've not seen anything strange in the main log. Then when I commented out

m_VertexAnchors->push_back(point);

the app works fine.

So, is there anything I've missed, if no how could I debug this (I use Eclipse with sequoyah plugin)

Will appreciate any help or suggestions, thanks.

1

There are 1 answers

1
hmjd On BEST ANSWER

Before using m_vertexAnchors you must initialize it correctly:

m_VertexAnchors = new std::vector<cocos2d::CCPoint*>();

you must remember to delete it when no longer required.

If you can avoid dynamically allocating the vector then declare it as:

std::vector<cocos2d::CCPoint*> m_VertexAnchors;

and use it:

m_VertexAnchors.push_back(point);