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.


Topics - Romex

Pages: [1]
1
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?

2
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 :)

3
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.

4
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]