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

Author Topic: Visual Studio working fine but white screen with the executable  (Read 350 times)

0 Members and 1 Guest are viewing this topic.

Tom Clabault

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Hello

So. I compiled my project using Visual Studio 2017 and within Visual Studio, no problems, the project runs fine, everything is alright.
The thing is that when I'm trying to launch the .exe produced by Visual Studio, the game pops, there's a window but it's white, as is there were no textures and it's not responding, as is the program crashed

I searched on the Internet but didn't found any relevant answer.

Thanks in advance

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9191
    • View Profile
    • development blog
    • Email
Re: Visual Studio working fine but white screen with the executable
« Reply #1 on: March 08, 2019, 02:28:08 pm »
Do you have some anti virus software running?
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

Tom Clabault

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Re: Visual Studio working fine but white screen with the executable
« Reply #2 on: March 08, 2019, 09:33:14 pm »
Windows Defender, nothing else. I added an exception but no changes

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6155
  • Thor Developer
    • View Profile
    • Bromeon
Re: Visual Studio working fine but white screen with the executable
« Reply #3 on: March 08, 2019, 09:59:37 pm »
Another possibility is that the working directory is different than when launching from the IDE. This can affect loaded resources (images, fonts, etc.) on one hand, but also dynamic libraries (DLLs) that your application depends on.

For resources, make sure you use a relative path from the same origin as in the IDE. If necessary, print some debug info on stdout before you do any SFML logic. The C++17 filesystem library will help you in this.

For *.dll files, either place them in the same directory as the *.exe, or in the environment variable PATH so that they're found.
« Last Edit: March 08, 2019, 10:01:38 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: first SFML book

Tom Clabault

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Re: Visual Studio working fine but white screen with the executable
« Reply #4 on: March 08, 2019, 10:25:15 pm »
To load ressources, I'm using path such as "./Resources/Textures/....png". Any problem with that kind of syntax ?
When running the .exe, Windows doesn't complain with missing DLLs so I assume they are at the right place

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6155
  • Thor Developer
    • View Profile
    • Bromeon
Re: Visual Studio working fine but white screen with the executable
« Reply #5 on: March 10, 2019, 02:03:46 pm »
As mentioned, you should debug your path and make sure it's found. A simple way to do so is to create a file at that location -- and see where it actually shows up in Explorer.

Apart from that, a crash is not the expected behavior when something can't be loaded, unless you don't check the error after loading and make subsequent logic dependent on the resource's existence. Thus, ensure that a simple main() that does nothing else than loading the resource succeeds.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: first SFML book

Tom Clabault

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Re: Visual Studio working fine but white screen with the executable
« Reply #6 on: March 11, 2019, 09:51:46 pm »
I created a file at the location pointed by the path and the file is actually where it it supposed to be...

if(!texture.loadFromFile("..."))
    exit(0);

That's what I do if the texture hasn't been loaded properly.
After trying not to give the program the textures he needed ( simply delete the textures from the executable location ), it takes half a second for the program to exit, that's really quick.
When giving the program the textures he needs ( As my game needs textures to work : ) ), it takes randomly from 4s to 16s for the game to crash after a white screen

By the way, I don't think that exit(0); is what to do in case the texture hasn't been loaded. What should I do since I need the texture later with the Sprites ?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6155
  • Thor Developer
    • View Profile
    • Bromeon
Re: Visual Studio working fine but white screen with the executable
« Reply #7 on: March 17, 2019, 10:47:54 am »
Is there any debug output on stderr explaining why the texture can't be loaded?
From the 4-16s it seems like the crash is not directly related to the texture loading, but another error in the program.

You should generally avoid std::exit() in C++, as it does not properly clean up all resources.
Quote from: https://en.cppreference.com/w/cpp/utility/program/exit
Stack is not unwound: destructors of variables with automatic storage duration are not called.

Instead, propagate the error up to your main function (e.g. using exceptions), and return a non-zero error code.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: first SFML book

Tom Clabault

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Re: Visual Studio working fine but white screen with the executable
« Reply #8 on: March 17, 2019, 02:40:37 pm »
I found what the error was and it was kinda stupid. A fopen() returned NULL but I wasn't checking for this kind of errors so the program kept on going with a NULL pointer... Nothing good happen then : )
There's no more problem. Is there any "Solved" state I need to set for the topic ?

One more question considering what you said:
What does it implies that destructors of variables aren't called ? If my program exits, all the memory used is released right ? So what's the problem of not calling the destructors on program exit ?