STL Vector heap accessing error

Started by
12 comments, last by TheBlackJester 21 years, 4 months ago
default ctor in your texture class doesn''t initialize the member pointer, and when dtor tries to delete it, debug heap shouts at you. copy ctor will also wreak havoc, as already stated.

if you use boost::shared_ptr instead of raw pointers, you wouldn''t need to implement any of copy ctor, assignment operator, or dtor. save yourself the trouble.

link

now regarding $: i never said you were an ms basher, but you''re subscribing to the typical ms basher image by spelling ms with $. yes, it probably is prejudice. but why invent problems for yourself by playing with fire when you can easily avoid them and get all the quality replies you deserve?
Advertisement
quote:Original post by TheBlackJester
If I used pointers for my texture objects, would that still require manuel deletion, even though vectors take care of that for you?

using vector<type *> will require you to call delete on every vector element to avoid memory leaks.

boost::shared_ptr will take care of this for you.
in your constructor you need to initialise data to some reasonable default (possibly zero)

then the destructor won''t be called on an uninitialised pointer to imageData_ but a zero pointer. that''ll be fine and won''t try and delete some random memory location.
Yeah, I initialized my m_imageData pointer to NULL, and it worked fine. Except, when I wasn''t passing the CTexture classes in to the vector as a pointer, I could only load up to the fourth texture, and it would crash with the previous error, so I just changed to pointers and its working fine.

Thank you for the replies


"With my feet upon the ground I lose myself between the sounds and open wide to suck it in, I feel it move across my skin. I''m reaching up and reaching out. I''m reaching for the random or what ever will bewilder me, what ever will bewilder me. And following our will and wind we may just go where no one''s been. We''ll ride the spiral to the end and may just go where no one''s been." - Maynard James Keenan Name: TheBlackJester
Team: Wildfire Studios

Projects
O A.D.
The Last Alliance

"With my feet upon the ground I lose myself between the sounds and open wide to suck it in, I feel it move across my skin. I'm reaching up and reaching out. I'm reaching for the random or what ever will bewilder me, what ever will bewilder me. And following our will and wind we may just go where no one's been. We'll ride the spiral to the end and may just go where no one's been." - Maynard James Keenan Name: [email=darkswordtbj@hotmail.com]TheBlackJester[/email]Team: Wildfire Games
Projects O A.D.The Last Alliance

This topic is closed to new replies.

Advertisement