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

Author Topic: RenderWindow default constructor  (Read 1328 times)

0 Members and 1 Guest are viewing this topic.

Corbett

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
RenderWindow default constructor
« on: February 12, 2018, 11:04:15 pm »
Hello. Simple question from noob. Tried to compile example project, everything looks OK:

int main()
{
  sf::RenderWindow MainRenderWindow((sf::VideoMode(800, 600), "my game");
  <skipped>
}

Changed a little:

sf::RenderWindow MainRenderWindow;
int main()
{
   MainRenderWindow.create(sf::VideoMode(800, 600), "my game");
}

It's crashed before entering main() function. I think it's crashed here:

void GlContext::initResource()
{
    Lock lock(mutex); <----- NULL value

So... If the default constructor crashes, may be better to delete it?
My config: VS 2017, SFML 2.4.2, build x64 Debug

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: RenderWindow default constructor
« Reply #1 on: February 12, 2018, 11:29:06 pm »
Don't use globally initialize SFML resources.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Corbett

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: RenderWindow default constructor
« Reply #2 on: February 13, 2018, 12:02:33 am »
Thanks, this works.

int main() {
  sf::RenderWindow MainRenderWindow;
  MainRenderWindow.create(sf::VideoMode(800, 600), "my game");
}