STL vector exception handling problems

Started by
3 comments, last by Qw3r7yU10p! 19 years, 1 month ago
Ok so heres is how my STL vector is setup: ////////// std::vector<CShader *> vShaders; vShaders.push_back (new CShader()); ////////// at the push_back line the program gets an unhandled exception: Unhandled exception at 0x00420846 in projekt.exe: 0xC0000005: Access violation reading location 0x00000004. and it stops in the file vector on line 516 inside the function: ////////// size_type size() const { // return length of sequence return (_Myfirst == 0 ? 0 : _Mylast - _Myfirst); } ////////// My CShader looks like this: ////////// class CShader { public: CShader(void); ~CShader(void); void load(char * fileName); char* getName(void); char* getVertexShader(void); char* getFragmentShader(void); protected: char name[128]; char* fragmentShader; char* vertexShader; }; ////////// Can someone please help me ive been trying to fix this for about 2 hours now and its not budging. Thanks in advance.
Advertisement
May I ask why are you making a vector of pointers?

  1. You can put code in the [ source ] tag (without the spaces), which will make your posted code easier to read.

  2. Your code is trying to read from address 0x00000004. I don't see why that would happen in an std::vector, perhaps the this pointer in the function is null (somehow).

Have you overloaded operator new?
Does the constructor for CShader do aything wih vectors?
Is the code you posted exactly as it is written in your application?

If the answer to all of those is no, then I've got no idea why yur code isn't working.
If it's a member function then the object it's acting on isn't valid.

Show us real code.

This topic is closed to new replies.

Advertisement