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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - 7krs

Pages: 1 [2] 3
16
Window / [SEMI-SOLVED] I Think I Found A Memory Leak
« on: January 16, 2013, 11:01:13 pm »
A minimal example:

    sf::RenderWindow* ptr = new sf::RenderWindow(sf::VideoMode(800, 600, 32), "title");
    ptr->setActive(false);
    while (true)
    {
        std::thread([=]()
                    {
                        ptr->setActive(true);
                        ptr->setActive(false);
                    }
                    ).join();
    }
 

Memory keeps rising (from ~12MB to over 300MB). Requesting confirmations.

17
Window / Re: Problems Threading A Window
« on: December 20, 2012, 11:47:50 am »
Quote
returns 234
How do you see that? Does it crash? If so, have you tried to run the debugger?




It comes up in the little terminal window like that. And no it doesn't crash, it just exits this way.


Yes, I have tried the debugger, but I can't seem to step into return 0; (Where dtors are called). The debugger finishes just fine.

18
Window / Re: Problems Threading A Window
« on: December 19, 2012, 10:50:37 pm »
No, not a single instance is global.


#include <SFML/Graphics.hpp>

class Draw
{
public:
    Draw()
    {
    }
    void start()
    {
        thr = new sf::Thread(&Draw::drawer, this);
        thr->launch();
    }
    void setWindow(sf::RenderWindow *wind)
    {
        wnd = wind;
    }
private:
    void drawer()
    {
        wnd->setActive(true);
        wnd->clear(sf::Color::Green);
        wnd->display();
        wnd->setActive(false);
    }
    sf::Thread *thr;
    sf::RenderWindow *wnd;
};

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600, 32), "Title", sf::Style::Default);
    Draw object;
    window.setActive(false);
    object.setWindow(&window);
    object.start();
    sf::sleep(sf::seconds(2)); // So the thread can finish in peace.
    return 0;
}

returns 234.

19
Window / Re: Problems Threading A Window
« on: December 19, 2012, 10:33:05 pm »
Problem is I don't, in practice the window is located in a class, and the thread is in another dedicated to drawing.

20
Window / Problems Threading A Window
« on: December 19, 2012, 09:20:56 pm »
Hi,

the code works, it's just that the return code is weird:

#include <SFML/Graphics.hpp>
sf::RenderWindow wnd;

void sig()
{
    wnd.setActive(true);
    wnd.clear(sf::Color::Green);
    wnd.display();
    wnd.setActive(false);
}

int main()
{
    wnd.create(sf::VideoMode(800, 600, 32), "Title", sf::Style::Default);
    wnd.setActive(false);
    sf::Thread ap(sig);
    ap.launch();
    ap.wait();
    return 0;
}
 

This is a minimal example, and it returns 234, or 0xEA in hex.

#include <SFML/Graphics.hpp>
sf::RenderWindow wnd;

void sig()
{
    wnd.setActive(true);
    wnd.clear(sf::Color::Green);
    wnd.display();
}

int main()
{
    wnd.create(sf::VideoMode(800, 600, 32), "Title", sf::Style::Default);
    wnd.setActive(false);
    sf::Thread ap(sig);
    ap.launch();
    ap.wait();
    return 0;
}
 

Will cause a segmentation fault and return 139 (0x8B).

What am I doing wrong?

21
Graphics / Re: [SOLVED] Very long rendering C-SFML / CAML-LIGHT
« on: October 29, 2012, 09:49:43 am »
But why Laurent? It worked for me and I never got any memleaks, could you explain why it is wrong to do so?

22
Graphics / Re: sf::Texture Destructor Causing Segfault
« on: October 28, 2012, 11:30:41 pm »
I copy / pasted your code.

Using C::B and MinGW as well, SFML 2.0 rc (latest update ~3 weeks ago). Ran it through the debugger, nothing. Created a small png file "image.png". No problems anywhere. Maybe you have some other code from a global class where the ctor is called before main? And the dtor of this class causes the segfault? I don't know otherwise  :-X

#include <SFML/Graphics.hpp>

using namespace sf;

int main()
{
    RenderWindow window(VideoMode(640, 480, 32), "Texture Crasher");
    Texture tx1, tx2;
    tx1.loadFromFile("image.png");
    tx2.loadFromFile("image.png");

    while(window.isOpen())
    {
         Event event;
         while (window.pollEvent(event))
         {
            if (event.type==Event::Closed)
            window.close();
         }

        window.clear();
        window.display();

        sleep(milliseconds(25));
    }
    return 0;
}
 

23
Graphics / Re: [SOLVED] Very long rendering C-SFML / CAML-LIGHT
« on: October 28, 2012, 11:20:02 pm »
how to update just a part of the window ?

Well I found that you can update just part of the window by simply drawing over it without clearing:
You could basically "clear" parts using sf::RectangleShape or even sf::CircleShape of your desired size and colour.

EDIT: read Laurent's comments in the posts beneath. This method is "not reliable".

24
Semaphores sound appropriate, after all, there could be a / some threads dedicated to handling locks. I only worry about increased complexity.

I'll check it out and see if I find any good solutions.

Thanks.

25
No that is not exactly what I had in mind;

I'd like a thread to be able to wait until there is a state change, then compute. Simply put.

26
Hello,

I am wondering if (possibly how) it would be possible to utilize sf::Event / (sf::Lock || sf::Mutex) to make threads process data at specific intervals. Why? Because it seems to me that sf::RenderWindow::waitEvent() and the mutexes are able to hlt (0xF4) the thread. This means ~0 processor usage - less power, less heat, more for other purposes.

I came up with two possible methods, but none work:

1. I am unable to lock a thread from itself.
#include <SFML/System.hpp>
#include <iostream>

sf::Mutex mutex;
bool runThread = true;
signed int dataToProcess = 0;

void processData()
{
    while (runThread)
    {
        mutex.lock();
        mutex.lock(); // Here I would like the thread to lock itself, and thus wait for any external mutex.unlock to complete one iteration.
        dataToProcess *= 10;
        std::cout << dataToProcess << std::endl;
    }
}

int main()
{
    sf::Thread dataProcessor(processData);
    dataProcessor.launch();
    while (runThread)
    {
        int numberAddition = 0;
        std::cin >> numberAddition;
        if (numberAddition == 0)
        {
            runThread = false;
            dataProcess.wait();
            return dataToProcess;
        }
        dataToProcess += numberAddition;
        mutex.unlock(); // The thread is now iterated through once.
    }
    return 0;
}

 

2. I am unable to wait for specific events in another thread.
    - Thread_1 & Thread_2 are running in parallel.
    - I want to make Thread_2 wait for a boolean to change. No polling.
    - If said boolean is changed, iterate over Thread_2's instructions.
    - When iteration is complete, wait for a change in boolean again.

This can however be solved by simply launching the thread from the location where it is needed, but what if I have local variables in the thread function that need to be re-initialized (extra processing power)? What if the locals need to contain data from previous iterations (A class can solve this tho...)? What if the function contains smaller parts that we can loop through? Using shared booleans in this context would be messy IMHO.

I'll rephrase my question; can we control a thread - that runs continuously - whilst utilizing the anti-power hogging delight of mutexes/locks or waitEvents? (Or is there something superior?)

27
Alright, all my questions have been answered, thanks a lot!

28
Thanks for the info and response.

What would you say is faster:

One sprite, switch the texture thereof, this means the window drawing function does not have to check for a condition, the pointer rendertexture changes during every iteration:

rendertexture->display();

renderSprite.setTexture(renderTexture->getTexture());
 

or

Two sprites, each for a rendertexture, switch which is drawn, window drawing function checks on every iteration (or one could change a pointer to the renderSprite at the end of the rendertexture thread iteration):

if (first)
    window.draw(firstRenderSprite);
else
    window.draw(secondRenderSprite);
 

29
Hello there,

I have two threads, one drawing a sprite to the screen at 30 Hz, the other drawing to a RenderTexture at 1 Hz.

The thread drawing to the RenderTexture has a lot of work to do, so whilst it is drawing, the first thread draws an unfinished sprite to the screen. This can be seen as half of what's being drawn, flickers.

I see that the sprite holds a reference to the renderTexture's texture, and I don't want to sf::Mutex::Lock the entire clear()-display() part of the second thread, that'd take too much time. So therefore I want one sprite that is always complete, and gets updated after finishing drawing to the rendertexture, to avoid the flickering.

How do I do this?

30
"ATI Radeon HD 3200 Graphics"

Under windows 7 device manager.

"Windows has determined the driver software for your device is up to date."

Pages: 1 [2] 3
anything