Jump to content
  • Advertisement
Sign in to follow this  

SDL & Arrays of pointers to structures

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

Hello, I am making a chess game and am having a problam with arrays of pointers to structures. Here is the code of the init of the array of pointer and defining the values.
 	/* this is an array of pointers to all the pieces in the game */
  	struct piece *All[32];
  	All[1] = &Bfort1;
  	All[2] = &Bhorse1;
  	All[3] = &Bprince1;
  	All[4] = &Bqueen;
  	All[5] = &Bking;
  	All[6] = &Bprince2;
  	All[7] = &Bhorse2;
  	All[8] = &Bfort2;
  	All[9] = &Bsoldier1;
  	All[10] = &Bsoldier2;
  	All[11] = &Bsoldier3;
  	All[12] = &Bsoldier4;
  	All[13] = &Bsoldier5;
  	All[14] = &Bsoldier6;
  	All[15] = &Bsoldier7;
  	All[16] = &Bsoldier8;
  	All[17] = &Wfort1;
  	All[18] = &Whorse1;
  	All[19] = &Wprince1;
  	All[20] = &Wqueen;
  	All[21] = &Wking;
  	All[22] = &Wprince2;
  	All[23] = &Whorse2;
  	All[24] = &Wfort2;
  	All[25] = &Wsoldier1;
  	All[26] = &Wsoldier2;
  	All[27] = &Wsoldier3;
  	All[28] = &Wsoldier4;
  	All[29] = &Wsoldier5;
  	All[30] = &Wsoldier6;
  	All[31] = &Wsoldier7;
  	All[32] = &Wsoldier8; 

And i have a function which is activated when SDL detects a click on a picture, it takes the array of pointers as a paramater and in it theres a refrence to it which compiles fine but when i click on the image i get the "Fatal signal: Segmentation Fault (SDL Parachute Deployed)" error:
for(i = 0; i <= 32; i++) if((All->position_column == Xoperator) && (All->position_line == Yoperator)) ToD = 1;
if((Xoperator >= first.x) && (Xoperator <= last.x) && (Yoperator >= first.y) && (Yoperator < (last.y - 1))) 
				Display_image(blue_squre, scrn, Xoperator, Yoperator); 

now the problematic line here is the first, ive checked and if instead of using i in using the array, and using a number, SDL dosent produce an error. what is SDL's problam ?

Share this post

Link to post
Share on other sites
You are accessing element 32 of the array, which is invalid. An array with 32 entries means you can access entries 0-31 only. This is a rule of C/C++.

Share this post

Link to post
Share on other sites
okay, i though i took care of that problam by using the '<=' but that was what created the problam.
thanks, up with your ratings.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!