Loading TMX files with SDL2 using Baylej's C library

Started by
3 comments, last by Datamancer 8 years, 1 month ago

Having a little trouble loading in a TiledMap with Baylej's C TMX Loader. I'm looking at his SDL example and the map is loading mostly okay. The only it that the tiles list under the map variable is NULL.

I'm using his example .tmx files. I tried in XML, CSV and zlib, all with the same result.

This is my barebones code. Just trying to attempt to get the tiles to show up under the map in the debugger.

http://pastebin.com/XaTb4vjE

(Sorry for copy pasting code, It's not letting me link a pastebin).

If anyone has had this problem I'd appreciate some insight, as I am pretty stumped.

Cheers.

Edit: Here is a picture of my debugger, if you look at the bottom of locals you can see that tiles in NULL after loading the map in.

http://i.imgur.com/PlyStj8.png

Advertisement

bool TMXLoader::LoadMap(std::string location)
{
    tmx_map *map = tmx_load(location.c_str());
 
    return true;
}
Unless you are inspecting map on this line, the tmx_map is lost once this method returns.

Yes, but I didn't step over the return and the rest of the object is still intact.

I put a quick printf before the return, redebugged and I still have the same results.

Thanks for the reply :)

tilecount is populated which would suggest that your tiles are getting parsed properly.

What do you see if you expand the tiles node in the debugger?
What Fastcall is saying is that you make a call and store the result in a pointer, but then never do anything with that pointer. The data isn't lost until execution returns; in this case when you return true. When you check the value before return the value will still be valid as you are still within the lifetime of the routine. Your variable is null because you never store that value in the routine and then it returns execution.

"The code you write when you learn a new language is shit.
You either already know that and you are wise, or you don’t realize it for many years and you are an idiot. Either way, your learning code is objectively shit." - L. Spiro

"This is called programming. The art of typing shit into an editor/IDE is not programming, it's basically data entry. The part that makes a programmer a programmer is their problem solving skills." - Serapth

"The 'friend' relationship in c++ is the tightest coupling you can give two objects. Friends can reach out and touch your privates." - frob

This topic is closed to new replies.

Advertisement