std::map 初始化在 iPhone 设备上崩溃,但在模拟器中则不然

发布于 2024-08-09 13:20:07 字数 562 浏览 1 评论 0原文

我尝试打开 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷乱花海 2024-08-16 13:20:08

我们很清楚:

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

如果 theMap[texID] 不存在,上面的行将导致构造一个 VertexInfo 对象(使用默认构造函数 VertexInfo())。这就是你的意图吗?

也许底层 std::map 在设备上的实现方式不同,从而阻止了这种初始化?

您确定在设备目标上设置了 Call C++ Default Ctors/Dtors in Objective-C 标志,而不仅仅是 Simulator 目标吗?

一般来说,模式是在这里使用指针(C++),所以你最终会得到:

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

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

//  now operate on theMap[0] normally

或者我误解了这个问题?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文