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

Pages: [1]
1
Window / Zero division issue and empty window
« on: October 05, 2012, 08:46:55 pm »
Hello everybody!
I recently came across this amazing library which I will use for my new 2D game.

I have got two issues, both of them regarding this little program:
#include <SFML/Graphics.hpp>
#include <string>
#include <sstream>
#include <math.h>
#include <stdlib.h>
#include <time.h>

long double angle = 0;
int rectPos = 0;

int main()
{
        sf::RenderWindow window(sf::VideoMode(1280, 780), "SFML works!");

        sf::CircleShape circle(150, 200);
        circle.setOutlineColor(sf::Color(0, 0, 255, 255));
        circle.setOutlineThickness(2);
        circle.setFillColor(sf::Color(0, 0, 0, 0));
        circle.setPosition(sf::Vector2f(5, 5));

        sf::RectangleShape rect(sf::Vector2f(50.0, 10.0));
        rect.setFillColor(sf::Color(255, 0, 0, 255));
        rect.setPosition(sf::Vector2f(0, 350));

        sf::Text text;
        text.setPosition(sf::Vector2f(10, 400));

        sf::Clock clock;

        int cycle = 0;
        float rt = 0;

        sf::String fpsStr;

        //window.setFramerateLimit(60);

        while (window.isOpen())
        {
                sf::Time time = clock.restart();
                rt += time.asMilliseconds();
               
                if (++cycle == 100)
                {
                        cycle = 0;
                        std::stringstream wss;
                        wss << "Frame rendering time (avg. of 100 frames): ";
                        wss << rt / 100;
                        rt = 0;
                        fpsStr.clear();
                        fpsStr.insert(0, sf::String(wss.str()));
                }

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

                window.clear();

                // drawing!

                window.draw(circle);

                angle += 0.02;

                sf::Vertex vertices[] =
                {
                        sf::Vertex(sf::Vector2f(155.0, 155.0), sf::Color::Red),
                        sf::Vertex(sf::Vector2f((int)(150.0 + cos(angle) * 150.0) + 5, (int)(150.0 - sin(angle) * 150.0) + 5), sf::Color::Red)
                };

                window.draw(vertices, 2, sf::PrimitiveType::Lines);
               
                rectPos++;
               
                if (rectPos > (int)window.getSize().x) rectPos = -50;
                rect.setPosition(sf::Vector2f((float)rectPos, 350));
                window.draw(rect);

                text.setString(fpsStr);
                window.draw(text);

                unsigned int random = rand() % 100 + 100;

                for (int i = 0; i < random; i++)
                {
                        sf::CircleShape tmpCircle(rand() % 20 + 10);
                        tmpCircle.setFillColor(sf::Color(rand() % 256, rand() % 256, rand() % 256, rand() % 256));
                        tmpCircle.setOutlineColor(sf::Color(rand() % 256, rand() % 256, rand() % 256, rand() % 256));
                        tmpCircle.setPosition(sf::Vector2f(rand() % (int)window.getSize().x, rand() % (int)window.getSize().y));
                        window.draw(tmpCircle);
                }

                // end drawing!

                window.display();
        }

        return 0;
}
 

The first issue is that when I exit the program I get a zero division exception (if I'm attached to Visual Studio's debugger) or the classic crash report window, if I'm running a Release build.

The second issue is that, when I sent my program (statically linked with SFML libraries, built with Release profile) to a friend, when he tries to open it, it can see two windows on the taskbar: one for the console, which shows normally, and one for the window that should be the RenderWindow... But it is like "invisible", it exists in the taskbar but there's no way to see it :(

Pages: [1]