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

Author Topic: Weird error when dealing with Clock and Time  (Read 2031 times)

0 Members and 1 Guest are viewing this topic.

ggggggggggggggg

  • Newbie
  • *
  • Posts: 36
    • View Profile
    • Email
Weird error when dealing with Clock and Time
« on: April 16, 2013, 04:38:02 am »
When the value of shoot speed is assigned to 0 - 3, the program exits without an error. However, with a value more than 3, this lovely error comes up - "Unhandled exception at 0x770015de in Practice  SFML.exe: 0xC0000005: Access violation reading location 0xfeeefef6."

Here's the two functions that use these variables.

Turent::Init-
void Turent::Init()
{
        sprite.setPosition(400, 300);
        sprite.setTexture(textureManager.turent);
        sprite.setOrigin(sprite.getGlobalBounds().width / 2, sprite.getGlobalBounds().height / 2);
        InScreen.setSize(sf::Vector2f(1024, 768));
        shootSpeed = sf::milliseconds(100); //line where I change the value
}

Turent::Shoot-
void Turent::Shoot(sf::RenderWindow& Window)
{
        if(shootClock.getElapsedTime().asSeconds() > shootSpeed.asSeconds() && sf::Mouse::isButtonPressed(sf::Mouse::Left)) //line where it's used
        {
                Bullet blt;
                blt.Setup(sprite.getPosition().x, sprite.getPosition().y, rotation + 90, sf::Mouse::getPosition(Window).x, sf::Mouse::getPosition(Window).y);
                bullets.push_back(blt);
                shootClock.restart();
        }
}
 

Note these were working perfectly until it stopped.
« Last Edit: April 16, 2013, 04:39:33 am by asusralis »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Weird error when dealing with Clock and Time
« Reply #1 on: April 16, 2013, 07:45:06 am »
You're accessing freed memory. That's all I can say, so use your debugger to find out more.
Laurent Gomila - SFML developer

ggggggggggggggg

  • Newbie
  • *
  • Posts: 36
    • View Profile
    • Email
Re: Weird error when dealing with Clock and Time
« Reply #2 on: April 16, 2013, 09:53:47 pm »
I don't see how. In my header file I have
sf::Clock shootClock;
and in my .cpp file I have
if(shootClock.getElapsedTime().asSeconds() > 1 && sf::Mouse::isButtonPressed(sf::Mouse::Left))
        {
                Bullet bullet;
                bullet.Setup(sprite.getPosition().x, sprite.getPosition().y, rotation + 90, sf::Mouse::getPosition(Window).x, sf::Mouse::getPosition(Window).y);
                bullets.push_back(bullet);
                shootClock.restart();
        }

It only gives an error with this
shootClock.getElapsedTime().asSeconds() > 1

When I comment it out the turent shoots super fast but it shuts down right.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Weird error when dealing with Clock and Time
« Reply #3 on: April 16, 2013, 10:08:39 pm »
Quote
I don't see how
That's why debuggers exist...
Laurent Gomila - SFML developer

ggggggggggggggg

  • Newbie
  • *
  • Posts: 36
    • View Profile
    • Email
Re: Weird error when dealing with Clock and Time
« Reply #4 on: April 16, 2013, 10:17:11 pm »
Right. Ok, thanks.

ggggggggggggggg

  • Newbie
  • *
  • Posts: 36
    • View Profile
    • Email
Re: Weird error when dealing with Clock and Time
« Reply #5 on: April 16, 2013, 10:25:24 pm »
So I found out why.. I guess. I don't see how this would be even related, but I guess it was.

In my main I had an FPS counter.. For some reason it only gave an error when another clock in another file was used.. Is that normal? They didn't touch each other at all.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Weird error when dealing with Clock and Time
« Reply #6 on: April 17, 2013, 08:00:05 am »
Seriously, what's wrong with the debugger? It will show you exactly where the application crashes. Don't waste your time like this.
Laurent Gomila - SFML developer

 

anything