|
Why won't this work? |
biubid_boy
Member #8,502
April 2007
|
Hello everyone. I'm using a custom structure, DEST_BITMAP, to work with destructible 2D bitmaps.
But when I called load_dest_bitmap in my main function, it crashes my program. The funny thing is, when the exact same code is used straight in my main, the program runs fine. The program crashes every time I access the bitmap data, so there is something wrong with the loading - I just can't see it. Any help would be appreciated, |
gnolam
Member #2,030
March 2002
|
Code tags are in lowercase ([code][/code]), not uppercase ([CODE][/CODE]). Edit your post accordingly. Quote: The program crashes every time I access the bitmap data, so there is something wrong with the loading - I just can't see it. You can't change the value of a function argument, unless you use a pointer. Consider this: int xsquared(int x) { x = x*x; return x; } int main(void) { int n; n = 2; //The value of n is now 2. xsquared(n); //What's the value of n here? The correct answer is "still 2". So you have to either have your load_dest_bitmap() return a DEST_BITMAP structure, or make the DEST_BITMAP argument a pointer. Oh, and check the return value of load_bitmap(), and make sure you destroy any loaded or created bitmaps. -- |
someone972
Member #7,719
August 2006
|
Make sure that the bitmaps your programs are accessing exist in the spot you tell it to look. You could also perform error checking on load_bitmap() to see if it returns NULL(indicating that it couldn't find the bitmap). As for changing the value passed to the load_dest_bitmap() function you could do as gnolam said or you could pass by reference by using the '&' operator: void load_dest_bitmap(DEST_BITMAP& dest, char image_path[], char dest_map_path[])
______________________________________ |
Kibiz0r
Member #6,203
September 2005
|
Quote: As for changing the value passed to the load_dest_bitmap() function you could do as gnolam said or you could pass by reference by using the '&' operator: No such thing exists in C. --- |
|