• ### Popular Now

• 12
• 12
• 9
• 10
• 13

#### Archived

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

# weird problem, or just bad coding?

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

## Recommended Posts

Hi all, i have a 800*600 window, and a .bmp that holds allot of tiles, and a funktion to clip out my tile i want to use and paint it depending on the "map file" btw i use SDL. but when i try to paint it, i do like this
for(int y = 0; y < 25; y++) // 25 is the number of "rows" with tiles in my file

{
for(int x = 0; x < 9; x++)
{
Tile.draw(x, y, xpositionOnScreen, ypositionOnScreen);
}
x = 0; // so that it goes back to the beginning in the .bmp file again

}

now, i just get a Segmention Fault parachute deployed, how ever if i comment out Tile.draw it works, and Tile.draw works for "itself" ive tested it without looping it to paint whole screen

##### Share on other sites
You declare "int x" for the loop, then set x's value outside of the loop (some compilers don't seem to mind this). If optimization is on, the compiler will probably throw out the whole thing when you comment out the "Tile...".

my compiler says:

name lookup of x' changed for new ISO for' scoping
using obsolete binding at `x'

lonesock

Piranha are people too.

[edited by - lonesock on February 26, 2004 5:57:21 PM]

##### Share on other sites
uch, wrong of me to add that, im a little tiered, since that loop will rerun efterytime Y++, so i shouldnt need to reset x to 0 right?

##### Share on other sites
correct.

lonesock

Piranha are people too.

##### Share on other sites
but my problem still lives i have coded it that way (without the x = 0; ) but still get Segmention Fault

##### Share on other sites
Your problem lies in the Tile.draw function,

the function itself may work right, but your use of it may be wrong,

perhaps by passing 'inappropriate' values to it,

from the values you are passing to it, are you maybe drawing images outside the destination image's boundries, i belive that could cause a segmentation fault, if so you will need to implement some kind of image clipping so that it wont try to draw out of bounds.

Raymond Jacobs,

www.EDIGames.com

www.EtherealDarkness.com

[edited by - EDI on February 27, 2004 9:56:03 AM]

##### Share on other sites
Paste the Tile::Draw-method here, so we can have a look at it.
I guess the segmentation-fault you''re getting is really an Access Violation-exception, which would mean you''re reading or writing from/to a page where you don''t have permissions.

--
MFC is sorta like the swedish police... It''''s full of crap, and nothing can communicate with anything else.

##### Share on other sites

According to the new ANSI standard, the looping
variable of the for-loop is only defined in the for-loop
itself. In that case you should not be allowed to set
x to zero after the loop, as there is no such thing as
a variable ''x'' after the loop.

Alas, I don''t think that''s the solution to your problem.
Just a side-remark.

Cheers
O.