13 Replies - 5527 Views - Last Post: 03 August 2011 - 06:58 PM Rate Topic: -----

#1 dartoscoder  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 313
  • Joined: 15-May 09

SFML freezing with dynamic + 50+ errors in static

Posted 02 August 2011 - 10:38 PM


#include <Box2D\Box2D.h>
#include <SFML\Graphics.hpp>
#include <SFML\window.hpp>

int main()
{

	sf::RenderWindow game(sf::VideoMode(800, 600, 32), "game");

	sf::Shape box = sf::Shape::Rectangle(0, 0, 2, 2, sf::Color(255,0,0));

	b2Vec2 gravity(0.0f, -10.0f);

	bool doSleep = true;

	b2World world(gravity, doSleep);

	b2BodyDef groundBodyDef;

	groundBodyDef.position.Set(0.0f, -10.0f);

	b2Body* groundBody = world.CreateBody(&groundBodyDef);

	b2PolygonShape groundBox;

	groundBox.SetAsBox(50.0f, 10.0f);

	groundBody->CreateFixture(&groundBox, 0);

	b2BodyDef bodyDef;

	bodyDef.type = b2_dynamicBody;

	bodyDef.position.Set(0.0f, 4.0f);

	b2Body* body = world.CreateBody(&bodyDef);

	b2PolygonShape dynamicBox;

	dynamicBox.SetAsBox(1.0f, 1.0f);

	b2FixtureDef fixtureDef;

	fixtureDef.shape = &dynamicBox;

	fixtureDef.density = 1.0f;

	fixtureDef.friction = 0.3f;

	body->CreateFixture(&fixtureDef);

	float32 timeStep = 1.0f / 60.0f;

	int32 velIter = 6;
	int32 posIter = 2;

	b2Vec2 pos = body->GetPosition();
	float32 an = body->GetAngle();

	box.SetPosition(pos.x, pos.y);
	box.SetRotation(an);

	bool quit = false;

	while(quit == false)
	{
		world.Step(timeStep, velIter, posIter);

		world.ClearForces();

		b2Vec2 pos = body->GetPosition();
		float32 angle = body->GetAngle();

		box.SetPosition(pos.x, pos.y);
		box.SetRotation(angle);

		if(game.GetInput().IsKeyDown(sf::Key::Escape))
		{
		    quit = true;
		}

		game.Clear(sf::Color(0,0,0));
		game.Draw(box);
		game.Display();
	}

	game.Close();

	return EXIT_SUCCESS;

}



so there is my code.
I have been trying to get this thing to work but every time i start it up the renderWindow crashes. the program keeps going but the renderwindow crashes.

I switched it to static by changing SFML_DYNAMIC to SFML_STATIC in the compiler settings and i changes all the linker commands to -libsfml-<whatever goes here>-s

Everything is linked right ( i think)

and if i switch it to static i get 50 + errors.

I am using mingw 4.4.1 on codeblocks.

most of the errors say undefined reference to '_Unwind_Resume'.

and again that only happens in static mode but in dynamic mode it freezes.

thanks a lot,
dartos

Is This A Good Question/Topic? 0
  • +

Replies To: SFML freezing with dynamic + 50+ errors in static

#2 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 768
  • View blog
  • Posts: 2,234
  • Joined: 20-March 10

Re: SFML freezing with dynamic + 50+ errors in static

Posted 03 August 2011 - 01:26 AM

Did you build SFML to use static or dynamic libraries ?

in c::b settings -> compiler and debugger

click on linker settings

in other linker options do you have the following

-lsfml-graphics
-lsfml-window
-lsfml-system

Best Wishes Snoopy.
Was This Post Helpful? 0
  • +
  • -

#3 dartoscoder  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 313
  • Joined: 15-May 09

Re: SFML freezing with dynamic + 50+ errors in static

Posted 03 August 2011 - 06:54 AM

I never built SFML i just used the lib and include folder that came with the mingw package.

To be honest i don't know the difference :hammer:

and should i put those on with the ones that have the -s or -d suffix?

This post has been edited by dartoscoder: 03 August 2011 - 02:45 PM

Was This Post Helpful? 0
  • +
  • -

#4 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 768
  • View blog
  • Posts: 2,234
  • Joined: 20-March 10

Re: SFML freezing with dynamic + 50+ errors in static

Posted 03 August 2011 - 08:25 AM

View Postdartoscoder, on 03 August 2011 - 06:54 AM, said:

should i put those on with the ones that have the -s or -d suffix?

neither

in your code::blocks MinGW folder
goto lib
in there
you should have things like
libsfml-graphics.a
libsfml-graphics-d.a
libsfml-graphics-s.a

its the first one you want to link to for dynamic libraries

so

in c::b settings -> compiler and debugger

click on linker settings

in other linker options you should have have the following

-lsfml-graphics
-lsfml-window
-lsfml-system

this is a sort of minimum for sfml

if you want to use the debug version of the libraries append -d

if you want to use the static libraries append -s

and in c::b -> Settings -> compiler and debugger
compiler settings tab
click on #defines

in there that should be

SFML_STATIC

that is if you really want to use the static libraries

other wise

SFML_DYNAMIC

for the dynamic libraries
like libsfml-graphics.a

Best Wishes Snoopy.
Was This Post Helpful? 1
  • +
  • -

#5 dartoscoder  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 313
  • Joined: 15-May 09

Re: SFML freezing with dynamic + 50+ errors in static

Posted 03 August 2011 - 02:44 PM

I did that. I said i linked it all correcly.

It still freezes.

Il try static and dynamic again.

by the bye, what is the difference

This post has been edited by dartoscoder: 03 August 2011 - 02:44 PM

Was This Post Helpful? 0
  • +
  • -

#6 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 768
  • View blog
  • Posts: 2,234
  • Joined: 20-March 10

Re: SFML freezing with dynamic + 50+ errors in static

Posted 03 August 2011 - 03:23 PM

Have you thought it might be box2d that is the problem ?


can you compile and run this simple sfml example code ?

//sfml test

 #include <SFML/Graphics.hpp>

 int main()
 {
     // Create the main window
     sf::RenderWindow App(sf::VideoMode(800, 600), "SFML window");

     // Load a sprite to display
     sf::Image Image;
     if (!Image.LoadFromFile("cute_image.jpg"))
         return EXIT_FAILURE;
     sf::Sprite Sprite(Image);

     // Create a graphical string to display
     sf::Font Arial;
     if (!Arial.LoadFromFile("arial.ttf"))
         return EXIT_FAILURE;
     sf::String Text("Hello SFML", Arial, 50);




     // Start the game loop
     while (App.IsOpened())
     {
         // Process events
         sf::Event Event;
         while (App.GetEvent(Event))
         {
             // Close window : exit
             if (Event.Type == sf::Event::Closed)
                 App.Close();
         }

         // Clear screen
         App.Clear();

         // Draw the sprite
         App.Draw(Sprite);

         // Draw the string
         App.Draw(Text);

         // Update the window
         App.Display();
     }

     return EXIT_SUCCESS;
 }



Can you tell me what the result of that is

you will have to supply it with an example .jpg

you can find arial.ttf in your Windows fonts folder
just copy it out of there and put it in your project directory

Best Wishes Snoopy.

This post has been edited by snoopy11: 03 August 2011 - 03:25 PM

Was This Post Helpful? 0
  • +
  • -

#7 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 768
  • View blog
  • Posts: 2,234
  • Joined: 20-March 10

Re: SFML freezing with dynamic + 50+ errors in static

Posted 03 August 2011 - 03:45 PM

looking at your box2d code I have some questions

b2Vec2 gravity(0.0f, -10.0f);



should gravity not be positive ?

like

b2Vec2 gravity(0.0f, 10.0f);



and this

b2World world(gravity, doSleep);



should this not be

b2World* world = new b2World(gravity, doSleep);




followed by a call to

delete world;



when your finished with it

I have never used box2d and I am not going to install it just to run your code...

However what I have gleaned from the API docs in the last 5 mins suggests your not using it correctly..

Best Wishes Snoopy.
Was This Post Helpful? 0
  • +
  • -

#8 dartoscoder  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 313
  • Joined: 15-May 09

Re: SFML freezing with dynamic + 50+ errors in static

Posted 03 August 2011 - 03:58 PM

Well If i compile that using static i get a whole bunch of errors.

Same as before with static.

with dynamic it compiled fine it.

But with box2d .... why do you think that is.

could it be that sfml requires the dwarf mingw .dlls?
Was This Post Helpful? 0
  • +
  • -

#9 dartoscoder  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 313
  • Joined: 15-May 09

Re: SFML freezing with dynamic + 50+ errors in static

Posted 03 August 2011 - 04:10 PM

View Postsnoopy11, on 03 August 2011 - 04:45 PM, said:

looking at your box2d code I have some questions

b2Vec2 gravity(0.0f, -10.0f);



should gravity not be positive ?

like

b2Vec2 gravity(0.0f, 10.0f);



and this

b2World world(gravity, doSleep);



should this not be

b2World* world = new b2World(gravity, doSleep);




followed by a call to

delete world;



when your finished with it

I have never used box2d and I am not going to install it just to run your code...

However what I have gleaned from the API docs in the last 5 mins suggests your not using it correctly..

Best Wishes Snoopy.



I took all that code right out of the Hello World prog on the docs.

it worked when it printed the x and y values in the console.

in fact when the render window crashed it still printed the values.

And i tried fixing those odd things and still no dice

This post has been edited by dartoscoder: 03 August 2011 - 04:12 PM

Was This Post Helpful? 0
  • +
  • -

#10 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 768
  • View blog
  • Posts: 2,234
  • Joined: 20-March 10

Re: SFML freezing with dynamic + 50+ errors in static

Posted 03 August 2011 - 04:23 PM

dartoscoder said:

I took all that code right out of the Hello World prog on the docs.

it worked when it printed the x and y values in the console.

in fact when the render window crashed it still printed the values.

And i tried fixing those odd things and still no dice


Oh I see, well i suppose the only option is to build box2d
and run your code..

give me 5 minutes

Snoopy
Was This Post Helpful? 0
  • +
  • -

#11 dartoscoder  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 313
  • Joined: 15-May 09

Re: SFML freezing with dynamic + 50+ errors in static

Posted 03 August 2011 - 04:30 PM

Take your time. Thanks a lot for helping me with this.
Was This Post Helpful? 0
  • +
  • -

#12 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 768
  • View blog
  • Posts: 2,234
  • Joined: 20-March 10

Re: SFML freezing with dynamic + 50+ errors in static

Posted 03 August 2011 - 06:20 PM

Right I managed to get this to run a little

without crashing still not too hot with box2d but

here goes

#include <SFML\Graphics.hpp>
#include <SFML\window.hpp>
#include <SFML\System.hpp>
#include <Box2D\Box2D.h>

#define PTM_RATIO 32.0
int main()
{

    sf::RenderWindow game(sf::VideoMode(800, 600, 32), "game");

    sf::Shape box = sf::Shape::Rectangle(0, 0, 2, 2, sf::Color(255,0,0));

    b2Vec2 gravity(0.0f, 9.8f);

    bool doSleep = true;



    b2World*  world;
    world = new b2World(gravity,doSleep);
    b2BodyDef groundBodyDef;
    groundBodyDef.position.Set(0,0);


    b2Body* Body ;
    b2BodyDef ballBodyDef;
    ballBodyDef.type = b2_dynamicBody;
    ballBodyDef.position.Set(100/PTM_RATIO, 100/PTM_RATIO);
    Body = world->CreateBody(&ballBodyDef);

    b2Body *groundBody = world->CreateBody(&groundBodyDef);

    b2PolygonShape groundBox;
    b2FixtureDef boxShapeDef;
    boxShapeDef.shape = &groundBox;

    groundBox.SetAsBox(50.0f, 10.0f);

    groundBody->CreateFixture(&groundBox, 0);

    b2BodyDef bodyDef;

    bodyDef.type = b2_dynamicBody;

    bodyDef.position.Set(0.0f, 4.0f);



    b2PolygonShape dynamicBox;

    dynamicBox.SetAsBox(1.0f, 1.0f);

    b2FixtureDef fixtureDef;

    fixtureDef.shape = &dynamicBox;

    fixtureDef.density = 1.0f;

    fixtureDef.friction = 0.3f;

    Body->CreateFixture(&fixtureDef);

    float timeStep = 1.0f / 60.0f;

    int velIter = 10;
    int posIter = 10;
    world->Step(timeStep, velIter, posIter);


    b2Vec2 pos = Body->GetPosition();
    float an = Body->GetAngle();

    box.SetPosition(pos.x, pos.y);
    box.SetRotation(an);


bool Running = true;
    while (Running)
    {
        sf::Event Event;

        while (game.GetEvent(Event))
        {
           if (Event.Type == sf::Event::Closed)
           Running = false;


            world->Step(timeStep, velIter, posIter);



            b2Vec2 pos = Body->GetPosition();
            float angle = Body->GetAngle();

            box.SetPosition(pos.x, pos.y);
            box.SetRotation(angle);



            game.Clear();
            game.Draw(box);
        }
        game.Display();
    }

    game.Close();

    return EXIT_SUCCESS;

}





I think what did the trick in the end was enclosing the drawing
inside an sf:Event loop,

The red dot after a while moves down the screen.

but it doesnt crash the render window.

Best wishes Snoopy.

This post has been edited by snoopy11: 03 August 2011 - 06:37 PM

Was This Post Helpful? 1
  • +
  • -

#13 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 768
  • View blog
  • Posts: 2,234
  • Joined: 20-March 10

Re: SFML freezing with dynamic + 50+ errors in static

Posted 03 August 2011 - 06:29 PM

sorry wrong code



#include <SFML\Graphics.hpp>
#include <SFML\window.hpp>
#include <SFML\System.hpp>
#include <Box2D\Box2D.h>

#define PTM_RATIO 32.0
int main()
{

    sf::RenderWindow game(sf::VideoMode(800, 600, 32), "game");

    sf::Shape box = sf::Shape::Rectangle(0, 0, 2, 2, sf::Color(255,0,0));

    b2Vec2 gravity(0.0f, 9.8f);

    bool doSleep = true;



    b2World*  world;
    world = new b2World(gravity,doSleep);
    b2BodyDef groundBodyDef;
    groundBodyDef.position.Set(0,0);


    b2Body* Body ;
    b2BodyDef ballBodyDef;
    ballBodyDef.type = b2_dynamicBody;
    ballBodyDef.position.Set(100/PTM_RATIO, 100/PTM_RATIO);
    Body = world->CreateBody(&ballBodyDef);

    b2Body *groundBody = world->CreateBody(&groundBodyDef);

    b2PolygonShape groundBox;
    b2FixtureDef boxShapeDef;
    boxShapeDef.shape = &groundBox;

    groundBox.SetAsBox(50.0f, 10.0f);

    groundBody->CreateFixture(&groundBox, 0);

    b2BodyDef bodyDef;

    bodyDef.type = b2_dynamicBody;

    bodyDef.position.Set(0.0f, 4.0f);



    b2PolygonShape dynamicBox;

    dynamicBox.SetAsBox(1.0f, 1.0f);

    b2FixtureDef fixtureDef;

    fixtureDef.shape = &dynamicBox;

    fixtureDef.density = 1.0f;

    fixtureDef.friction = 0.3f;

    Body->CreateFixture(&fixtureDef);

    float timeStep = 1.0f / 200.0f;

    int velIter = 0.1;
    int posIter = 0.3;
    world->Step(timeStep, velIter, posIter);


    b2Vec2 pos = Body->GetPosition();
    float an = Body->GetAngle();

    box.SetPosition(pos.x, pos.y);
    box.SetRotation(an);


bool Running = true;
    while (Running)
    {
        sf::Event Event;

        while (game.GetEvent(Event))
        {
           if (Event.Type == sf::Event::Closed)
           Running = false;
        }

            world->Step(timeStep, velIter, posIter);



            b2Vec2 pos = Body->GetPosition();
            float angle = Body->GetAngle();

            box.SetPosition(pos.x, pos.y);
            box.SetRotation(angle);



            game.Clear();
            game.Draw(box);

        game.Display();
    }

    game.Close();

    return EXIT_SUCCESS;

}





Snoopy.
Was This Post Helpful? 1
  • +
  • -

#14 dartoscoder  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 313
  • Joined: 15-May 09

Re: SFML freezing with dynamic + 50+ errors in static

Posted 03 August 2011 - 06:58 PM

WOOOOT!!! :bananaman: :bananaman: :bananaman: :bananaman:

thank you so much I cant thank you enough.
Was This Post Helpful? 0
  • +
  • -

#15 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 768
  • View blog
  • Posts: 2,234
  • Joined: 20-March 10

Re: SFML freezing with dynamic + 50+ errors in static

Posted 03 August 2011 - 11:00 PM

Ah, thats ok I enjoyed doing this one...

Good Luck

Snoopy.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1