SFML community forums
Help => Window => Topic started by: AdrianM on January 20, 2010, 08:42:17 pm
-
I just downloaded the snapshot from here: http://www.sfml-dev.org/download.php. I'm running on Ubuntu 9.10 and after the application exited the resolution was not restored(it remained under the resolution of the sfml application). Is this a problem with SFML or i am forgetting something?
-
Does the same thing happen with SFML 1.5?
Can you show your code?
-
Does the same thing happen with SFML 1.5?
Can you show your code?
The code is kind of long, i'll make some minimal example right away!
-
Does the same thing happen with SFML 1.5?
Can you show your code?
The code is kind of long, i'll make some minimal example right away!
Further tests did not show up the problem anymore. It just happened the first time i ran the sfml application. Now it seems it's working fine. I'll tests on other machines and report back!
Thanks for the fast reply!
-
After further experimentation i have managed to reproduce(every time i was fast enough) a somewhat weird issue. First of all here's the code:
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <fstream>
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
// Create the main window
sf::RenderWindow* pApplication = new sf::RenderWindow;
pApplication->Create(sf::VideoMode(800, 600, 32),
"Testing!",sf::Style::Fullscreen);
// Create a clock for measuring the time elapsed
sf::Clock Clock;
// Set the color and depth clear values
glClearDepth(1.f);
glClearColor(0.f, 0.f, 0.f, 0.f);
// Enable Z-buffer read and write
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
// Setup a perspective projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.f, 1.f, 1.f, 500.f);
// Start the game loop
while (pApplication->IsOpened())
{
// Process events
sf::Event Event;
while (pApplication->GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
{
delete pApplication;
//pApplication->Close();
}
// Escape key : exit
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
pApplication->Close();
// Resize event : adjust viewport
if (Event.Type == sf::Event::Resized)
glViewport(0, 0, Event.Size.Width, Event.Size.Height);
}
// Set the active window before using OpenGL commands
// It's useless here because the active window is always the same,
// but don't forget it if you use multiple windows
pApplication->SetActive();
// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Apply some transformations
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.f, 0.f, -200.f);
glRotatef(Clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f);
glRotatef(Clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f);
glRotatef(Clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f);
// Draw a cube
glBegin(GL_QUADS);
glColor3f(1.f, 0.f, 0.f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);
glColor3f(1.f, 0.f, 0.f);
glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f( 50.f, 50.f, 50.f);
glVertex3f( 50.f, -50.f, 50.f);
glColor3f(0.f, 1.f, 0.f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f(-50.f, -50.f, 50.f);
glColor3f(0.f, 1.f, 0.f);
glVertex3f(50.f, -50.f, -50.f);
glVertex3f(50.f, 50.f, -50.f);
glVertex3f(50.f, 50.f, 50.f);
glVertex3f(50.f, -50.f, 50.f);
glColor3f(0.f, 0.f, 1.f);
glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f, 50.f);
glColor3f(0.f, 0.f, 1.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, 50.f);
glEnd();
// Finally, display the rendered frame on screen
pApplication->Display();
}
return EXIT_SUCCESS;
}
Now for the problem: run the application and just after you see the desktop run it again but very fast, so the resolution switch is not complete. The application will either run in window mode or run as usual but not preserve the resolution. I'm running on Ubuntu 9.10 here. Thanks!
-
Does it happen:
- when you close the window => "delete pApplication", which leads to an undefined behaviour because you don't exit the main loop and still use the pointer
or
- when you press escape => "pApplication->Close()", which leads to a memory leak because you never delete the window, and thus the desktop resolution is never restored
:?:
-
Does it happen:
- when you close the window => "delete pApplication", which leads to an undefined behaviour because you don't exit the main loop and still use the pointer
or
- when you press escape => "pApplication->Close()", which leads to a memory leak because you never delete the window, and thus the desktop resolution is never restored
:?:
When i press Escape. I thought close was just enough to close the window and restore the resolution, hmm...
-
When i press Escape. I thought close was just enough to close the window and restore the resolution, hmm...
That's right, actually ;)
But you should still delete your instance anyway. Or better: don't allocate it with new.
-
When i press Escape. I thought close was just enough to close the window and restore the resolution, hmm...
That's right, actually ;)
But you should still delete your instance anyway. Or better: don't allocate it with new.
Yes you are right! Here is another code. After compiling the application and running:
./Application & ./Application from the console the app is executed in two instances. The first instance is ok, but the second is just in windowed mode and can't be closed. Is this intended behaviour?
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <fstream>
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
// Create the main window
sf::RenderWindow Application(sf::VideoMode(800, 600, 32),
"Testing!",sf::Style::Fullscreen);
// Create a clock for measuring the time elapsed
sf::Clock Clock;
// Set the color and depth clear values
glClearDepth(1.f);
glClearColor(0.f, 0.f, 0.f, 0.f);
// Enable Z-buffer read and write
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
// Setup a perspective projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.f, 1.f, 1.f, 500.f);
// Start the game loop
while (Application.IsOpened())
{
// Process events
sf::Event Event;
while (Application.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
{
Application.Close();
break;
}
// Escape key : exit
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
{
Application.Close();
break;
}
// Resize event : adjust viewport
if (Event.Type == sf::Event::Resized)
glViewport(0, 0, Event.Size.Width, Event.Size.Height);
}
// Set the active window before using OpenGL commands
// It's useless here because the active window is always the same,
// but don't forget it if you use multiple windows
Application.SetActive();
// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Apply some transformations
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.f, 0.f, -200.f);
glRotatef(Clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f);
glRotatef(Clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f);
glRotatef(Clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f);
// Draw a cube
glBegin(GL_QUADS);
glColor3f(1.f, 0.f, 0.f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);
glColor3f(1.f, 0.f, 0.f);
glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f( 50.f, 50.f, 50.f);
glVertex3f( 50.f, -50.f, 50.f);
glColor3f(0.f, 1.f, 0.f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f(-50.f, -50.f, 50.f);
glColor3f(0.f, 1.f, 0.f);
glVertex3f(50.f, -50.f, -50.f);
glVertex3f(50.f, 50.f, -50.f);
glVertex3f(50.f, 50.f, 50.f);
glVertex3f(50.f, -50.f, 50.f);
glColor3f(0.f, 0.f, 1.f);
glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f, 50.f);
glColor3f(0.f, 0.f, 1.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, 50.f);
glEnd();
// Finally, display the rendered frame on screen
Application.Display();
}
return 0;
}
-
The first instance is ok, but the second is just in windowed mode and can't be closed. Is this intended behaviour?
Yes, only one fullscreen window is allowed.
-
The first instance is ok, but the second is just in windowed mode and can't be closed. Is this intended behaviour?
Yes, only one fullscreen window is allowed.
Okay, but sometimes it may happen something as i stated above: a sfml application exits from fullscreen mode, does not finish it's business with freeing resources and restoring resolution and i click another fullscreen application. In this moment the second application is just hanged there. Do you plan to address this issue in the future ?
-
Well, I'm not even sure that this is an issue. Can't you just wait until the resolution switch is finished after closing the SFML app?
-
Well, I'm not even sure that this is an issue. Can't you just wait until the resolution switch is finished after closing the SFML app?
Well, yes, i can do that, no problem, just wanted to see what are your thoughts about this and if one must considere it an issue or not. :D
-
Honestly I have no idea. What you could do is to test another fullscreen program instead of your SFML app, and see if you get the same thing.
-
I don't know if this really helps, but a problem I recently came across:
This code leads to OpenGL errors because Close() is invoked and the OpenGL functions are still called (even if only for one frame). This can be fixed by a return statement (instead of break, which only exits the inner loop) after Application.Close();.
Laurent, maybe you should fix this in your OpenGL sample, too.