2

project environ:
windows 7 x64 pro
visual studio 2008 c++ sp1 pro
win32 api
directx 9.0c june 2010
boost

question :
my project is run successful on DEBUG mode. but only Release mode error occurs.

template <typename T>
class SceneVector : public std::vector<T>
{
public:
    SceneVector()
    {
        for(int i = 0 ; i < MAX_OBJNODE_NUMBER ; ++i) push_back(NULL);
    }
}; 



//i think the class's contents are not important
class ITaggingDebugInfo
{
protected:
    int idvl;
public:
    ITaggingDebugInfo();
    ~ITaggingDebugInfo();
    int iTaggindDebugInfoID;
    virtual std::vector<AbstractTag*> OnMakeTagList(int VlogicPackageID);
    static void Select(int vlid, int id);
    static stdext::hash_map<int,SceneVector<ITaggingDebugInfo*>> TaggingDebugInfoManager; //problem
    static std::vector<AbstractTag*> taglist[MAX_SCENE_NUMBER];             
};

//on other's cpp file
stdext::hash_map<int,SceneVector<ITaggingDebugInfo*>> ITaggingDebugInfo::TaggingDebugInfoManager;

the release mode problem is occuring when static hash_map's constructor.
here's my STL debugging step. step 1

hash_map()
: _Mybase(key_compare(), allocator_type())
    {   // construct empty map from defaults
    }

step 2

    explicit _Hash(const key_compare& _Parg,
    const allocator_type& _Al)
    : _Traits(_Parg), _List(_Al),
        _Vec(_Al),
        _Max_bucket_size(_Bucket_size)
    {   // construct empty hash table
    _Init();
    }

step 3

void _Init(size_type _Buckets = min_buckets)
    {   // initialize hash table with _Buckets buckets, leave list alone
    _Vec.assign(_Buckets + 1, end());
    _Mask = _Buckets - 1;
    _Maxidx = _Buckets;
    }

when step 3, this pointer is NULL(0x00000000) (by debugger's watcher. but it is not confidently because release mode) and access violation exception.

but on DEBUG mode the error dosen't occur.
i really don't know why this problem happen. somebody help me!

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
user1101221
  • 394
  • 6
  • 21
  • Turn the warning level up. The default is too low. In older version of DevStudio I always turned this too max. On newer version aparently they have a new higher max that is just way to high (but I have not seen it). Also check the box that says "Treat Warnings as Errors". Now try and rebuild. – Martin York Aug 12 '12 at 07:04
  • 2
    To help with this kind of problem you need to reduce the code to the smallest compilable example the exhibits the problem before posting. Usually this processes will lead you to finding the problem if not then you get a 1,000,000 pairs of eyes that can look at real code. – Martin York Aug 12 '12 at 07:09
  • P.S. Identifiers beginning with an underscore are usually reserved for the implementation. Thus `_Vec` makes your code non-conforming and thus technically not valid. See http://stackoverflow.com/a/228797/14065 – Martin York Aug 12 '12 at 07:11
  • The reserved identifiers are used in `namespace stdext`, which sounds like it might in fact be from the implementation. – aschepler Aug 12 '12 at 07:17

1 Answers1

3

You're not supposed to derive from an STL container like vector because they don't provide a virtual destructor. I suspect the behaviour you're experiencing may because of this. Read all the pros and cons about doing that here: Thou shalt not inherit from std::vector

Community
  • 1
  • 1
acraig5075
  • 10,588
  • 3
  • 31
  • 50
  • thanks i can't understand all of the document's meaning but i know one thing : **don't inherit from STL container** – user1101221 Aug 12 '12 at 07:10