std::map 初始化在 iPhone 设备上崩溃,但在模拟器中则不然
我尝试打开 Call C++ Default Ctors/Dtors in Objective-C
标志,但当我第一次尝试访问我的地图时,仍然收到 EXC_BAD_ACCESS
错误:
(*[TextureBatcher getSharedTextureBatcher].getMap)[texID].vertexCount=0;
(*[TextureBatcher getSharedTextureBatcher].getMap)[texID].indexCount=0;
getMap 只是返回对我的地图的引用:
-(VertexMap *) getMap{
return &texMap;
}
VertexMap 是 std::map 的 typedef:
typedef std::map<GLuint, VertexInfo> VertexMap;
不确定为什么这在设备上失败而不是在模拟器中失败,有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们很清楚:
如果 theMap[texID] 不存在,上面的行将导致构造一个 VertexInfo 对象(使用默认构造函数 VertexInfo())。这就是你的意图吗?
也许底层 std::map 在设备上的实现方式不同,从而阻止了这种初始化?
您确定在设备目标上设置了 Call C++ Default Ctors/Dtors in Objective-C 标志,而不仅仅是 Simulator 目标吗?
一般来说,模式是在这里使用指针(C++),所以你最终会得到:
或者我误解了这个问题?
Just so we're clear:
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:
Or did I misunderstand the question?