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

Author Topic: [SOLVED] LoadFromFile Crash  (Read 3810 times)

0 Members and 1 Guest are viewing this topic.

Tresky

  • Newbie
  • *
  • Posts: 44
    • View Profile
    • Email
[SOLVED] LoadFromFile Crash
« on: May 20, 2013, 12:35:50 am »
Hey guys!

I have been having particular trouble loading an image. It's never given me trouble before, but now it is.

I have checked to use the correct versions of the library. I am using the pre-compiled VS2012 version of the SDK. I am linking Debug libraries to my Debug project.

I couldn't produce a smaller version of the error. I first created a test program to test and see if it was SFML messing up. Just as I predicted, SFML was not the problem and it is my own doing. Since then, I have not been able to locate the error.

// Load the image of the tileset and store
  // it in the SfTileset.
  string source = "tmw_desert_spacing.png";

  cout << source << endl;
  if (!tileset_image.loadFromFile(source))
  {
    cout << "Failed to load tileset image" << endl;
    return false;
  }
  cout << "Success" << endl;

This code managed to gather the correct source from the XML file, so we can rule out the TinyXML code. I debugged the crash and it occurs directly on the line with the loadFromFile() call. It doesn't send a fail to SFML either because it never gets inside of the if statement or even past it.

The error says:
Unhandled exception at 0x0FB5CCC8 (msvcp110d.dll) in sf_tile_engine.exe: 0xC0000005: Access violation reading location 0x51DF2948.

The call stack says:
>   msvcp110d.dll!std::_Container_base12::_Orphan_all() Line 216
>   sfml-graphics-d-2.dll!0ff5dd9a()
>   [Frames below may be incorrect and/or missing, no symbols loaded for sfml-graphics-d-2.dll]   
>   sfml-graphics-d-2.dll!0ff63ea4()
>   sfml-graphics-d-2.dll!0ff629b9()
>   sf_tile_engine.exe!sftile::SfTileset::Parse(tinyxml2::XMLElement * _element) Line 74 // This is the function that contains the above code.


Any hints?

PS: The image it's trying to load is indeed in the directory and of the type PNG.

Thanks! :)
« Last Edit: May 20, 2013, 05:52:16 am by Tresky »

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: LoadFromFile Crash
« Reply #1 on: May 20, 2013, 03:13:19 am »
Tresky, try loading the same image in a minimal example. If it crashes anyway, try loading a different image.

It will probably work and if it doesn't it will indicate its a setup error because SFML does work :D

Tresky

  • Newbie
  • *
  • Posts: 44
    • View Profile
    • Email
Re: LoadFromFile Crash
« Reply #2 on: May 20, 2013, 03:15:21 am »
Yup. As I said earlier, I tried a minimal example of just loading that image and it worked fine. So it's something in my code, but I don't even know where to look.

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: LoadFromFile Crash
« Reply #3 on: May 20, 2013, 03:24:12 am »
Then you need to debug your own code as its not happening in sf::Texture. We don't know how to help without more code to look at :)

There is also a slight chance IT IS crashing in sf::Texture, in which case that means memory is corrupted by some weird thing you did before loading the texture.  :)

Tresky

  • Newbie
  • *
  • Posts: 44
    • View Profile
    • Email
Re: LoadFromFile Crash
« Reply #4 on: May 20, 2013, 03:28:54 am »
Hmmm. I see. The sf::Image it is loading into is a member of the class containing the above mentioned function. All I did was:

class Class
{
public:
  Class()
    : tileset_image()
  {}

  bool Parse()
  {
    tileset_image.loadFromFile(source);
    return true;
  }

private:
  sf::Image tileset_image;
};

Am I forgetting anything? Of course, this code is shortened an extreme amount. Haha.

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: LoadFromFile Crash
« Reply #5 on: May 20, 2013, 05:26:44 am »
If that is the class, and its properly instantiated before you call Parse(), then its a weird memory corruption.. maybe a memory leak somewhere?

Tresky

  • Newbie
  • *
  • Posts: 44
    • View Profile
    • Email
Re: LoadFromFile Crash
« Reply #6 on: May 20, 2013, 05:51:39 am »
I switched smart pointers and that solved it for the most part, so it was probably some memory leaks somewhere like you said. Thanks a lot. :)