Alright, this is my first time posting on the forums, so I apologize if I do something unorderly or incorrectly. I've been having an issue with using LoadFromFile with an Image, while it's in a class, and not in main.
For example, in main()
sf::Image Image;
Image.LoadFromFile("Bunny.png");
sf::Sprite Sprite;
Sprite.SetImage(Image);
This works perfectly, and how it should. I can further on use "Sprite" to draw the "Bunny.png" and everything else. With the Draw(Sprite); function, and such.
However, in a larger game I'm working on, I've made an image manager class (so I can handle, load, and set images in just one little file, instead of in every class, monster, level, etc). In my larger game, it works perfectly, but in this tiny application I'm attempting to make, anytime I call "LoadFromFile" while it's not in main, it will crash.
In my ImageManager class, I have the following:
char FilePath[256];
for(int i = 0; i < 5; i++)
{
switch(i)
{
case 0:
strcpy(FilePath, "./Data/Images/TitleBackground.png");
break;
default: ;
}
Image[i].LoadFromFile(FilePath);
}
For whatever reason, it crashes when it gets to "LoadFromFile()." Which has me dumbfounded, because I have used the exact same code -- with the exception of the specific files I'm loading, of course -- and it still produces the crash. I have tried switching the images, moving the images into other locations. Making the image be direction in the same folder, not in a "Data/Images/" directory, I've double checked to make sure I've linked everything properly with the -lsfml-system, graphics, audio, etc; nothing is making any sense. Aside from the project's files, settings-wise, it is identical to my other project that works; however, I can't for the life of me, figure out why this one refuses to work, and produces a crash.
If I am calling LoadFromFile while in main.cpp, it works as it should, but in any other file, such as ImageManager.cpp, it does not. I am using Code::Blocks. Everything (that I know of) is linked properly, and my code should be working correctly, considering I copy and pasted it verbatim from my other project. Compiling gives no errors nor no warnings; however, I know good and well that doesn't mean it will be flawless code, but the crash doesn't make any sense from me. The console window does not say anything, so I can assume it's working fine; it just crashes whenever LoadFromFile is called outside of main.cpp.
I have went as far as to simply copy
Image.LoadFromFile("Bunny.png");
Sprite.SetImage(Image);
into the ImageManager's loading function (just to test if it was a code error), but it crashes as well. While having "sf::Image Image;" and "sf::Sprite Sprite;" defined in the ImageManager.h class, of course, under private. It still crashes with no info or insight into what's causing this crash.
This started out as a tiny little project to make something for a friend over night, and it's turned into a five-hour headache for me.