Advertisement

member (outside of constructor) asignment of surface

Started by December 08, 2004 04:43 PM
4 comments, last by Drew_Benton 20 years, 2 months ago
ok i have the following code and it dosent like that im giving it an SDL_LoadBMP macro (its a runtime error): #include "Weapon.h" void Weapon::Read(const char* FILENAME) { ifstream fin; fin.open(FILENAME); getline(fin,Name); fin >> Attack; fin >> Defence; fin >> Speed; fin >>Image_File; I_Weapon = SDL_LoadBMP("1.bmp"); fin.close(); }; the constructor dose nothing should it? if i comment out the line were it says I_Weapon... it works thanks[smile]
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
It is crashing because you car calling Weapon::Read before SDL has been initalized. Try calling that function after you make a call to SDL_Init(). If by some chance that is not the problem, try moving the
I_Weapon = SDL_LoadBMP("1.bmp");
after the
fin.close();
Lastly check to make sure the file "1.bmp" exists and is in the same folder as all your project's .cpp, .h, and other files.
Advertisement
check,check and check. Ive had alot of weird problems with fstreams in this project [looksaround] i guess if i cant figure it out then ill just hae to find a way around it thanks though[smile]
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Some other stuff I can think of is that is your 'I_Weapon' decalred as a SDL_Surface* in which you do not allocate new memory for it? Also make sure you debug your Read function, set a breakpoint on the last statement and make sure the Attack,Defence,Speed are correct. You should us getline again to get the 'Image_File' instead of 'fin >>Image_File;' Also is the code supposed to be _Weapon = SDL_LoadBMP(Image_File);? That is assuming Image_File is a string. Finally make sure your bmp is in the correct file format. It could be saved at too low a resolution (bpp) or something like that. Try saving the file in 8,16, and 24bit modes and test.
its not the color depth because all my other images work and they are the same, I donst use Image File at the moment because i wanted to make sure that the fact that i was using a string read in from file wasnt an issue (it wasnt) and third of all THANKS A TON! that was my problem! i tryed calling the weapon constructor within the player constructor and vola [grin][grin]
(it wasnt being intialized)
i descoverd this after doing a few experaments to even trying to accsess some of the class variables like if(Attack == 2) and it crashed and that was why thanks again
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
No problem! Goodluck

This topic is closed to new replies.

Advertisement