Archived

This topic is now archived and is closed to further replies.

STL Vector heap accessing error

This topic is 5551 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hey, Just started recently getting familiar with STL, and it seemed pretty easy, and the uses quickly became obvious. So, for my first try at implementing vectors, I wanted a dynamic list of textures that I could add to for my editor. vector TextureList; (in the after the file is opened...) TextureList.push_back(CTexture()); Anyway, i get a heap access error, which is actually a failing assert in micro$softs dbgheap.c file. I''m wondering if there is a specific way that I need to tell my program that I want to specifically access the ''local'' heap, so as not to try to access any bogus memory. Thanx "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 Share this post Link to post Share on other sites Advertisement if i had a company that was really successful, i''d love it if people spelled the name with a dollar sign rather than an s. are you chipping away at something? Share this post Link to post Share on other sites Last time I saw that error, the guilty party had trashed the vector housekeeping data by writing to v[-1]. Check that you''re not doing that. [ Start Here ! | How To Ask Questions The Smart Way | Recommended C++ Books | Free C++ IDE. ] [ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Boost C++ Lib ] Share this post Link to post Share on other sites Ok, I try to ask a legitamate, mature question. I use a common, sarcastic mispelling of a generally (not unanimously) disliked company, and you waste my, and everyone elses who will read this thread's time by commenting on such subtleties.... I'm sorry. [EDIT:] Sorry fruny, you replied while I was replying to petewood. Thanks for the useful reply . Unfortunately thats not the problem though. I'm not trying to access any part of the vector, rather, i'm just trying to push_back one element. "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 [edited by - TheBlackJester on December 7, 2002 3:28:38 PM] Share this post Link to post Share on other sites i'm also helping keep your thread at the top of the list. edit: i think something that moved me to comment was the fact that you refered to microsoft in such a way as to imply that their desire for money was related to a crash in the dbgheap.c file. maybe you weren't but i reacted. anyway, it's quite unlikely that your crash has anything to do with a problem in the library implementation. show us more code please. also putting a & followed by lt; for a less than sign and & followed by gt; for greater than will sort out your formatting sorry to waste your time. lets try to get your problem sorted out. pete [edited by - petewood on December 7, 2002 4:08:23 PM] Share this post Link to post Share on other sites Another possibility would be that your CTexture object holds a pointer, deleted in the destructor, and you didn't define a copy constructor. Thus, when the temporary object created by CTexture() gets destroyed, so does the data. Or something... Though it shouldn't cause a problem here... Hmm... I'm afraid you're going to have to examine your call stack and the history of the operations done on that vector. BTW - petewood, according to Ars Technica, it's 'Microshizzle' [ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | Free C++ IDE. ] [ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Boost C++ Lib ] [edited by - Fruny on December 7, 2002 4:16:54 PM] Share this post Link to post Share on other sites quote: Original post by TheBlackJester I try to ask a legitamate, mature question. yes, and you ruin it by quote: a common, sarcastic mispelling of a generally (not unanimously) disliked company don''t like ms software? don''t use it. you may not realize it, but spelling ms with$ puts you in the camp of the brainless ms bashers that blame all their bugs on ms and think they are cool because of that.

i don''t want to help people who dislike environment they are working in with environment-related because i think they just paste code related to said environment without thinking much about it.

ms debug heap provides more information than "a failing assert", which is all you gave us. if you weren''t as ignorant as you are, you could''ve fixed or at least localized the problem yourself by using the tools of your environment, such as the call stack, by looking at the source code in dbgheap.c that breaks, as well as reading the comments and error message produced by the c runtime.

Share on other sites
Petewood: Apology accepted, thank you. I'll try out the suggestion you gave, thanks a bunch. I didn't mean to sound like I was blaming microsoft for my issue, and I'm sure there is no problem with the dbgheap.c file. I simply wanted to let you guys know where the assert was failing, because I thought it might give a little insight into the problem. I apologize for that.

Fruny: I believe the problem lies where you mentioned, in my CTexture file. You mention that I may need a copy constructor, and I'm sure that that could likely be the problem, but considering how i'm not completely familiar with the term or how to implement it, I'll do some research

Niyaw: ... Hmm. Normally, I would respond to your post with an apology, just like with Petewood, but your tone struck me as degrading, conceded, and pretty much unnessassary. So...

quote:

don't like ms software? don't use it.

As you may have noticed, I wrote, "a generally disliked company ". Not software. I enjoy microsoft software very much, and as I pointed out to petewood, I was not trying to blame them for my problem, but give insight into what might be causing it.

quote:

Share on other sites
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.

Share on other sites
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.

Share on other sites
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