Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Visual studio project broken in release mode  (Read 4214 times)

0 Members and 1 Guest are viewing this topic.

Teleman

  • Newbie
  • *
  • Posts: 2
    • View Profile
Visual studio project broken in release mode
« on: August 18, 2021, 11:46:42 pm »
hello all, I have been using sfml for a while and I must say I really like the workflow. I now have a game that I'm ready to release but I have encountered a weird problem in visual studio when I switch to release mode the sprites for the npc characters render but they don't move and the player cant interact with them, the whole game runs completely fine in debug with no problems or errors and I made sure to have it use the release sfml DLL files when running in release and the debug files when running in debug but I still can't figure out why the npc characters don't do anything in release but work fine in debug. is this a common problem with the visual studio compiler, is there something I did wrong. thanks in advance  :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Visual studio project broken in release mode
« Reply #1 on: August 19, 2021, 08:48:24 am »
A common problem when you have issues between debug and release is because of uninitialized variables. In debug mode they tend to get initialized with zeros in memory, but in release you can end up with any random value.
Make sure you initialize all your variables where you don't have proper default initialization.

Otherwise it's really hard to say without code.
I would suggest to build in release with debug symbols, then start up the project in a debugger and step through it. That way you should see where values are not or wrongly changed.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Teleman

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Visual studio project broken in release mode
« Reply #2 on: August 19, 2021, 02:23:43 pm »
thank you, I read a book on sfml and they never mentioned this and it left me kind of confused. thank you for the information.

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: Visual studio project broken in release mode
« Reply #3 on: August 19, 2021, 05:22:46 pm »
It applies generally to all C++ programs, not just SFML. Visual Studio has a few differences between debug and release (I'm not as familiar with G++/Clang behavior). The biggest one, as eXpl0it3r mentioned is the uninitialised variable issue.
In debug builds, Visual Studio fills variables with special values. Stack variables are filled with 0xcc. Heap memory is filled with 0xcd. When freed, heap memory is filled with 0xdd. A guard region of 0xfd is placed around allocations to detect overflow.
(A quick test with Clang in VS shows it uses 0xcc for uninitialised variables in debug too)

If your code has (as local variables):
float f;
int i;
then in debug they will have the default values: f = -107374176.0 and i = -858993460. That's how a float and an int interpret the value 0xcccccccc (meaning 4 bytes of uninitialised stack memory).
A bool that's uninitialised will always be true (it will have 0xcc or 0xcd internally, and any non zero value is true).

But all this filling has a performance hit, so in release mode it just leaves whatever is already there, so you may have random values each time it's run. So for example an uninitialised bool that's always started as true in debug will randomly be true or false in release.

 

anything