开发者

dynamic cast throws pointer is not std::__non_rtti_object

开发者 https://www.devze.com 2023-02-23 07:19 出处:网络
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

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();
}

nothing in code changed and when I check in debugger every variable开发者_如何学Go 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!


Does CCNode have any virtual functions? Are all elements of temp->getChildren()->begin() really CCNodes? Does temp->getChildren() return a reference? The latter is especially insidious: you call both temp->getChildren()->begin() and temp->getChildren()->end(). If getChildren() returns a copy, you're taking the begin of one copy and the end of another copy.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号