kroyee / SpeedBlocks

Fast paced tetris game cloned from Cultris II
GNU Lesser General Public License v3.0
11 stars 7 forks source link

Fix deprecation errors for visual studio #21

Closed zDEFz closed 7 years ago

zDEFz commented 7 years ago

simple but effective #pragma warning(disable: 4996)

texus commented 7 years ago

As far as I know this only fixes the issue for Visual Studio and not for other compilers. Defining SFML_NO_DEPRECATED_WARNINGS when compiling is probably going to be a better solution if the only deprecated warnings are coming from SFML.

zDEFz commented 7 years ago

@texus defining SFML_NO_DEPRECATED_WARNINGS doesn't fix the TGUI deprecation warnings. If its only a fix for visual studio its okay since it doesn't break other things. Also using _CRT_SECURE_NO_WARNINGS doesn't help in that case.

texus commented 7 years ago

Which TGUI deprecation warnings?

zDEFz commented 7 years ago

No TGUI warnings, was inaccurate. Sorry

Schweregrad Code Beschreibung Projekt Datei Zeile Unterdrückungszustand Fehler C4996 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. Projekt2 d:\dev\speedblocks-master (3)\speedblocks-master\gui.cpp 1311

zDEFz commented 7 years ago

After restart of vs2015 the ignoring with _CRT_SECURE_NO_WARNINGS SFML_NO_DEPRECATED_WARNINGS

does the trick... however what is bad in having this line in gameplay.h additonally?

texus commented 7 years ago

Visual Studio likes to promote its own non-standard functions. That warning is about such a function where VS wants you to use their non-cross-platform function instead of sprintf.

The real solution is however to not use sprintf at all. @kroyee should change the implementation of the SFKeyToString function to something like this:

char* SFKeyToString(unsigned int keycode) {
    switch (keycode) {
    case sf::Keyboard::Key::Escape: return "Escape";
    case sf::Keyboard::Key::LControl: return "LControl";
    // ...

That way there won't be a sprintf and thus VS won't complain and thus you won't have to define _CRT_SECURE_NO_WARNINGS

zDEFz commented 7 years ago

Well that is for sprintf. Then we only would need

SFML_NO_DEPRECATED_WARNINGS

texus commented 7 years ago

Yeah, but you will always need that unless the code would be updated to use SFML 2.4 functions. But obviously such a code change means that it will no longer work with SFML 2.3 which means that ubuntu users won't be able to download SFML from the repository and instead have to manually compile it. And when newer SFML versions come out you would have the same issue again: update the code or get warnings.

Having the pragma warning in gameplay.h is not bad IF the issue isn't fixed for all compilers. But I think adding #define SFML_NO_DEPRECATED_WARNINGS instead of #pragma warning will also do the trick and if that is the case then it will be a better solution as it is cross-platform.

zDEFz commented 7 years ago

define SFML_NO_DEPRECATED_WARNINGS

results:

Schweregrad Code Beschreibung Projekt Datei Zeile Unterdrückungszustand Fehler C4996 'sf::Text::setColor': wurde als veraltet deklariert Projekt2 d:\dev\speedblocks-master (3)\speedblocks-master\gameplay.h 59

It's not doing the trick for me.

texus commented 7 years ago

It indeed seems to be a bit more complicated. I knew that it would have to be defined in front of every SFML include but I thought that because you only needed pragma warning on one place you could get away with the define in only one place as well. But I realize now that it doesn't work due to the order files are included. The pragma warning just has to occur before the code that gives the warning while the define needs to occur before the first SFML include. So the lines aren't interchangeable.

Edit: having it in the global defines like you did earlier is thus still a better solution than having to define it in most headers.

kroyee commented 7 years ago

I went ahead and upgraded to sfml-2.4.2. Then added -Wall -Wextra to my compiling options. So now I'm also getting all the no return warnings and deprecation warning. Added #define SFML_NO_DEPRECATED_WARNINGS to all .h files as suggested and can now compile without warning.

Only remaining is 2 warning for unused variables in unimplemented functions, I left them there since they will be used eventually.