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

Author Topic: Problem in release mode  (Read 3352 times)

0 Members and 1 Guest are viewing this topic.

arthur08

  • Newbie
  • *
  • Posts: 8
    • View Profile
Problem in release mode
« on: May 25, 2014, 03:08:11 pm »
Hello everyone,

I am having a weird problem: i made a game where you play as a moving turret and you need to shoot randomly spawning enemies and everything works in debug mode but in release mode, there is one problem, i cannot shoot. It should shoot when there is a Mouse::Released event.
Can someone help me with this?

Using MinGW and netbeans

sorry for my bad english

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Problem in release mode
« Reply #1 on: May 25, 2014, 03:43:46 pm »
Usually, differences between release/debug mode may result of wrong configurations (linked libraries) or initializations that are not performed.

To help you further: read before posting
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

arthur08

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Problem in release mode
« Reply #2 on: May 25, 2014, 08:06:33 pm »
Ok, checked my debug/release confguration, read the post, tried some things but it's still not working
Here is some info :
OS: Windows 8.1
Graphics card: NVIDIA GeForce GTX 670
SFML version: latest snapshot(i have compiled it)
Compiler: GCC(MinGW) 4.8.1

Note: the application doesn't crash, i just cannot shoot bullets in release mode, while i can in debug mode

The basic bullet code
#include <SFML/Graphics.hpp>
#include <list>

std::list<Bullet> bullets;
sf::Sprite sprite; //player-sprite

sf::RenderWindow window(sf::VideoMode(1200, 800), "Test", sf::Style::Titlebar | sf::Style::Close);

int main()
{


    while (window.isOpen())
    {

        sf::Event event;
        while (window.pollEvent(event))
        {


            switch (event.type)
            {

                case sf::Event::Closed:
                    window.close();
                    break;
                case sf::Event::MouseButtonReleased:
                    fire();
                    break;
            }


        }

        draw();
    }

}

void fire()
{

    sf::Vector2i mouse_pos = sf::Mouse::getPosition(window);
    sf::Vector2f curPos = sprite.getPosition();
    float angle = atan2(mouse_pos.y - curPos.y, mouse_pos.x - curPos.x) * (180 / PI);
    Bullet bullet(curPos, angle, 800.0f, 300.0f); //start-position, angle, start-speed, acceleration
    bullet.sprite.setFillColor(sf::Color::Red);

    bullets.push_back(bullet);

}

void draw()
{


    for (Bullet bullet : bullets)
    {

        bullet.Update(time);
        window->draw(bullet.sprite);


    }


}
 
« Last Edit: May 25, 2014, 08:10:43 pm by arthur08 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: Problem in release mode
« Reply #3 on: May 25, 2014, 08:15:20 pm »
It might just be too fast thus it flies out of the screen view before it gets drawn.
Make your movement depending on the refresh rate or implement fixed time steps (google for more info).

In any case you could output positiin values to see where the billet is.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

arthur08

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Problem in release mode
« Reply #4 on: May 25, 2014, 08:18:10 pm »
Ok thanks, but in my bullet class i multiply the speed with the elapsed time from the last frame in seconds, will try outputting position

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Problem in release mode
« Reply #5 on: May 25, 2014, 08:46:52 pm »
...
    for (Bullet bullet : bullets)
...
Don't you want a reference to the original Bullet here to update rather than a copy?
That is "for (Bullet& bullet : bullets)" or "for (auto& bullet : bullets)".
« Last Edit: May 25, 2014, 08:50:07 pm by Jesper Juhl »

arthur08

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Problem in release mode
« Reply #6 on: May 25, 2014, 08:52:29 pm »
Ok i tried that but still not working, when i output the bullets position to the console, it seems that it only updates once in release mode while it stays updating in debug mode

arthur08

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Problem in release mode
« Reply #7 on: May 25, 2014, 09:20:29 pm »
Now i found this: my bullet moves way faster in release mode then in debug mode, so that it directly leaves the window and gets deleted out of the list. How is this possible???

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Problem in release mode
« Reply #8 on: May 25, 2014, 09:23:47 pm »
How is this possible???
What do you think does Debug mode do? ;)

The number of assertions and checks for debugging purposes don't come for free, they slow down your program. You should find an approach that doesn't rely on the real time, but rather a fixed time step that leads to deterministic and thus reproducible behavior.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Problem in release mode
« Reply #9 on: May 25, 2014, 09:26:21 pm »
Of course things run faster in release mode - that's the whole point. Just like it'll run faster on some computers than others you must deal with this.
Sounds like you are not properly taking the time per frame into account.
I think this thread, and the links mentioned in it, will be helpful to you: http://en.sfml-dev.org/forums/index.php?topic=15175.msg107603#msg107603

Edit: as Nexus said, in debug mode you have assertions and all kinds of other checks enabled that slow you down. But you also don't have the optimizer of the compiler kick in (at least not in any meaningful way). Once all the debug checks go away and the optimizer gets to do its job you'll see orders of magnitude increases in speed.
« Last Edit: May 25, 2014, 09:30:13 pm by Jesper Juhl »

arthur08

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Problem in release mode
« Reply #10 on: May 27, 2014, 05:33:34 pm »
And the problem disappeared...
Anyways, thanks for your help
And when moving i do: speed * time.asSeconds () so shouldn't the movement in release mode be as fast as in debug mode?

 

anything