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

Author Topic: Standalone header Graphics/Sprite.hpp doesn't compile  (Read 2787 times)

0 Members and 1 Guest are viewing this topic.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Standalone header Graphics/Sprite.hpp doesn't compile
« on: June 14, 2011, 12:06:15 pm »
The famous minimal and complete example:
Code: [Select]
#include <SFML/Graphics/Sprite.hpp>

int main()
{
sf::Sprite s;
}

Error: You use the incomplete type sf::Image at line 60 of System/ResourcePtr.inl:
Code: [Select]
template <typename T>
ResourcePtr<T>::~ResourcePtr()
{
    if (myResource)
        myResource->Disconnect(*this); // <--
}

The problem is, sf::Sprite has no user-defined destructor, therefore the compiler generates one in the class definition. This leads to the instantiation of the function ResourcePtr<Image>::~ResourcePtr() inside Sprite.hpp, which requires the definition of sf::Image.

The other resource frontends (sf::Text, sf::Sound) work, although you didn't include the resource classes (sf::Font, sf::SoundBuffer). The solution is to declare a destructor in Sprite.hpp and to provide an empty implementation in Sprite.cpp.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Standalone header Graphics/Sprite.hpp doesn't compile
« Reply #1 on: June 16, 2011, 12:41:18 pm »
Looks like this thread got lost... ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Standalone header Graphics/Sprite.hpp doesn't compile
« Reply #2 on: June 16, 2011, 02:38:52 pm »
Sorry for not answering. It's not lost don't worry, it's on my task list so it won't be forgotten until it's fixed.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Standalone header Graphics/Sprite.hpp doesn't compile
« Reply #3 on: June 16, 2011, 03:00:16 pm »
Ah okay. Since you usually answer fast, I thought you might not have seen it ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

short

  • Newbie
  • *
  • Posts: 9
    • View Profile
Standalone header Graphics/Sprite.hpp doesn't compile
« Reply #4 on: September 16, 2011, 04:03:11 am »
I can't seem to get this fix to work.

In sprite.hpp I defined the destructor (right below the constructor) public, ie:

Code: [Select]
class SFML_API Sprite : public Drawable
{
public :

    ////////////////////////////////////////////////////////////
    /// \brief Default constructor
    ///
    /// Creates an empty sprite with no source texture.
    ///
    ////////////////////////////////////////////////////////////
    Sprite();
    ~Sprite();

    ////////////////////////////////////////////////////////////
    /// \brief Construct the sprite from a source texture
    ///
    /// \see SetTexture
    ///
    ////////////////////////////////////////////////////////////
    explicit Sprite(const Texture& texture);


In Sprite.cpp, I defined the destructor,

Code: [Select]
////////////////////////////////////////////////////////////
Sprite::Sprite(const Texture& texture) :
Drawable    (),
mySubRect   (0, 0, 1, 1),
myIsFlippedX(false),
myIsFlippedY(false)
{
    SetTexture(texture);
}

Sprite::~Sprite()
{

}


After which I rebuilt the SFML project, copied the new DLL's to my project's BIN directory (where the dll's were previously) and rebuild (vs 2010). I still get the error,

Code: [Select]

c:\sfml 2.0\include\sfml\system\resourceptr.inl(51): error C2027: use of undefined type 'sf::Texture'
3>          c:\sfml 2.0\include\sfml\graphics\renderer.hpp(42) : see declaration of 'sf::Texture'
3>          c:\sfml 2.0\include\sfml\system\resourceptr.inl(47) : while compiling class template member function 'sf::ResourcePtr<T>::ResourcePtr(const sf::ResourcePtr<T> &)'
3>          with
3>          [
3>              T=sf::Texture
3>          ]
3>          c:\sfml 2.0\include\sfml\graphics\sprite.hpp(208) : see reference to class template instantiation 'sf::ResourcePtr<T>' being compiled
3>          with
3>          [
3>              T=sf::Texture
3>          ]
3>c:\sfml 2.0\include\sfml\system\resourceptr.inl(51): error C2227: left of '->Connect' must point to class/struct/union/generic type
3>c:\sfml 2.0\include\sfml\system\resourceptr.inl(60): error C2027: use of undefined type 'sf::Texture'
3>          c:\sfml 2.0\include\sfml\graphics\renderer.hpp(42) : see declaration of 'sf::Texture'
3>          c:\sfml 2.0\include\sfml\system\resourceptr.inl(58) : while compiling class template member function 'sf::ResourcePtr<T>::~ResourcePtr(void)'
3>          with
3>          [
3>              T=sf::Texture
3>          ]
3>c:\sfml 2.0\include\sfml\system\resourceptr.inl(60): error C2227: left of '->Disconnect' must point to class/struct/union/generic type
3>c:\sfml 2.0\include\sfml\system\resourceptr.inl(69): error C2027: use of undefined type 'sf::Texture'
3>          c:\sfml 2.0\include\sfml\graphics\renderer.hpp(42) : see declaration of 'sf::Texture'
3>          c:\sfml 2.0\include\sfml\system\resourceptr.inl(67) : while compiling class template member function 'sf::ResourcePtr<T> &sf::ResourcePtr<T>::operator =(const sf::ResourcePtr<T> &)'
3>          with
3>          [
3>              T=sf::Texture
3>          ]
3>c:\sfml 2.0\include\sfml\system\resourceptr.inl(69): error C2227: left of '->Disconnect' must point to class/struct/union/generic type
3>c:\sfml 2.0\include\sfml\system\resourceptr.inl(74): error C2027: use of undefined type 'sf::Texture'
3>          c:\sfml 2.0\include\sfml\graphics\renderer.hpp(42) : see declaration of 'sf::Texture'
3>c:\sfml 2.0\include\sfml\system\resourceptr.inl(74): error C2227: left of '->Connect' must point to class/struct/union/generic type
3>  PolygonRenderer.hpp
3>  main.cpp
3>  GameImageManager.cpp
3>  Generating Code...
3>
3>Build FAILED.


Did I miss a step, or forget something otherwise?

Thanks,
Short

short

  • Newbie
  • *
  • Posts: 9
    • View Profile
Standalone header Graphics/Sprite.hpp doesn't compile
« Reply #5 on: September 17, 2011, 09:46:16 am »
I figured it out, at one point I was trying to return a sf::Sprite from a function, the error probably coming from the fact there is no copy constructor defined?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Standalone header Graphics/Sprite.hpp doesn't compile
« Reply #6 on: September 17, 2011, 02:06:35 pm »
There is one.

It's not an error in your code, it's a "bug" in SFML that needs to be fixed.
Laurent Gomila - SFML developer

 

anything