动态转换抛出指针不是 std::__non_rtti_object [英] dynamic cast throws pointer is not std::__non_rtti_object

查看:29
本文介绍了动态转换抛出指针不是 std::__non_rtti_object的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了 dynamic_cast 的问题.我刚刚编译了我的项目并在调试模式下测试了所有东西,然后我尝试在发布模式下编译它,我已经从调试模式 exept 优化参数复制了每个配置,现在是/o2,(在调试时我将它设置为/od)项目已编译,但当它开始加载我的资源时,我在此处的代码段中遇到异常:

I'm having problem with dynamic_cast. i just compiled my project and tested every thing in debug mode and then i tried compiling it in release mode, i have copied every configuration from debug mode exept optimization parameter which is now /o2, (while debuging i set it as /od) the project compiled but when it starts loading my resources i got exception in the piece of code here :

for(int j = 1; j < i->second->getParametersNumber();j++)
{
    CCTMXTiledMap* temp = CCTMXTiledMap::tiledMapWithTMXFile(i->second->As<string>(j).c_str());
    CCTMXLayer* ret = NULL;
    for(NSMutableArray<CCNode*>::NSMutableArrayIterator l=temp->getChildren()->begin();!ret && l!=temp->getChildren()->end();l++)
        ret = dynamic_cast<CCTMXLayer*> (*l);
    t1.first = ret;
    templates[i->first].second.push_back(t1);
    templates[i->first].second.back().first->retain();
}

代码中没有任何改变,当我检查调试器时,类中的每个变量都是它应该是的,但动态转换抛出 std::__non_rtti_object.我做错了什么?而且我正在使用 cocos2d-x ,我没有足够的声誉来添加该标签!

nothing in code changed and when I check in debugger every variable in classes is what it should be but dynamic cast is throwing std::__non_rtti_object. what am i doing it wrong? and i'm using cocos2d-x ,I didn't have enough reputation to add that tag!

推荐答案

在这种情况下,经过多次代码更改后,我发现代码优化时必须有一些错误(仍然不知道是不是编译器的错误优化或我的代码有一些问题,但它可能是我的).这个问题的主要原因是 *l 为 NULL.

In this case after many code changes I found out there has to be some bugs which show themselves when code is optimized (still don't know if it's compiler's mis optimization or my code has some problems but it's probably mine). and the main reason for that problem was with *l being NULL.

这篇关于动态转换抛出指针不是 std::__non_rtti_object的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆