SFML community forums

Help => General => Topic started by: Gobbles on January 07, 2014, 07:18:08 am

Title: [Solved] weird pointer issue
Post by: Gobbles on January 07, 2014, 07:18:08 am
Recently for my project I made the switch from VS 2010 to VS 2012 to take advantage of some of the newer features it offers, but I've seem to run into an interesting issue I can't seem to figure out.

Currently right now I am trying to build the TextureHolder from the sfml game dev book
namespace Textures
{
        enum ID
        {
                Skeleton
        };
}

class TextureHolder
{
public:
        void Load(Textures::ID id, const std::string& filename);
        sf::Texture& Get(Textures::ID id);
        const sf::Texture& Get(Textures::ID id) const;

private:
        std::map<Textures::ID, std::unique_ptr<sf::Texture>> mTextureMap;
};
 

Pretty Straight forward stuff. But on use I get this error:
error C2248: 'std::unique_ptr<_Ty>::unique_ptr' : cannot access private member declared in class 'std::unique_ptr<_Ty>.

So I investigated this little issue, which appears that the pairing of the std::map is trying to copy over the unique_ptr, which is illegal. I looked into this but couldn't find one single answer as to what was going on. Apparently the issue might be my compiler using old libs? I have tried full uninstalls/re-installs, full repairs, creating a new Empty Project and bringing in all my files individually - everything I can think of.

I've exhausted my resources so now I turn to all of you...  I hope one of you has an answer.
Also I would give you all a complete and minimal example, but I believe this to be a compiler issue... but I could be completely wrong, who knows.
Title: Re: weird pointer issue
Post by: eXpl0it3r on January 07, 2014, 08:00:26 am
Since this is an issue of using the object, could you show the code, where you use it.

If it's not your mistake, but a compiler issue, it should be very easy to create a minimal example. ;)
Title: Re: weird pointer issue
Post by: amir ramezani on January 07, 2014, 09:38:54 am
if it is a compiler issue, you may write minimal example that use's it
if you've got error, it means an issue but if not, it seam's your code has problem
Title: Re: weird pointer issue
Post by: Gobbles on January 07, 2014, 03:40:44 pm
I'll post my useage of the object and whip up a an example when I get home from work. However I am certain using the github code for the book will produce the same results. I'll test all this as soon as I can.
Title: Re: weird pointer issue
Post by: amir ramezani on January 07, 2014, 07:13:25 pm
try GCC with Codeblocks and see what happen's?
because I haven't used MSVC to develop games and my Operating System
Title: Re: weird pointer issue
Post by: zsbzsb on January 07, 2014, 08:45:19 pm
try GCC with Codeblocks and see what happen's?
because I haven't used MSVC to develop games and my Operating System

Microsoft VS 11/2012 and 12/2013 work fine with the SFML Game Development book.
Title: Re: weird pointer issue
Post by: Gobbles on January 08, 2014, 02:39:32 am
Ok so I figured out the issue, quite the slap in the face once I did.

Originally I stored my character in a std::shared_ptr, for whatever reason I have no idea.. but I did, anyways this conflicts with the use of std::unique_ptr's inside of vectors and maps(within the character), but not standalone std::unique_ptr's, which is quite curious. I'll have to read up more on why this is. Switching pointers cleaned up the issue.