Sign in to follow this  
KanonBaum

STL bug on Mac os? (C++)

Recommended Posts

I am using a TMX parser library I found online to load my maps for my game (using TiledQT). I've been having more than a ridiculous time trying to load maps so I got rather excited when I stumbled across this library.
You can find it here:

http://code.google.com/p/tmx-parser/

Now, I'm having a problem with the example program it came with. Not a compiler issue, but a run time. I contacted the author and he spent some time we me trying to track it down but to no avail.
He suggested that maybe it was a problem with STL on my Mac Os x (Snow Leopard). Luckily, the chat between me and him about the issue was recorded on the google code project page.

If you could take a look here and the code, it would be great:

http://code.google.com/p/tmx-parser/issues/detail?id=1

I'd like this fixed for me and him so we can get onto our coding lives. :D

Thanks for any future help!

Share this post


Link to post
Share on other sites
Have you tried enabling the debugging features of the GCC STL implementation?

Add this to your compiler's command line (ALL source files!!):

-D_GLIBCXX_DEBUG=1 -D_GLIBCXX_DEBUG_PEDANTIC=1 -D_GLIBCXX_CONCEPT_CHECKS=1

That might help uncover any usage problems.

Can you confirm that none of the functions in the call chain are returning references to local variables? Can you make the test case smaller so that peeps can try it at home easily?

FWIW, I've been using the Mac's STL implementation heavily for 5 years. It's generally fine. It's a slippery slope after you start blaming compilers and standard libraries...

Share this post


Link to post
Share on other sites
The best thing to do when you think you've found a compiler/library problem is to create a minimal complete program that shows the unexpected behavior. That way you can be sure that it's not some other part of your code messing things up, and others can compile your minimal program and reproduce the bug themselves, and that way you can convince them that it really is a problem with the compiler/library.

Most of the time, you'll discover it's something else, while you are in the process of generating that minimal complete program.

Share this post


Link to post
Share on other sites
You know, I've been using and contributing to GCC's libstdc++-v3 (the standard C++ library use on Mac OS) for 12 years. I think I would have heard there is a fundamental implementation flaw in the copy constructor of std::map by now, but I guess you just never know.

Or, perhaps, there are some unrelated lifetime issues (returning references to local variables or dangling pointers) elsewhere in the code that could cause memory allocation error in unexpected places.

Valgrind wants to be your friend.

Share this post


Link to post
Share on other sites
Well this library (as linked above) is not mine. And there is an example program it comes with that I am using to test the library:

[url="http://code.google.com/p/tmx-parser/source/browse/trunk/TmxParser_Test/TmxParser_Test.cpp"]http://code.google.c...Parser_Test.cpp[/url]

And it always crashes on line 66. If I comment it out, then it runs perfectly fine but I cannot grab property tile values.
Also, I have tried narrowing this down with help from the author of the library, but he can't seem to fix it either. All bugs are listed in the links provided in the original post.

If it's not a syntax error, I'm not sure what else to do at this point. (Not being lazy here. I just really don't know what else to do)

Share this post


Link to post
Share on other sites
How much of the example code can you strip out before the error goes away?

Is the pointer created on line 64 definitely non-null-valued?

Did you try recompiling with the debug features of the STL, as I suggested?

Share this post


Link to post
Share on other sites
[quote name='KanonBaum' timestamp='1307466650' post='4820586']
Well this library (as linked above) is not mine. And there is an example program it comes with that I am using to test the library:

[url="http://code.google.com/p/tmx-parser/source/browse/trunk/TmxParser_Test/TmxParser_Test.cpp"]http://code.google.c...Parser_Test.cpp[/url]
[/quote]
That code is malformed. For example, on line 37, a std::string is passed by value to printf(). Who knows what will happen? It's undefined. You're lucky your hard drive is not being reformatted as you read this.

Try changing all the C code printf()s to C++ cout and rerun. That should avoid [i]that[/i] little bit of undefined behaviour. Also, try enabling warnings when building the library and sample code. All warnings. See what they have to say.

Share this post


Link to post
Share on other sites
Hidden
It honestly didn't produce any different results.

If it helps, I can show local values from the compiler of the variables. Some values seem cryptic but maybe someone with more knowledge can figure them out?

Share this post


Link to post
I took the liberty of running valgrind (as suggested) on the library and found two errors that could account for the problems that you are seeing. I posted a patch to [url="http://code.google.com/p/tmx-parser/issues/detail?id=1"]the google code project.[/url]

Share this post


Link to post
Share on other sites
I made the changes you suggested but it still crashes on line 66 specifically. When I try to get values from the tiles.

However, I commented it out and I am able to get property values from objects which follows the same format so I'm confused, but hey! It's finally progress now! Thanks for your help so far. :D

Share this post


Link to post
Share on other sites
[quote name='KanonBaum' timestamp='1307480958' post='4820692']
I made the changes you suggested but it still crashes on line 66 specifically. When I try to get values from the tiles.
[/quote]
It really sounds like Tileset::GetTile() is returning NULL (indicating tile not found). Since I can not reproduce the problem, could you check the various pointers returned for NULL?

It could be a line ending problem when reading or parsing data.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this