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

Author Topic: Window not showing anymore  (Read 1411 times)

0 Members and 1 Guest are viewing this topic.

Maikibu

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Window not showing anymore
« on: October 25, 2020, 02:09:51 am »
My window won't appear anymore. It used to work, I could already see and move around sprites, but for no apparent reason now my program won't get past the very first line:


int main()
{
    g_window = new sf::RenderWindow(sf::VideoMode(1080, 720), "MyGame");
    // ...never reaches here


If I put code before that line with a breakpoint, it works. But as soon as it reaches that line, it's like an infinite loop... And the window never appears.

Stauricus

  • Sr. Member
  • ****
  • Posts: 303
    • View Profile
    • Email
Re: Window not showing anymore
« Reply #1 on: October 25, 2020, 03:13:51 am »
I don't really know why you are trying to use new in that case, but try
sf::RenderWindow g_window(sf::VideoMode(1080, 720), "MyGame");

Maikibu

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Window not showing anymore
« Reply #2 on: October 25, 2020, 11:17:05 am »
The issue was in fact related to my misuse of "new". I was saving the pointer into a class that granted global access, similarly to a singleton:

------
Renderer.h
#pragma once
#include "SFML\Graphics\RenderWindow.hpp"

extern sf::RenderWindow* g_window;
-------
-------
Renderer.cpp
#include "Renderer.h"

sf::RenderWindow* g_window;
-------

However, I was forgetting to delete the instance when closing the program. I imagine that after a number of times there was too much leaked memory. Simply had to restart my PC.

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: Window not showing anymore
« Reply #3 on: October 26, 2020, 05:16:27 pm »
More like you are doing something that you shouldn't be doing. Don't have global SFML resources like this. Have a proper design, and singleton is pretty much always bad.
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

 

anything