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

Author Topic: [Advice/Warning] RenderWindow Android Crash  (Read 2628 times)

0 Members and 2 Guests are viewing this topic.

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
[Advice/Warning] RenderWindow Android Crash
« on: April 14, 2016, 02:29:07 am »
I want to advice that creating o initializing a RenderWindow before the entry point (main) is called will cause and app crash on Android.

Tested with SFML 2.3.2.
Devices: Sony Xperia E3 & Samsumg Galaxy Note 4.

Example:


sf::RenderWindow window ;

void main() // Entry Point.
{
   // Game logic .. bla bla.
}

 

This will compile but will crash.

If for whatever reason you need the RenderWindow outside the main function, the workaround is make the RenderWindow a pointer.

sf::RenderWindow *window ;

void main() // Entry
{
  sf::RenderWindow win( sf::VideoMode::getDesktopMode() , "" ) ;
  window = &win ;
   // Game logic .. bla bla.
}
 

Hope it help for finding bugs.

If the bug was/is repaired please notify on this topic.

PD: Should i start a "new issue" on GitHub?
« Last Edit: April 14, 2016, 02:31:17 am by DarkRoku »
I would like a spanish/latin community...
Problems building for Android? Look here

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: [Advice/Warning] RenderWindow Android Crash
« Reply #1 on: April 14, 2016, 09:08:24 am »
Nope, it's well-known that globals are bad and that global OpenGL/SFML resources tend to blow up.

Yes, global variables are really error-prone (initialization and destruction order, multithreading, no access control, lots of dependencies). Even more sf::RenderWindow, never make it global.

I cannot remember exactly what goes wrong when you have a global resource (if there is a post explaining that in detail the forum search isn't good enough to find it) but I'm under the impression that this is not the sort of thing SFML can "fix" but rather an inherent problem with using global variables that refer to objects from an extremely stateful API like OpenGL.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
AW: [Advice/Warning] RenderWindow Android Crash
« Reply #2 on: April 14, 2016, 11:29:04 am »
Globally initialized SFML resources are "prohibited" because the destruction order of global objects is undefined, meaning internal SFML states could be destroyed before your global variable leading to crashes.

I'm not sure but with Android it could also be, that some things need to be properly initialized before the main function is called.

As for the topic: The better solution is to use classes instead, which will give you a fully and non-globally defined scope.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/