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 - Romex

Pages: [1]
1
SFML projects / Re: Witch Blast (dungeon crawl shooter)
« on: April 20, 2014, 06:57:18 am »
Nice music=D

2
Graphics / Re: sf::Text shift
« on: January 14, 2013, 11:23:11 am »
Thanks!

3
Graphics / sf::Text shift
« on: January 14, 2013, 11:07:45 am »
Hello!
#include <SFML/system.hpp>
#include <SFML/graphics.hpp>
int main()
{
        sf::Font font;
        font.loadFromFile("fallout_decayed.ttf");

        sf::Text text("EXAMPLE",font, 50 );
        text.setPosition( 100, 100 );
        text.setColor(sf::Color::Red);

        sf::RectangleShape rectangle( sf::Vector2f( text.getGlobalBounds().width, text.getGlobalBounds().height )  );
        rectangle.setPosition(100,100);
       
        sf::RenderWindow window( sf::VideoMode(400, 300), "EXAMPLE" );

        while( window.isOpen() )
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }
                window.clear();
                window.draw( rectangle );
                window.draw(text);
                window.display();
        }
        return 0;      
}
 
Why is the text shifted from its position?

4
Graphics / Re: Divide by zero in sf::RenderWindow::draw SFML 2.0
« on: January 11, 2013, 02:05:52 pm »
Thanks
Quote
It also allocates the objects dynamically

Yes, but it frees allocated memory itself.
Quote
Btw having two variables with nearly the same names (states vs states_) is a bit misleading.
It's my old illness/=

5
Graphics / Divide by zero in sf::RenderWindow::draw SFML 2.0
« on: January 11, 2013, 01:41:25 pm »
Hello!
In my simple button class I store textures and sprites in
std::vector< std::pair< sf::Sprite , sf::Texture > > states;
It works, but some times i've got this:
Unhandled exception at 0x0f6d2382 in D_D.exe: 0xC0000094: Integer division by zero.
on
 target.draw(  states [ pos ].first, states_ );
It happens when size of states > 3.  I think sprite's link to texture become not valide when std::vector reallocate his memory .

I don't want to use dynamic memory or std::vector::reserve to solve it.
Are there any other solution?

Sorry for my English :)

6
System / Re: vector<sf::thread *> = memory leak
« on: May 19, 2012, 03:08:18 pm »
Problem is solved!
Program I used finds leaks in code without SFML.
Sorry for claiming :'(

7
System / Re: vector<sf::thread *> = memory leak
« on: May 19, 2012, 01:51:05 pm »
Are you sure there's a memory leak (and not just the allocation in the Windows Task Manager)? How did you measure it?
Yes, I am. Intel Parallel Studio.

8
System / Re: vector<sf::thread *> = memory leak
« on: May 19, 2012, 01:35:51 pm »
#include<SFML\Graphics.hpp>
#include <vector>
#include<iostream>
#include <Windows.h>
std::vector < std::pair< sf::Thread * , int> > threadArray;
void loop( int id)
{
        //empty window
        sf::RenderWindow window(sf::VideoMode(800, 400, 32), "", 4);
        while ( window.isOpen() )
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if ((event.type == sf::Event::Closed) ||
                                ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
                        {
                                window.close();
                                break;
                        }
                }
                window.clear(sf::Color::White);
                window.display();
        }
        //mark thread as ended
        for( int i=0; i<threadArray.size(); i++ )
        {
                if(threadArray[i].second == id)
                        threadArray[i].second = -1;
        }
};
int main()
{
        sf::RenderWindow window( sf::VideoMode(800, 400, 32), "memory leak example", 4);
        window.setPosition(sf::Vector2i( 0,0) );
        int threadId = 0;
        while ( window.isOpen() )
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if ((event.type == sf::Event::Closed) ||
                                ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
                        {
                                window.close();
                                break;
                        }
                        if(event.type == event.MouseButtonPressed)
                        {
                                if(event.mouseButton.button == sf::Mouse::Left)
                                {

                                        threadArray.push_back( std::pair< sf::Thread* , int >( new sf::Thread( &loop, threadId ), threadId ) );
                                        threadArray.back().first->launch();
                                        Sleep(100);
                                        threadId++;
                                }
                        }
                }
                for( int i=0; i < threadArray.size(); i++ )
                {
                        if(threadArray[i].second == -1)
                        {
                                delete threadArray[i].first;
                                threadArray.erase( threadArray.begin() + i );
                                i = 0;
                        }
                }
                window.clear(sf::Color::White);
                window.display();
        }
        return EXIT_SUCCESS;
}


 
This code with regular deallocating without using ended threads has the same problem.
Quote
Why don't you write a class that stores a window and its own thread? Then you can just have a container with elements of this class, and don't need questionable code to reuse threads.
It's not that code where I noticed the problem.
I tried to write simple example which illustrate trouble. Sorry if it is not good.

9
System / Re: vector<sf::thread *> = memory leak
« on: May 19, 2012, 01:12:08 pm »
I don't use delete because it's not necessary. Ended threads are used again.
thread class is noncopyable and has no move semantics. [/tt].
It's main problem.

10
System / vector<sf::thread *> = memory leak
« on: May 19, 2012, 12:50:58 pm »
Hello!
I use SFML 2.0 RC (17.05.2012).
This program opens new subwindow when main window is clicked.
#include<SFML\Graphics.hpp>
#include <vector>
#include<iostream>
#include <Windows.h>
std::vector < std::pair< sf::Thread * , int> > threadArray;
void loop( int id)
{
        //empty window
        sf::RenderWindow window(sf::VideoMode(800, 400, 32), "", 4);
        while ( window.isOpen() )
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if ((event.type == sf::Event::Closed) ||
                                ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
                        {
                                window.close();
                                break;
                        }
                }
                window.clear(sf::Color::White);
                window.display();
        }
        //mark thread as ended
        for( int i=0; i<threadArray.size(); i++ )
        {
                if(threadArray[i].second == id)
                        threadArray[i].second = -1;
        }
};
int main()
{
        sf::RenderWindow window( sf::VideoMode(800, 400, 32), "memory leak example", 4);
        window.setPosition(sf::Vector2i( 0,0) );
        int threadId = 0;
        while ( window.isOpen() )
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if ((event.type == sf::Event::Closed) ||
                                ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
                        {
                                window.close();
                                break;
                        }
                        if(event.type == event.MouseButtonPressed)
                        {
                                if(event.mouseButton.button == sf::Mouse::Left)
                                {
                                        int i=0;
                                        //use ended
                                        for(; i < threadArray.size(); i++)
                                        {
                                                if( threadArray[i].second == -1 )
                                                {
                                                        threadArray[i].first->launch();
                                                        threadArray[i].second = i;
                                                        break;
                                                }
                                        }
                                        //or create new thread
                                        if( i== threadArray.size() )
                                        {
                                                threadArray.push_back( std::pair< sf::Thread* , int >( new sf::Thread( &loop, threadId ), threadId ) );
                                                threadArray.back().first->launch();
                                                Sleep(100);
                                                threadId++;
                                        }
                                }
                        }
                }
                window.clear(sf::Color::White);
                window.display();
        }
        return EXIT_SUCCESS;
}
 
It works, but I noticed memory leak about 3mb per new subwindow.
I suppose it's incorrect to store threads in dynamic memory, but I have not any idea how to do it differently.
How can I solve this problem?
Thank you for your help and sorry for my English.

11
Graphics / color line SFML2
« on: March 30, 2012, 12:32:18 pm »
Hello,
sorry for silly question, but how to create color line in SFML2? VertexArray doesn't have setColor method.

Pages: [1]