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

Author Topic: Tearing issue probably not related to vsync  (Read 6566 times)

0 Members and 1 Guest are viewing this topic.

alienjon

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Tearing issue probably not related to vsync
« on: January 27, 2013, 10:01:31 pm »
I've been working on a maze game and I've come across a strange issue with visual tearing on the top of the screen.  I've posted a screenshot to make this a bit easier to visualize (note that the tearing does not occur in the screenshot).  You'll notice that map is basically neon vertical and horizontal lines and that the camera centers on the stick figure (unless it's at the edge of the level, like in the screenshot).

The problem is that when the stick figure moves left or right on the map the vertical lines at the very top of the screen will tear.  The horizontal lines will not tear if the figure moves up or down and I've found that the problem occurs no matter the framerate it is being displayed at.  I am currently running this on Kubuntu 12.04 with an nvidia driver.  I saw in the forums another post about a tearing problem in kubuntu with nvidia, but I've disabled system-forced v-sync and ensured that the game was running at unlimited FPS (at least for testing purposes - I usually have a FPS counter on the screen, but I'm working on updating it right now, so it's not there).

I did a brief search online and found some suggestions to try limiting the game processing speed instead of the display speed to see if that has an impact, but still the same.  I've also done the opposite and set the framerate to very low.  The game is choppy at pretty much 40fps or below, I feel, but the tearing still occurs.  I'm building this on a laptop with a 60hz display, so if this were simply a vsync issue I imagine it would have gone away with the decrease to 40fps.  I feel that, no matter what I've tried, this tearing persists.  Does anyone have any ideas of stuff I could do/try?

[attachment deleted by admin]

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Tearing issue probably not related to vsync
« Reply #1 on: January 27, 2013, 10:07:04 pm »
Tearing problems usually get solved by activating vsync, not deactivating it... ;)
Did you try it also with vsync?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

alienjon

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: Tearing issue probably not related to vsync
« Reply #2 on: January 27, 2013, 11:17:05 pm »
Oh good grief, I'm sorry.  I thought I had mentioned it earlier in the message.  I had started off with vsync on and wasn't getting anywhere.  When I first noticed the problem I saw that vsync was the usual culprit, so I explicitly set it to be turned on, but when that didn't fix the problem I waited until now to figure out what was going on.  The tearing happens with vsync on and off, making me think that it might not be a graphics issue, but I just don't know what else could be causing it.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Tearing issue probably not related to vsync
« Reply #3 on: January 27, 2013, 11:23:30 pm »
How are you handling updating and rendering?

If they are not in sync then you can experience tearing, otherwise it's hard to say... Maybe a driver issue?

At best you should provide a complete and minimal example, so we can test it and eventually point out some mistakes. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

alienjon

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: Tearing issue probably not related to vsync
« Reply #4 on: January 28, 2013, 01:31:25 am »
Quote
How are you handling updating and rendering?
Probably very poorly  :P.  Thanks for the help, by the way.  As this is part of a larger, multi-file project give me a day or so to get things simplified (I'm wondering if doing so I might figure out what's going on anyway).  I'll update when I have something more specific.  Thanks again!

alienjon

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: Tearing issue probably not related to vsync
« Reply #5 on: January 28, 2013, 02:37:14 am »
Ok, so I apparently lied and decided to squeeze in the stuff tonight before bed  :P.  I've written the code as concisely as I could, and I found that the problem persists (although, admittedly, possibly not as bad as in the regular code).  Below you can find the images I refer to in the code.  Also, I added FPS information for reference.  It's console-based because I can't seem to get the SFML internal font to work for me :-/

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

sf::Sprite player, background;
sf::Texture playerTex, backgroundTex;
sf::View view;
unsigned int fps = 0;
sf::Clock fpsClock;

int main()
{
        // Setup SFML.
        sf::RenderWindow renderer;
        renderer.create(sf::VideoMode(800, 600, 32), "Example Title", sf::Style::Titlebar);
        view = renderer.getDefaultView();
        renderer.setView(view);
        renderer.setVerticalSyncEnabled(true);

        // Load stuff.
        playerTex.loadFromFile("player.png");
        player.setTexture(playerTex);
        backgroundTex.loadFromFile("background.png");
        background.setTexture(backgroundTex);

        while(renderer.isOpen())
        {
                /* Logic */
                // Input
                sf::Event event;
                while(renderer.pollEvent(event))
                {
                        if((event.type == sf::Event::Closed) ||
                                (sf::Keyboard::isKeyPressed(sf::Keyboard::C) && sf::Keyboard::isKeyPressed(sf::Keyboard::LControl)))
                                renderer.close();
                        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                                player.setPosition(player.getPosition().x - 10, player.getPosition().y);
                        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                                player.setPosition(player.getPosition().x + 10, player.getPosition().y);
                        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                                player.setPosition(player.getPosition().x, player.getPosition().y - 10);
                        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                                player.setPosition(player.getPosition().x, player.getPosition().y + 10);
                }

                // Re-center the view on the player.
                view.setCenter(player.getPosition().x, player.getPosition().y);
                renderer.setView(view);

                /* Rendering */
                renderer.clear();
                renderer.draw(background);
                renderer.draw(player);

                // Render the frame.
                renderer.display();

                if(fpsClock.getElapsedTime().asMilliseconds() > 1000)
                {
                        std::cout << "FPS: " << fps << std::endl;
                        fps = 0;
                        fpsClock.restart();
                }
                else
                        fps++;
        }

        return 0;
}
 

Here's the pics:
background.png
player.png

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Tearing issue probably not related to vsync
« Reply #6 on: January 28, 2013, 03:05:01 am »
If you're inside the event loop you shouldn't directly call sf::Keyboard::isKeyPressed but use events instead.
Real-time input and events are two different systems and should mostly kept separated... ;)
Global variables are never suggested, even for testing.
So your code should look more like this:

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

int main()
{
    // Setup SFML.
    sf::RenderWindow renderer;
    renderer.create(sf::VideoMode(800, 600, 32), "Example Title");
    renderer.setVerticalSyncEnabled(true);

        sf::View view;
    view = renderer.getDefaultView();
    renderer.setView(view);

        sf::Sprite player, background;
        sf::Texture playerTex, backgroundTex;
        unsigned int fps = 0;
        sf::Clock fpsClock;

    // Load stuff.
    playerTex.loadFromFile("player.png");
    player.setTexture(playerTex);
    backgroundTex.loadFromFile("background.png");
    background.setTexture(backgroundTex);

    while(renderer.isOpen())
    {
        /* Logic */
        // Input
        sf::Event event;
        while(renderer.pollEvent(event))
        {
            if((event.type == sf::Event::Closed))
                renderer.close();
        }

                if(sf::Keyboard::isKeyPressed(sf::Keyboard::C) && sf::Keyboard::isKeyPressed(sf::Keyboard::LControl))
                        renderer.close();

                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                        player.setPosition(player.getPosition().x - 10, player.getPosition().y);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                        player.setPosition(player.getPosition().x + 10, player.getPosition().y);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                        player.setPosition(player.getPosition().x, player.getPosition().y - 10);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                        player.setPosition(player.getPosition().x, player.getPosition().y + 10);

        // Re-center the view on the player.
        view.setCenter(player.getPosition().x, player.getPosition().y);
        renderer.setView(view);

        /* Rendering */
        renderer.clear();
        renderer.draw(background);
        renderer.draw(player);

        // Render the frame.
        renderer.display();

        if(fpsClock.getElapsedTime().asMilliseconds() > 1000)
        {
            std::cout << "FPS: " << fps << std::endl;
            fps = 0;
            fpsClock.restart();
        }
        else
            fps++;
    }

    return 0;
}
 

I don't see any kind of tearing...


The rendering is okay, so I'm not sure what's going on here. Since it's Linux, I'd guess some driver issues... :-\
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Sui

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
    • http://www.suisoft.co.uk/
Re: Tearing issue probably not related to vsync
« Reply #7 on: January 28, 2013, 09:28:10 am »
If you set VSYNC off using SFML, is the tearing behaviour exactly the same? If so, that suggests that the driver is ignoring the VSYNC (ON).

My experience using OpenGL / SFML under Windows, is that driver support for VSYNC is patchy. My main development desktop allows it no problem but my laptop ignores the flag.

In the game options, I have implemented three choices: (VSYNC) ON, OFF, FORCE.
The first two use the OpenGL flag. The FORCE option utilises Direct-X to check for the VSYNC. This solves the problem on machines with idiotic video drivers.

My experience of Linux is minimal at the moment. I plan to port my game(s) to Linux in the near future. The hard bit for me will be figuring out the O/S itself and the development tool installation / use. I'm not sure if there's another way to handle VSYNC on Linux, perhaps via the operating system API?
Gary Marples, Developer of games and other stuff.
www.suisoft.co.uk/games/BlogTwitter

alienjon

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: Tearing issue probably not related to vsync
« Reply #8 on: January 29, 2013, 04:35:15 am »
Quote from: eXpl0it3r
If you're inside the event loop you shouldn't directly call sf::Keyboard::isKeyPressed but use events instead.
Real-time input and events are two different systems and should mostly kept separated... ;)
Global variables are never suggested, even for testing.
Sage advice.  I typically avoid globals (though I usually have a few standard exceptions) but I'll keep that in mind for the input stuff.

Quote from: eXpl0it3r
The rendering is okay, so I'm not sure what's going on here. Since it's Linux, I'd guess some driver issues... :-\
I've always preferred to develop in linux over windows, but after seeing your vid I did compile the sfml libs and tried the example in windows 7.  Both my ubuntu and windows are on the same laptop (dual boot), so that would iron it out to be a driver problem, then :-/  Shame, as I recently upgraded to the latest drivers (though the problem occurred in the previous ones as well).  I'm guessing this means I don't have any options to fix it in linux unless something changes in the driver code.

Quote from: Sui
If you set VSYNC off using SFML, is the tearing behaviour exactly the same? If so, that suggests that the driver is ignoring the VSYNC (ON).
I've forced the video driver to have vsync on and I still had the same issue.  Actually, when I first started addressing this problem I tried enabling and disabling the sfml vsync, but the FPS never went above 60 no matter what I did (vsync on/vsync off/framerate limit unlimited/framerate limit limited).  After a bit of research I found out that my vsync setting in the nvidia driver config program was enabled and disabling that gave me the expected results of unchained FPS.

Also, eXpl0it3r: what program did you use to record the video?  Do you have any recommendations for a linux screen record program too?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Tearing issue probably not related to vsync
« Reply #9 on: January 29, 2013, 05:18:02 am »
Both my ubuntu and windows are on the same laptop (dual boot), so that would iron it out to be a driver problem, then :-/
Why? The only thing it shows, that it's not a hardware issue, but the Linux and Windows drivers are completely different and unfortunately Linux doesn't come with such a string driver support, that's why I'm guessing a driver issue in the first place. I'm not very familiar with Linux, but I know that there are different drivers, maybe you could try another one?

Also, eXpl0it3r: what program did you use to record the video?  Do you have any recommendations for a linux screen record program too?
I used PlayClaw to record the video, unfortunately it's Windows only. You can directly use FFMPEG, Tank has once written a small script, which could be useful: Screen-casting in Linux using ffmpeg
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

alienjon

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: Tearing issue probably not related to vsync
« Reply #10 on: January 29, 2013, 12:34:34 pm »
Quote
Why? The only thing it shows, that it's not a hardware issue, but the Linux and Windows drivers are completely different and unfortunately Linux doesn't come with such a string driver support, that's why I'm guessing a driver issue in the first place. I'm not very familiar with Linux, but I know that there are different drivers, maybe you could try another one?
There are a few linux drivers, but my understanding is that the nvidia does the best job of 3d support (I find it to often come up as the recommended driver, though I know that's subjective).  I could try with another driver - at least to see if the problem goes away, but the proprietary nvidia driver is still very much in use, so even if it works with an open source driver there would still be others affected... Of course, this is assuming anyone else would end up actually playing my final product  ;)

Quote
I used PlayClaw to record the video, unfortunately it's Windows only. You can directly use FFMPEG, Tank has once written a small script, which could be useful: Screen-casting in Linux using ffmpeg
Thanks for the recommendations!  I'll look into them both :-)

alienjon

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: Tearing issue probably not related to vsync
« Reply #11 on: January 30, 2013, 02:57:08 am »
I did make (however terribly) a short video demonstrating the issue if that's helpful for anyone.  I'll try some open source drivers to see if that helps, but I at least wanted to try showing what I'm experiencing here.  As I threw it together real quick, the main points to focus on are on the first 10 seconds (not the last 15 :-p).

http://www.youtube.com/watch?v=Kvgz_hQCkZ4&feature=youtu.be