SFML community forums

Help => General => Topic started by: Nival on January 27, 2018, 06:42:42 pm

Title: Maploader for Tile editor
Post by: Nival on January 27, 2018, 06:42:42 pm
Hi guys, can anyone help me to load map from .tmx file, i tried to make it with tinyxml , coppied code from topics but always get error at "   image = tilesetElement->FirstChildElement("image");
                                          std::string imagepath = image->Attribute("source");"  -  read access violation.

Code in attachment
Title: Re: Maploader for Tile editor
Post by: eXpl0it3r on January 27, 2018, 07:26:21 pm
I recommend using tmxlite (https://github.com/fallahn/tmxlite) or if you must sfml-tmxloader (https://github.com/fallahn/sfml-tmxloader).

Secondly you should learn some modern C++ where never use owning raw pointers and instead make use of unique (and shared) pointers and thus pretty much do away with manual memory management.

As for the crash:

image = tilesetElement->FirstChildElement("image");
std::string imagepath = image->Attribute("source");

It's most likely that FirstChildElement("image") returned nullptr and then you try to access it, causing an access violation, thus crash.
Title: Re: Maploader for Tile editor
Post by: Nival on January 27, 2018, 07:38:33 pm
I recommend using tmxlite (https://github.com/fallahn/tmxlite) or if you must sfml-tmxloader (https://github.com/fallahn/sfml-tmxloader).

Secondly you should learn some modern C++ where never use owning raw pointers and instead make use of unique (and shared) pointers and thus pretty much do away with manual memory management.

As for the crash:

        image = tilesetElement->FirstChildElement("image");
        std::string imagepath = image->Attribute("source");

It's most likely that FirstChildElement("image") returned false and then you try to access it, causing an access violation, thus crash.
Thanks, it's rly returned false i'll try to use libs that u adviced