Jump to content
  • Advertisement
Sign in to follow this  
jake_Ghost

problem while using vector.push_back [FIXED]

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

well i have made a class for heightmaps which i will use for terrain. I have all of different heightmap files in a vector. heres my struct
struct TERRAIN
{
	BYTE HeightMap[1024*1024];
	int MAP_SIZE;
	int ID;
};


the thing is, when i push a vector with the hieghtmap data, the array is way to big for the vector (i think), so it causes an error. If i reduce the size of the byte array then it will work properly. Is there a way to fix this? thx jake [Edited by - jake_Ghost on March 28, 2005 6:36:43 PM]

Share this post


Link to post
Share on other sites
Advertisement
What happens when you try to push that structure? Do you get an error message or something?

Share this post


Link to post
Share on other sites
You could replace the BYTE array itself with a vector<BYTE>. A 1M struct is huge; it won't fit on the stack.

Share this post


Link to post
Share on other sites
You realize that structure is over 1MB big? Hopefully you don't want to push to many of them.

Anyway, it helps to mention what the error is when you say you get an error.

Share this post


Link to post
Share on other sites
its one of those window errors that says send error report or dont send. i am using the code from gametutorials.com for raw loading.

Share this post


Link to post
Share on other sites
I think the problem is probably that, even though vector uses the heap, when you do push_back you pass it a TERRAIN object that was created on the stack. And like Fruny said, that structure won't fit on the stack.

Share this post


Link to post
Share on other sites
Quote:
Original post by jake_Ghost
its one of those window errors that says send error report or dont send. i am using the code from gametutorials.com for raw loading.


It's a stack overflow. The default stack size is generally only 1MB. A single variable of that type is already bigger than that. Use dynamic allocation (e.g. a vector<BYTE>) instead of an array.

Share this post


Link to post
Share on other sites
ok well i cant use vector unfortunatly cause it screws up some other code i have so how do i do it normally using pointers and new statment.

can i do it like this??


BYTE *HeightMap;

//and when i push the vector resize the heightmap array
HeightMap = new BYTE[1024*1024];



Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!