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

Author Topic: Weird stuttering and freezing  (Read 2184 times)

0 Members and 1 Guest are viewing this topic.

Fray

  • Newbie
  • *
  • Posts: 5
    • View Profile
Weird stuttering and freezing
« on: July 28, 2011, 12:13:39 pm »
Hi,

My window doesn't seem to refresh correctly  (stuttering / freezing) when I try to display some sprites.
The strange thing is that it only happens when there is between about 2442 and 2507 sprites.
Even stranger, the problem disappears when I use Fraps or some other overlay to display the fps count.

Here's the code:
Code: [Select]

#include <SFML/Graphics.hpp>
#include <vector>

//#define SPRITES 2442
#define SPRITES 2500
//#define SPRITES 2507

#define WIDTH 1024
#define HEIGHT 768

inline float frand(const float min, const float max)
{
    return ((float(rand()) / float(RAND_MAX)) * (max - min)) + min;
}

void main()
{
sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT), "Bench");

sf::Image image;
image.LoadFromFile("sprite1.png"); // 64x64
image.SetSmooth(true);
float originX = image.GetWidth() / 2.0f;
float originY = image.GetHeight() / 2.0f;

std::vector<sf::Sprite*> sprites;
for(int i = 0; i < SPRITES; ++i)
{
sf::Sprite* sprite;
sprite = new sf::Sprite(image);
sprite->SetBlendMode(sf::Blend::Alpha);
sprite->SetPosition(frand(0, WIDTH), frand(0, HEIGHT));
sprite->SetOrigin(originX, originY);
sprites.push_back(sprite);
}

sf::Clock timer;
unsigned int lastTime = 0, frameTime = 0, delta = 0;
float step = 1000.0f / 60;

sf::Sprite* sprite;
sf::Event evt;
while (window.IsOpened())
{
while (window.PollEvent(evt))
{
if (evt.Type == sf::Event::Closed)
window.Close();
}
frameTime = timer.GetElapsedTime();
delta = frameTime - lastTime;
if (delta >= step)
{
window.Clear();
lastTime = frameTime;
for (std::vector<sf::Sprite*>::iterator it = sprites.begin(), itEnd = sprites.end(); it != itEnd; ++it)
{
sprite = *it;
sprite->Rotate(1);
window.Draw(*sprite);
}
window.Display();
}
}

}


I doesn't look like it's graphics related because the animation "continues" during the freezes.

I'm using SMLF2, static libs, VS 2010, Win7, ATI graphics card.

Thanks in advance  :)

Jove

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • http://www.jestofevekites.com/
Weird stuttering and freezing
« Reply #1 on: July 28, 2011, 01:03:24 pm »
Long shot here, but do you have Task Manager open?

When I do with an Aero theme, the TM window update causes my game to stutter once, every second.
{much better code}

Fray

  • Newbie
  • *
  • Posts: 5
    • View Profile
Weird stuttering and freezing
« Reply #2 on: July 28, 2011, 01:08:05 pm »
Quote from: "Jove"
Long shot here, but do you have Task Manager open?


Nope
I'll try disabling Aero, just to be sure, since I've already tried nearly everything else.

Edit: Disabling desktop composition seems to fix the problem. But that's not what you can really call "fixing", right?  :D

Another funny thing is that the freezing disappears if I put, for example a video player window, beneath my SFML app (the part of the window which is above the video player gets refreshed, the rest of the window remains frozen).

therocode

  • Full Member
  • ***
  • Posts: 125
    • View Profile
    • Development blog
Weird stuttering and freezing
« Reply #3 on: August 05, 2011, 10:06:13 pm »
I also had this problem and disabling the desktop composition helped as well. Not nice if every player would have to do that to play the game though. :/

Somebody who knows a workaround?