SFML community forums

Help => Window => Topic started by: Maikibu on October 25, 2020, 02:09:51 am

Title: Window not showing anymore
Post by: Maikibu 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.
Title: Re: Window not showing anymore
Post by: Stauricus 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");
Title: Re: Window not showing anymore
Post by: Maikibu 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.
Title: Re: Window not showing anymore
Post by: Rosme 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.