unfortunately I have been trying to recreate the problem to no avail |
That usually means the problem is unrelated to what you think it's related to. It might take some old-fashioned debugging (stepping through the code and watching vars to make sure they're updated as you expect).
heres a link to my project, im dying for complex feedback, |
That code does not compile for me due to your misunderstanding/misuse of globals. I had to copy/paste the contents of load_files.cpp and stringtoint.cpp into main.cpp to get it to build.
Running the program also causes it to immediately crash (also because of the misuse of globals -- looks like static initialization order fiasco)
I'm surprised this is building for you -- and even more surprised that it is actually running. =x
I'm going to outline some things about SFML (and C++ in general) that you should know. If this is too much to follow... it's basically summarized with
"Globals are bad and you shouldn't use them"
1) Global variables are constructed before "main" starts. In one "compilation unit" (basically, a single cpp file), globals are constructed in the order they are declared. That is:
1 2
|
string a; // a will be constructed before b because it is declared first
string b = a; // <- safe because a has already been constructed
|
If you have multiple compilation units... the order of construction is not guaranteed and this can lead to nasty problems. Example:
1 2 3 4 5 6
|
// in a.cpp
string a;
// in b.cpp
string b = a; //<- NOT SAFE, see below
|
Here, there is no way to know whether a or b is constructed first. And since the construction of b depends on a already being constructed... you are HOSED.
2) SFML may or may not have its own globals. I don't think it does anymore... but I still would not attempt to construct any SFML object globally, as its construction may depend on some SFML initialization that doesn't happen until main starts. This isn't really specific to SFML... it's just a general rule of thumb when using any library.
3) SFML creates the OpenGL context with the first created window, and destroys it when there are no more windows.
4) Things like sf::Texture require a GL context to construct/destruct. This combined with #3 mean you are blowing yourself up with this code. You have a globally created sf::Texture ('contact'). Being globally created means it is constructed before your window, and destructed AFTER your window.
This is the opposite of what you need. The window must be created FIRST and destroyed LAST so that there is always a valid GL context for the sf::Texture to use.
5) Defining a variable in multiple cpp files causes a linker error. If you make two separate variables named "foo" in two separate cpp files... the linker will get confused because it now has 2 vars with the same name at the same scope, and it doesn't know which of the 2 you want to use.
6) #include <someheader> is effectively a copy/paste operation. The compiler basically copy/pastes the header code into the cpp file when you do an #include. This, combined with #5, means that global variables defined in headers... which are #included in multiple files.... means each of those files are defining their own variable... which causes linker errors.