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

Author Topic: Visual Studio - Debug Mode fails to open file, Release mode works  (Read 6639 times)

0 Members and 1 Guest are viewing this topic.

moticon

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
I'm new to SFML, but have decent programming background.

I'm using Visual Studio 2019 and have run into a very strange bug.  I've narrowed the code down to the following:
#include <SFML/Graphics.hpp>

int main() {
        sf::Texture ship;
        ship.loadFromFile("ship.png");
        return 0;    
}
The code builds with no problem.  When I build it in debug mode it fails. When I build it in "release" mode it works and opens the file to load the Texture object.

The output that I see on the console is a message from the loadFromFile() method.  It says "Failed to load image "....".  The contents in the quotes will include the "ship.png" preceded by four characters and succeeded by a randomly sized list of characters.  It looks to me like the string address received/used by the loadFromFile() method is not correct. I'm wondering if it's a problem with the stack or something related to the fact that the parameter is passed by reference and the reference address is reduced by four bytes (thus the consistently preceding four meaningless chars before the actual file name).

Here's the output from a run in debug mode:
Failed to load image "╚> ♥ship.pngßÑ│2►☼2►çL°╛α≈╛.ßÑ│2►ç┤°╛►▐2►ç┤°╛►▐Ç-~x┬Fe╦■   ♀°╛♀°╛e√qx↑°╛│εqx≡╘☺║↕4°╛4°╛<¶rx4°╛│εqx≡╘☺║↕P°╛P°╛<¶rx2►ç0┴εÇ.<u╠

This goes on for several pages with looks like a non-terminated string that is read past the end of the string into local memory after the string.

Here's the output when I build the project using a release build instead of debug build.

C:\Users\pat.smith\source\repos\careful test sfml\Release\careful test sfml.exe (process 33828) exited with code 0.


Any ideas on where to look next?

TIA!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Visual Studio - Debug Mode fails to open file, Release mode works
« Reply #1 on: November 19, 2021, 04:11:27 pm »
Someone else just posted abotu the same issue. ;)

The solution is to link debug libs (with -d suffix) in debug mode and release libs (without -d suffix) in release mode.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

moticon

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Visual Studio - Debug Mode fails to open file, Release mode works
« Reply #2 on: November 19, 2021, 04:17:39 pm »
Thanks! I saw the reference in the tutorial to the -d libs, but since it was building I thought I was OK. I should have tried that as well.

In any case I am grateful!

That fixed it.