Advertisement Jump to content
Sign in to follow this  
Mr Lane

[Solved] Segmentation Fault driving me mad!

This topic is 4932 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

I try not to post bugs in forums, rather I try and use these to try and get concepts explained to me...but this is causeing me to get behind in my work. I cant work out what is wrong with the following: EDIT: for some reason -> is showing as -&
delete bb->indexArray;
bb->indexArray = NULL;
bb->indexArray = new int(NUM_INDICIES_CUBE);  // There are 24

int indicies[NUM_INDICIES_CUBE]= {0,1,2,3,0,2,1,3,4,5,6,7,4,6,5,7,0,4,1,5,2,6,3,7};

for(int i = 0; i < NUM_INDICIES_CUBE; i++)
    bb->indexArray = indicies;           //I believe seg fault is here
                                               //Does not happen if that line
                                               //Is commented out

And this attempt is no better:
	delete bb->indexArray;          //Clear existing mem
	bb->indexArray = NULL;          //Set pointer to NULL
	bb->indexArray = new int(NUM_INDICIES_CUBE);   //Assign new mem
	bb->indexArray[0] = 0;
 	bb->indexArray[1] = 1;
	bb->indexArray[2] = 2;
	bb->indexArray[3] = 3;
	bb->indexArray[4] = 0;
	bb->indexArray[5] = 2;
	bb->indexArray[6] = 1;
	bb->indexArray[7] = 3;
	bb->indexArray[8] = 4; 
	bb->indexArray[9] = 5; 
	bb->indexArray[10] = 6; 
	bb->indexArray[11] = 7; 
	bb->indexArray[12] = 4; 
	bb->indexArray[13] = 6;
	bb->indexArray[14] = 5;
	bb->indexArray[15] = 7;
	bb->indexArray[16] = 0;
	bb->indexArray[17] = 4;
	bb->indexArray[18] = 1;
	bb->indexArray[19] = 5;
	bb->indexArray[20] = 2;
	bb->indexArray[21] = 6;
	bb->indexArray[22] = 3;
	bb->indexArray[23] = 7;

Can anyone see what I am doing wrong here? Is there a better way to do this? Thanks in advance. [Edited by - Mr Lane on July 21, 2005 11:48:35 AM]

Share this post

Link to post
Share on other sites
I think here:

bb->indexArray = new int(NUM_INDICIES_CUBE); // There are 24

You want to be using [] instead of ()

bb->indexArray = new int[NUM_INDICIES_CUBE]; // There are 24

Or just switch to a std::vector.

Share this post

Link to post
Share on other sites
Well there you go. Fixed. Thanks.

Out of intrest, why did int() compile? Does it have some valid meaning?

Share this post

Link to post
Share on other sites
Yes, it means to create a single new int with a value equal to the argument, in this case 24. Similarly you can do new float(3.1415926535) to get a float on the heap with a value equal to 3.1415926535.

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!