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

Author Topic: Exe File Different From What I Compile  (Read 1137 times)

0 Members and 1 Guest are viewing this topic.

pedro

  • Newbie
  • *
  • Posts: 2
    • View Profile
Exe File Different From What I Compile
« on: April 28, 2023, 03:11:16 am »
Hello everyone, firstly I would like to thank you because I have been building a simple game this last week and the topics here helped me a lot.
Secondly, when I compile inside the Visual Studio 2022, the code works fine and I am able to play my game. However, when I open the exe version on the Release folder, it opens but nothing happens, it only shows the background color of the window that I chose. Why is that? Is there a way to release my game in a folder where people can easily download it and just execute it. I know that the dll files must be present, which they are.

Thanks in advance

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: Exe File Different From What I Compile
« Reply #1 on: April 28, 2023, 07:39:48 am »
One of the common causes for this is the working directory.
When you run a program from explorer, the working directory is set to the same directory as where the exe is.
When you run a program from visual studio, the default is to set the working directory to where the .vcxproj file is (which is rarely the same place as the exe).

How this affects the program running is all file access that doesn't have absolute paths will be relative to the working directory.
Let's say I have a project set up (with my sfml based engine Kage) with the exe file going into f:\work\kage\bin and the vcxproj is in f:\work\kage\projects\example
Now if my code asks sfml to load a sprite like data\cat.png then it looks for the file:
Running from explorer: f:\work\kage\bin\data\cat.png
Running from VS: f:\work\kage\projects\example\data\cat.png

The easiest fix is to go into the project properties and find Debugging / Working Directory. Change the value from $(ProjectDir) to $(TargetDir).
You'll probably need to move your assets or change your paths in the code as well.

pedro

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Exe File Different From What I Compile
« Reply #2 on: April 28, 2023, 08:27:47 pm »
Oh I see, great explanation! I changed to $TargetDir and moved all my files to the same folder where the exe file was located and it worked great!

Thanks!

 

anything