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

Author Topic: [Linux] Program get crashed while usind threads and windows  (Read 2794 times)

0 Members and 1 Guest are viewing this topic.

Travnick

  • Newbie
  • *
  • Posts: 12
    • View Profile
[Linux] Program get crashed while usind threads and windows
« on: February 01, 2011, 11:53:58 pm »
I want to try SFML. Since yesterday i read tutorials and decided to write application with two windows. One is for shape render, the second is for frame rate. Every window uses separate thread. Everytnig works while there is only one window, when the seccond is added then strange things are happend.

errors:
Code: [Select]
sfmltest: xcb_io.c:221: poll_for_event: Assertion `(((long) (event_sequence) - (long) (dpy->request)) <= 0)' failed.
Przerwane (core dumped)

sfmltest: xcb_io.c:140: dequeue_pending_request: Assertion `req == dpy->xcb->pending_requests' failed.
Przerwane (core dumped)

sfmltest: xcb_io.c:128: append_pending_request: Assertion `(((long) (dpy->xcb->pending_requests_tail->sequence) - (long) (node->sequence)) < 0)' failed.
Przerwane (core dumped)

X Error of failed request:  GLXBadContextTag
  Major opcode of failed request:  136 (GLX)
  Minor opcode of failed request:  5 (X_GLXMakeCurrent)
  Serial number of failed request:  31248
  Current serial number in output stream:  31248


Eaven X serwer get crashed a few times while running my app ...

there is my code:
Code: [Select]

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
//#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <sstream>
#include <iostream>
//#include <ctime>

using namespace std;

////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////

sf::Mutex FramerateMutex;
sf::Mutex RenderMutex;
int Framerate = 0;

void framerate(void *UserData) {
    sf::Clock Clock;
    RenderMutex.Lock();

    sf::RenderWindow App2(sf::VideoMode(200, 40, 32), "SFML OpenGL", sf::Style::Close);

    //        App2.UseVerticalSync(true);
    //        App2.SetFramerateLimit(20);
    RenderMutex.Unlock();
    sf::Font MyFont;

    if (!MyFont.LoadFromFile("/usr/share/fonts/dejavu/DejaVuSans.ttf")) {
return;
    }

    sf::Event Event;

    while (Framerate != -1) {
Clock.Reset();

ostringstream text;

FramerateMutex.Lock();
text << Framerate;
cout << "fps :" << Framerate << endl;
FramerateMutex.Unlock();

sf::String Text(text.str(), MyFont);
Text.SetColor(sf::Color(255, 255, 255));

App2.SetActive();
App2.Clear();
App2.SetActive();
App2.Draw(Text);
App2.Display();
App2.SetActive(false);

// Process events
while (App2.GetEvent(Event)) {
   // Close window : exit
   if (Event.Type == sf::Event::Closed)
App2.Close();

   // Escape key : exit
   if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App2.Close();

   // Resize event : adjust viewport
   if (Event.Type == sf::Event::Resized)
glViewport(0, 0, Event.Size.Width, Event.Size.Height);
}
sf::Sleep(0.3 - Clock.GetElapsedTime());
    }
}

int main() {

    sf::Clock Clock;
    sf::Thread fps(&framerate);
    sf::WindowSettings Settings;
    Settings.AntialiasingLevel = 16; // Request 2 levels of antialiasing
    //    //Settings.
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML OpenGL", sf::Style::Close, Settings);


    sf::Shape Polygon;
    Polygon.AddPoint(0, -50, sf::Color(255, 0, 0), sf::Color(0, 128, 128));
    Polygon.AddPoint(50, 50, sf::Color(255, 85, 85), sf::Color(0, 128, 128));
    Polygon.AddPoint(50, 50, sf::Color(255, 170, 170), sf::Color(0, 128, 128));
    Polygon.AddPoint(0, 50, sf::Color(255, 255, 255), sf::Color(0, 128, 128));
    Polygon.AddPoint(-50, 50, sf::Color(255, 170, 170), sf::Color(0, 128, 128));
    Polygon.AddPoint(-50, 0, sf::Color(255, 85, 85), sf::Color(0, 128, 128));

    // Get the attributes of the third point
    sf::Vector2f Position = Polygon.GetPointPosition(2);
    sf::Color Color = Polygon.GetPointColor(2);
    sf::Color OutlineColor = Polygon.GetPointOutlineColor(2);

    // Set the attributes of the second point
    Polygon.SetPointPosition(1, sf::Vector2f(50, 100));
    Polygon.SetPointColor(1, sf::Color::Black);
    Polygon.SetPointOutlineColor(1, sf::Color(0, 128, 128));

    // Set an outline width of 10
    Polygon.SetOutlineWidth(10);

    // Disable filling the shape
    Polygon.EnableFill(false);

    // Enable drawing its outline
    Polygon.EnableOutline(true);

    Polygon.SetColor(sf::Color(255, 255, 255, 200));
    //    Polygon.Move(300, 300);
    Polygon.Scale(3, 2);




    sf::Event Event;
    Clock.Reset();
    fps.Launch();
    float vx = 2.0;
    float vy = 2.0;
    while (App.IsOpened()) {
FramerateMutex.Lock();
Framerate = 1 / App.GetFrameTime();
// Framerate = 1 / Clock.GetElapsedTime();
FramerateMutex.Unlock();
Clock.Reset();

Polygon.Rotate((0.2));
Polygon.Move(vx, vy);
if (Polygon.GetPosition().x >= 800 || Polygon.GetPosition().x <= 0) {
   vx = -vx;
}
if (Polygon.GetPosition().y >= 600 || Polygon.GetPosition().y <= 0) {
   vy = -vy;
}

// Process events
while (App.GetEvent(Event)) {
   // Close window : exit
   if (Event.Type == sf::Event::Closed)
App.Close();

   // Escape key : exit
   if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();

   // Resize event : adjust viewport
   if (Event.Type == sf::Event::Resized)
glViewport(0, 0, Event.Size.Width, Event.Size.Height);
}

RenderMutex.Lock();
App.SetActive();
App.Clear();
App.SetActive();
App.Draw(Polygon);
App.SetActive();

App.Display();
App.SetActive(false);
RenderMutex.Unlock();
    }
    FramerateMutex.Lock();
    Framerate = -1;
    FramerateMutex.Unlock();
    fps.Wait();

    return EXIT_SUCCESS;
}

 

anything