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

Pages: [1]
1
General / Re: Unresolved External Symbols
« on: October 06, 2016, 04:44:41 pm »
Instead of linking sfml-main.lib I had set main as the entry point which caused all the linker errors. Thanks for the help.

2
General / Re: This error appears...
« on: October 02, 2016, 10:15:00 pm »
I got the same error earlier because I had accidentally downloaded the 64bit version. If you're targeting for 32bit you need to get the 32bit version.

3
General / Unresolved External Symbols
« on: October 02, 2016, 09:49:14 pm »
Trying to set up SFML on a new PC. I've used it successfully in the past but this time it's not working. All I did was follow the tutorial using the 32bit download on MSVS14.0. There are more errors when building debug than building for release.

Severity   Code   Description   Project   File   Line   Suppression State
Error   LNK2019   unresolved external symbol ___CxxFrameHandler3 referenced in function __ehhandler$??0locale@std@@QAE@XZ   SFMLProject1   c:\Users\Greg\documents\visual studio 2015\Projects\SFMLProject1\SFMLProject1\main.obj   1   
Error   LNK2019   unresolved external symbol __CrtDbgReport referenced in function __CRT_RTC_INIT   SFMLProject1   c:\Users\Greg\documents\visual studio 2015\Projects\SFMLProject1\SFMLProject1\MSVCRTD.lib(_init_.obj)   1   
Error   LNK2019   unresolved external symbol __CrtDbgReportW referenced in function __CRT_RTC_INITW   SFMLProject1   c:\Users\Greg\documents\visual studio 2015\Projects\SFMLProject1\SFMLProject1\MSVCRTD.lib(_init_.obj)   1   
Error   LNK2019   unresolved external symbol ___stdio_common_vsprintf_s referenced in function __vsprintf_s_l   SFMLProject1   c:\Users\Greg\documents\visual studio 2015\Projects\SFMLProject1\SFMLProject1\MSVCRTD.lib(_error_.obj)   1   
Error   LNK2019   unresolved external symbol __wmakepath_s referenced in function "int __cdecl GetPdbDllPathFromFilePath(wchar_t const *,wchar_t *,unsigned int)" (?GetPdbDllPathFromFilePath@@YAHPB_WPA_WI@Z)   SFMLProject1   c:\Users\Greg\documents\visual studio 2015\Projects\SFMLProject1\SFMLProject1\MSVCRTD.lib(_pdblkup_.obj)   1   
Error   LNK2019   unresolved external symbol __wsplitpath_s referenced in function "int __cdecl GetPdbDllPathFromFilePath(wchar_t const *,wchar_t *,unsigned int)" (?GetPdbDllPathFromFilePath@@YAHPB_WPA_WI@Z)   SFMLProject1   c:\Users\Greg\documents\visual studio 2015\Projects\SFMLProject1\SFMLProject1\MSVCRTD.lib(_pdblkup_.obj)   1   
Error   LNK2019   unresolved external symbol _wcscpy_s referenced in function "int __cdecl GetPdbDllPathFromFilePath(wchar_t const *,wchar_t *,unsigned int)" (?GetPdbDllPathFromFilePath@@YAHPB_WPA_WI@Z)   SFMLProject1   c:\Users\Greg\documents\visual studio 2015\Projects\SFMLProject1\SFMLProject1\MSVCRTD.lib(_pdblkup_.obj)   1   
Error   LNK2019   unresolved external symbol ___vcrt_GetModuleFileNameW referenced in function "struct HINSTANCE__ * __cdecl GetPdbDll(void)" (?GetPdbDll@@YAPAUHINSTANCE__@@XZ)   SFMLProject1   c:\Users\Greg\documents\visual studio 2015\Projects\SFMLProject1\SFMLProject1\MSVCRTD.lib(_pdblkup_.obj)   1   
Error   LNK2019   unresolved external symbol ___vcrt_GetModuleHandleW referenced in function "struct HINSTANCE__ * __cdecl GetPdbDll(void)" (?GetPdbDll@@YAPAUHINSTANCE__@@XZ)   SFMLProject1   c:\Users\Greg\documents\visual studio 2015\Projects\SFMLProject1\SFMLProject1\MSVCRTD.lib(_pdblkup_.obj)   1   
Error   LNK2019   unresolved external symbol ___vcrt_LoadLibraryExW referenced in function "struct HINSTANCE__ * __cdecl GetPdbDll(void)" (?GetPdbDll@@YAPAUHINSTANCE__@@XZ)   SFMLProject1   c:\Users\Greg\documents\visual studio 2015\Projects\SFMLProject1\SFMLProject1\MSVCRTD.lib(_pdblkup_.obj)   1   
Error   LNK2019   unresolved external symbol __except_handler4_common referenced in function __except_handler4   SFMLProject1   c:\Users\Greg\documents\visual studio 2015\Projects\SFMLProject1\SFMLProject1\MSVCRTD.lib(_chandler4gs_.obj)   1   


Only the following for release:
Severity   Code   Description   Project   File   Line   Suppression State
Error   LNK2001   unresolved external symbol ___std_terminate   SFMLProject1   c:\Users\Greg\documents\visual studio 2015\Projects\SFMLProject1\SFMLProject1\main.obj   1   

These are the additional dependencies:
sfml-graphics.lib;sfml-window.lib;sfml-audio.lib;sfml-network.lib;sfml-system.lib;opengl32.lib;freetype.lib;jpeg.lib;winmm.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;ws2_32.lib;

I've checked the input & lib directories. The code is copied & pasted from the tutorial. I've started again from scratch multiple times. So, I've tried everything I can think of. Help would be appreciated!

4
General / Re: Can't get animation to work
« on: August 31, 2013, 02:53:42 pm »
I'm suprised your code doesn't crash instantly...
I think the problem is that your texture and the animation go out of scope at the end of your activate method. AnimatedSprite only takes references to both the texture and the animation, so both have to stay alive for as long as you want to use the AnimatedSprite. This behavior is similar to sf::Sprite. There is also a notice on the wiki page explaining this...
So the easiest fix would be to make texture and animation members of your class.
Thanks, unfortunately the wiki is down at the moment, but I made texture and animation both members of the class, and now the animation works :)  I noticed that, in your Animated Sprite class, you declare a "setFrameTime" function in the header file, but never define it in the source file.  As I used this function, it caused a linker error, so I added it in:
void AnimatedSprite::setFrameTime(sf::Time time)
{
        m_frameTime = time;
}
Also, on first build several warnings were generated.  Although warnings don't really matter, they are annoying.  This was simply a case of modifying the following line:
explicit AnimatedSprite(sf::Time frameTime = sf::seconds(0.2f), bool paused = false, bool looped = true);
As you can see, I typed an "f" after "0.2", which makes it a float and not a double.  Similarly:
float left = static_cast<float>(rect.left) + 0.0001f;
0.0001 suggested a double without an "f" on the end.
Also these following lines:
m_vertices[1].position = sf::Vector2f(0, (float)rect.height);
m_vertices[2].position = sf::Vector2f((float)rect.width, (float)rect.height);
m_vertices[3].position = sf::Vector2f((float)rect.width, 0);
"rect.width" and "rect.height" return ints, so they should be casted to floats to show that you mean to convert them.  Anyway, thanks for the class :D

5
General / Re: Can't get animation to work
« on: August 31, 2013, 09:25:22 am »
I am always happy to see my class being useful and to see it in action.
Please post a complet and minimal code of what is not working. Without that I can't help you…
Have you checked the return value of loadFromFile?
I made a simple animation test project using your class and the same sprite sheet, and it works, but trying to use it in my game does not work.  Running the game results of one of 3 results:
1)
Quote
Unhandled exception at 0x003013EF in Game.exe: 0xC0000005: Access violation reading location 0x0000004F.
It points to this line in AnimatedSprite.cpp, in the setFrame function:
sf::IntRect rect = m_animation->getFrame(m_currentFrame);

2)
Quote
Unhandled exception at 0x590765CE (sfml-graphics-2.dll) in Game.exe: 0xC0000094: Integer division by zero.
It points to this line in AnimatedSprite.cpp, in the draw function:
target.draw(m_vertices, 4, sf::Quads, states);

3) The screen flashes black and white, occasionally settling at black.

These results happen randomly, with 3) being the most common.

This is the file that implements the animation:
#include "PlayState.h"
#include "resources.h"

;PlayState PlayState::instance;

void PlayState::activate()
{      
        sf::Texture texture;
        if (!texture.loadFromFile(FILE_PLAYER))
                throw std::runtime_error("Could not open " + FILE_PLAYER);

        Animation animation;
        animation.setSpriteSheet(texture);

        for (int i = 0; i < 8; ++i)
        {
                animation.addFrame(sf::IntRect(i * 16, 0, 16, 48));
        }

        player = AnimatedSprite(sf::milliseconds(30));
        player.setAnimation(animation);
}

void PlayState::input()
{

}

void PlayState::update(sf::Time delta)
{
        player.update(delta);
}

void PlayState::render(sf::RenderWindow &window)
{
        window.draw(player);
}

void PlayState::deactivate()
{
       
}
 

I can't understand how it would work in the test, but not here :O
Just in case, here's the code I used to test it:
#include <SFML/Graphics.hpp>
#include "AnimatedSprite.h"

int main()
{
        sf::RenderWindow window(sf::VideoMode(800, 600), "Animation Test");
       
        sf::Texture texture;
        if (!texture.loadFromFile("spritesheet.png"))
                return 1;

        Animation animation;
        animation.setSpriteSheet(texture);
       
        for (int i = 0; i < 8; ++i)
        {
                animation.addFrame(sf::IntRect(i * 16, 0, 16, 48));
        }

        AnimatedSprite sprite(sf::milliseconds(100));
        sprite.setAnimation(animation);

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

                sprite.update(clock.restart());

                window.clear();
                window.draw(sprite);
                window.display();
        }

        return 0;
}
 

6
General / Re: Can't get animation to work
« on: August 30, 2013, 09:18:54 pm »
I also wrote an animation class. It's free and on the wiki. If you want you can use it directly or as a inspiration if you want.

I also noticed something weird in your code. In the constructor of Animtion you set currentFrame to -1 and then you set the texture to the first element in the texture vector. In the update() method you increment the currentFrame variable (in this case to 0) and then you set the texture to the vector element with that index. So in the first run you see the first frame twice.

And like Gobbles said you should look into spritesheets (i.e. having all frames of one animation in a single file), because texture switching is a costly operation on the GPU.

edit: Also another important thing: sizeof does NOT return the number of element in an array!!! (In your case you actually fill the vector with 192 textures!!!) It shows how much memory the given variable or type uses in byte. There is a way to determin the number of elements (sizeof(FILE_PLAYER) / sizeof(FILE_PLAYER[0])), but this is C style and you should really rethink the way you load the textures... (for example the return value of loadFromFile isn't checked either...)
Ah, thanks.  If I replace sizeof(frames) with 8 (which is how many frames I actually have), the animation fully loops.  I will definitely switch to using a spritesheet though, and I might use your animation class, at least for now :)

edit: I tried to use your class, but it doesn't work :(  The game just instantly crashes.
Code: [Select]
sf::Texture texture;
texture.loadFromFile(FILE_PLAYER);

Animation animation;
animation.setSpriteSheet(texture);
for (int i = 0; i < 8; ++i)
{
int width = 16;
int height = texture.getSize().y;
animation.addFrame(sf::IntRect(width * i, 0, width, height));
}

player = new AnimatedSprite(sf::milliseconds(30));
player->setAnimation(animation);

7
General / Re: Can't get animation to work
« on: August 30, 2013, 07:44:23 pm »
It animates now, thanks for spotting that mistake.  The bad news is, only 4 frames actually show, then it returns to the starting frame.  Any idea why this might happen?

8
General / Can't get animation to work
« on: August 30, 2013, 05:49:52 pm »
I wrote an animation class which inherits the sf::Sprite class.  But it only displays the first frame of the animation.  It's probably something small I've missed, but I can't figure out why it doesn't work.

Animation.h
#pragma once
#include <SFML/Graphics.hpp>

class Animation : public sf::Sprite
{
private:
        std::vector<sf::Texture> frames;
        sf::Time frameTime;
        int currentFrame;
        sf::Time time;
        bool playing;

public:
        Animation(const std::string frames[], sf::Time frameTime);

        void play();
        void pause();
        int getWidth();
        int getHeight();
        void flipX();
        void flipY();

        void update(sf::Time delta);
};
 
Animation.cpp
#include "Animation.h"

Animation::Animation(const std::string frames[], sf::Time frameTime) : frameTime(frameTime),
                                                                                                                                           currentFrame(-1),
                                                                                                                                           time(sf::Time::Zero),
                                                                                                                                           playing(false)
{
        for (int i = 0; i < sizeof(frames); ++i)
        {
                sf::Texture texture;
                texture.loadFromFile(frames[i]);

                this->frames.push_back(texture);
        }

        setTexture(this->frames.at(0));
}

void Animation::play()
{
        playing = true;
}

void Animation::pause()
{
        playing = false;
}

int Animation::getWidth()
{
        return getTexture()->getSize().x;
}

int Animation::getHeight()
{
        return getTexture()->getSize().y;
}

void Animation::flipX()
{
        setTextureRect(sf::IntRect(getWidth(), 0, -getWidth(), getHeight()));
}

void Animation::flipY()
{
        setTextureRect(sf::IntRect(getWidth(), 0, getWidth(), -getHeight()));
}

void Animation::update(sf::Time delta)
{
        if (playing)
        {
                time += delta;

                if (time >= frameTime)
                {
                        time = sf::Time::Zero;
                        currentFrame ++;

                        if (currentFrame = frames.size())
                                currentFrame = 0;

                        setTexture(frames.at(currentFrame));
                }
        }
}
 
PlayState.cpp (The class that uses the animation)
#include "PlayState.h"
#include "resources.h"

;PlayState PlayState::instance;

void PlayState::activate()
{
        player = new Animation(FILE_PLAYER, sf::milliseconds(30));
        player->play();
}

void PlayState::input()
{

}

void PlayState::update(sf::Time delta)
{
        player->update(delta);
}

void PlayState::render(sf::RenderWindow &window)
{
        window.draw(*player);
}

void PlayState::deactivate()
{
        delete player;
}
 
FILE_PLAYER is defined as the following
const std::string FILE_PLAYER[8] = { "data/player/player_01.png", "data/player/player_02.png", "data/player/player_03.png", "data/player/player_04.png",
                                                                         "data/player/player_05.png", "data/player/player_06.png", "data/player/player_07.png", "data/player/player_08.png" };
 

Any help is appreciated :)

Pages: [1]