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

Author Topic: Assertion failed in running thor animation example  (Read 3352 times)

0 Members and 1 Guest are viewing this topic.

rojan_neo

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://makeagame.tumblr.com
Assertion failed in running thor animation example
« on: November 20, 2013, 05:12:53 pm »
I am Trying to run thor::animation example that was provided with the download but i am getting a strange error. It says:
 Assertion Failed: !mFrames.empty() in FrameAnimation.hpp line 115.

It Seems that the frames are not being added to mFrames but I don't know how that could happen.


The part of code where I am getting this error:
void FrameAnimation::operator() (Animated& target, float progress) const
{
        assert(!mFrames.empty());
        assert(progress >= 0.f && progress <= 1.f);

        ensureNormalized();
        AURORA_FOREACH(const detail::Frame& frame, mFrames)
        {
                progress -= frame.duration;
               
                if (progress < 0.f)
                {
                        target.setTextureRect(frame.subrect);
                        break;
                }
        }
}
 

The code is same as in example file

#include <Thor/Animation.hpp>
#include <SFML/Graphics.hpp>

// Adds a range of frames, assuming they are aligned as rectangles in the texture.
// animation:      FrameAnimation to modify
// x:              Column index of the texture rectangle
// [yFirst,yLast]: Bounds for row indices (if yLast < yFirst, add frames in reverse order)
// duration:       Relative duration of current frame (1 by default)
void addFrames(thor::FrameAnimation& animation, int x, int yFirst, int yLast, float duration = 1.f)
{
        const int step = (yFirst < yLast) ? +1 : -1;
        yLast += step; // so yLast is excluded in the range

        for (int y = yFirst; y != yLast; y += step)
                animation.addFrame(duration, sf::IntRect(36*x, 39*y, 36, 39));
}

int main()
{
        sf::RenderWindow window(sf::VideoMode(300, 200), "Thor Animation");
        window.setVerticalSyncEnabled(true);
        window.setKeyRepeatEnabled(false);

        sf::Font font;
        if (!font.loadFromFile("../data/fonts/Primitive.ttf"))
                return 1;

        // Instruction text
        sf::Text instructions(
                "W:     Play walk animation (loop)\n"
                "A:      Play attack animation\n"
                "S:      Stop current animation\n"
                "Esc:  Quit",
                font, 12);

        sf::Text animationText("", font, 12);
        animationText.setPosition(100.f, 150.f);

        // Load image that contains animation steps
        sf::Image image;
        if (!image.loadFromFile("../data/graphics/animation.png"))
                return 1;
        image.createMaskFromColor(sf::Color::White);

        // Create texture based on sf::Image
        sf::Texture texture;
        if (!texture.loadFromImage(image))
                return 1;

        // Create sprite which is animated
        sf::Sprite sprite(texture);
        sprite.setPosition(100.f, 100.f);

        // Define walk animation
        thor::FrameAnimation walk;
        addFrames(walk, 0, 0, 7);                       // Frames 0..7  Right leg moves forward
        addFrames(walk, 0, 6, 0);                       // Frames 6..0  Right leg moves backward

        // Define attack animation
        thor::FrameAnimation attack;
        addFrames(attack, 1, 0, 3);                     // Frames 0..3  Lift gun
        addFrames(attack, 1, 4, 4, 5.f);        // Frame  4             Aim (5 times normal frame duration)
        for (int i = 0; i < 3; ++i)
                addFrames(attack, 1, 5, 7);             // Frame  5..7  Fire (repeat 3 times)
        addFrames(attack, 1, 4, 4, 5.f);        // Frame  4             Wait
        addFrames(attack, 1, 3, 0);                     // Frame  3..1  Lower gun

        // Define static frame for stand animation
        thor::FrameAnimation stand;
        addFrames(stand, 0, 0, 0);

        // Register animations with their corresponding durations
        thor::Animator<sf::Sprite, std::string> animator;
        animator.addAnimation("walk", walk, sf::seconds(1.f));
        animator.addAnimation("stand", stand, sf::seconds(1.f));
        animator.addAnimation("attack", attack, sf::seconds(1.f));

        // Create clock to measure frame time
        sf::Clock frameClock;

        // Main loop
        for (;;)
        {
                // Handle events
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::KeyPressed)
                        {
                                switch (event.key.code)
                                {
                                        case sf::Keyboard::W:           animator.playAnimation("walk", true);                   break;
                                        case sf::Keyboard::A:           animator.playAnimation("attack");                               break;
                                        case sf::Keyboard::S:           animator.stopAnimation();                                               break;
                                        case sf::Keyboard::Escape:      return 0;
                                }
                        }
                        else if (event.type == sf::Event::Closed)
                        {
                                return 0;
                        }
                }

                // If no other animation is playing, play stand animation
                if (!animator.isPlayingAnimation())
                        animator.playAnimation("stand");

                // Output playing animation (general case; at the moment an animation is always playing)
                if (animator.isPlayingAnimation())
                        animationText.setString("Animation: " + animator.getPlayingAnimation());
                else
                        animationText.setString("");

                // Update animator and apply current animation state to the sprite
                animator.update(frameClock.restart());
                animator.animate(sprite);

                // Draw everything
                window.clear(sf::Color(50, 50, 50));
                window.draw(instructions);
                window.draw(animationText);
                window.draw(sprite);
                window.display();
        }      
}
 

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Assertion failed in running thor animation example
« Reply #1 on: November 20, 2013, 05:46:28 pm »
Strange... I can't reproduce it. What's your compiler and OS?

Does it work if you build the examples directly with CMake (enable the THOR_BUILD_EXAMPLES option) and don't change the code at all? Are you sure everything is linked and set up correctly?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

rojan_neo

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://makeagame.tumblr.com
Re: Assertion failed in running thor animation example
« Reply #2 on: November 20, 2013, 06:02:19 pm »
I am using visual studio 2010. I am not sure if every thing is linked or not.. Other aspect of the library like resource management and Inputs are working fine but animation is not. I also cannot seem to find the function description for the AddFrame function.. can you tell me where it is located... Maybe I am missing some files...

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Assertion failed in running thor animation example
« Reply #3 on: November 20, 2013, 11:54:30 pm »
I am not sure if every thing is linked or not..
Then follow the installation tutorial exactly and make sure you don't miss any step.

I also cannot seem to find the function description for the AddFrame function.. can you tell me where it is located...
Use the documentation: thor::FrameAnimation

As already asked, what happens if you build Thor with CMake, including the examples (that is, do not modify a single line in any source code)? Does the animation then work correctly?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

rojan_neo

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://makeagame.tumblr.com
Re: Assertion failed in running thor animation example
« Reply #4 on: November 21, 2013, 02:34:14 am »
That seems to do the trick. Although I still can't figure out what the problem was.. because I did the exact same steps before   ;D

 

anything