Game Development Community

TGEA and stl string issue

by Playware · in Torque Game Engine · 04/01/2009 (12:16 am) · 10 replies

Hi,

I'm integrating Torque 1.8.1 with some other 3rd party libraries which use stl string.
I put this line in my main.cpp.

std::string return = gLibrary::getProperty("label");

It compiled fine but when I debug it, this line run into access violation error somewhere in memcpy.asm. I found out that stl has issues with Torque in memory manager.

I already looked at stl_fix resource and other threads also.
But they seem pretty old and the files and codes to modify mentioned in these threads are no longer here in TGEA.

My problem is similar to that one and that thread also get no replies yet.
http://www.garagegames.com/community/forums/viewthread/86195

Anybody knows how to get STL working with TGEA 1.7.1 or 1.8?

Thanks

#1
04/01/2009 (1:50 am)
As the original author of stl_fix many years ago, I'll have a look to see if I can work out a new fix for TGEA and Torque3D.

No promises though, stl_fix was a hack of the highest order!

#2
04/01/2009 (6:55 pm)
Thanks. I'm looking forward to it.
Hope you can touch it again.
#3
04/02/2009 (10:58 pm)
From reading through stl_fix, what I understand is, the problem occurs because of that Torque overwrite the global new operator. I couldn't find the mentioned new overwrite in that platform.h file. So I searched through the entire solution to see if I can find such new overwrite. But I couldn't find such new operator overwrite in the entire solution either. So I wonder if it's still the stl problem or am I having some other errors.
#4
04/04/2009 (4:55 am)
I think your right stl_fix isn't required, I successfully added a std:string and std::vector to TorqueMain without any problems. That was on the Mac build of TGEA 1.8.1. (I'm assuming its the same on the Win build)

So at least out the box, the STL is supported now.

Of course it may well be better to support to Torque version (i.e. tVector, String) when you can but at least now interop with other libraries that do use STL should be easy :)
#5
04/05/2009 (8:20 pm)
Thanks for the reply.
So I'm confused now. As I thought this could be the stl issue.
But if it's not, what issues can make that stl::string assignment line runs into access violation error i n memcpy.asm?
In my release build, I couldn't debug it and still have the problem occur.
But if I run the exe that's built, it runs fine. I suspect it's just hiding the error rather than solving it.

Any ideas will be really appreciated.
Many thanks.
#6
04/06/2009 (4:32 am)
Could it be a lifetime issue? is the std::string being destroyed before being copied or something similar?

Having a crash in memcpy.asm in release sounds likes the pointer has been corrupted, which sounds like lifetimes issues, unfortunately that's impossible to tell from here.

I'll write a unit test tonight for TGEA 1.8.1 to test STL <-> Torque interop, see if I can cause it to crash, but can't see any reason while me initial quick tests worked and the unit test won't, but then you never know :-/


#7
04/07/2009 (2:18 am)
My unit test so far, hasn't revealed any issues...

I'll finish it up tonight and publish it here but afaict their is no problem with STL and Torque anymore.
#8
04/07/2009 (11:32 am)
Follow the link to my STL/Torque unit test dl.getdropbox.com/u/273521/testSTL.cpp Add it too Engine/unit/test/testSTL.cpp, compile, run, bring up the console and then type

unitTest_runTests("stl",false)

And hopefully all will pass (as it does on mine on a Mac in both debug and release)

Currently only do a few tests on std::vector, std::string and String but should show up any issues, if there were any.

GG peeps: Might be good to add this to the code base proper
#9
04/07/2009 (8:11 pm)
Thanks. I gonna check it out on Windows and will post the results here soon.
#10
04/07/2009 (8:15 pm)
Hi,
All tests passed.
So it's not an stl issue.
I'm trying to find out whether it's a lifetime issue.

I'll update this thread as I progress.

Many thanks.