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

Author Topic: Running game from exe loading issues.  (Read 1923 times)

0 Members and 4 Guests are viewing this topic.

AT24

  • Newbie
  • *
  • Posts: 4
    • View Profile
Running game from exe loading issues.
« on: August 19, 2016, 01:10:24 am »
Hello I'm trying to launch my game from the exe generated from visual studio 2015, but it freezes whenever I load a texture. I already moved my assets folder to the exe directory and it works fine when I launch it through vs2015. Any ideas on why this is happening?
« Last Edit: August 19, 2016, 01:13:18 am by AT24 »

Tigre Pablito

  • Full Member
  • ***
  • Posts: 226
    • View Profile
    • Email
Re: Running game from exe loading issues.
« Reply #1 on: August 19, 2016, 02:12:00 am »
Hello, if your code is in C#, i can see it and try to find the problem if you post it  ...  :)

if i try to guess, maybe there could be an error with the directory path that would not be the same when you launch the exe from the folder than when you run from VS2015  :(

AT24

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Running game from exe loading issues.
« Reply #2 on: August 19, 2016, 05:33:32 am »
Thanks, it's, c++ but here is the code anyways. I also thought it has something to do with the paths, it's not an immediate issue as it runs in vs.

void TextureManager::loadTextures()
{
        //every sub folder
        for (unsigned int i = 0; i < subfolders.size(); i++)
        {
                std::vector<std::string> files = misc::getFileNames(ROOT_FOLDER + subfolders[i]);
               
                //every file within folder
                for (unsigned int j = 0; j < files.size(); j++)
                {
                        //create texture object
                        if (validFileType(files[j]))
                        {
                                Texture* texture = new Texture;
                                sf::Texture raw_texture;

                                //load and set name
                                raw_texture.loadFromFile(ROOT_FOLDER + subfolders[i] + '/' + files[j]);
                                texture->texture = raw_texture;
                                texture->name = files[j];

                                textureList.push_back(texture);
                        }
                }
        }
}

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Running game from exe loading issues.
« Reply #3 on: August 19, 2016, 10:03:13 am »
This has most likely to do with the working directory. If you double click an executable in Explorer, the working directory is the same location as the folder the executable is inside.

If you launch an executable from its project in visual studio, the working directory is usually the folder that includes the project file.

In Visual Studio's project settings find "Debugging" and set the working directory to be the final location of the executable file. Then just debug as usual and you should be able to step through your code, trying to figure out what's wrong.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Running game from exe loading issues.
« Reply #4 on: August 19, 2016, 02:32:21 pm »
Just two points:
  • You're loading a texture into a temporary texture and then assigning it to another one held by a pointer. You could load it directly into the one pointed to by the pointer and remove the temporary.
  • You aren't checking the return value of loadFromFile. This returns true if the file loaded successfully. If it fails - and therefore returns false - you shouldn't be using it.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

AT24

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Running game from exe loading issues.
« Reply #5 on: August 21, 2016, 06:30:57 am »
Thanks, the temp texture due to me changing my loading methods.

Texture* texture = new Texture;

                                //load and set name
                                if (texture->texture.loadFromFile(ROOT_FOLDER + subfolders[i] + '/' + files[j]))
                                {
                                        texture->name = files[j];
                                        textureList.push_back(texture);
                                }
                                else
                                {
                                        std::cout << "Failed to load " << ROOT_FOLDER + subfolders[i] + '/' + files[j] << '\n';
                                        delete texture;
                                }

AT24

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Running game from exe loading issues.
« Reply #6 on: August 21, 2016, 07:36:04 am »
I fixed it, I was trying read a .txt that didnt exist in a while loop.... I need to start checking if files are being loaded and opened properly from now on.