tags:

views:

126

answers:

1

I've tried turning on the Call C++ Default Ctors/Dtors in Objective-C flag but I'm still getting an EXC_BAD_ACCESS error when I first try to access my map:

(*[TextureBatcher getSharedTextureBatcher].getMap)[texID].vertexCount=0;
(*[TextureBatcher getSharedTextureBatcher].getMap)[texID].indexCount=0;

getMap just returns a reference to my map:

-(VertexMap *) getMap{
    return &texMap;
}

And a VertexMap is a typedef of a std::map:

typedef std::map<GLuint, VertexInfo> VertexMap;

Not sure why this is failing on device and not in the simulator, any thoughts?

+1  A: 

Just so we're clear:

(*[TextureBatcher getSharedTextureBatcher].getMap)[texID].vertexCount=0;

If theMap[texID] does not exist, the above line will cause a VertexInfo object to be constructed (with the default constructor, VertexInfo()). Is this what you're intending?

Perhaps the underlying std::map is implemented differently on the device, preventing this kind of initialisation?

Are you sure you set the Call C++ Default Ctors/Dtors in Objective-C flag on the Device target, not just the Simulator target?

Generally, the pattern is to use pointers here (C++) so you'd end up with:

typedef std::map<GLunit, VertexInfo*> VertexMap;
VertexMap theMap;

theMap[0] = new VertexInfo(...);

//  now operate on theMap[0] normally

Or did I misunderstand the question?

Josh
Yes, I do want the default constructor to be called. Yes, Default Ctor/Dtor is turned on in the device target. Still scratching my head unfortunately :-\
spencewah
Did you find out what the problem was?
Peter B