In the past, I've gotten flak for using "unsafe" C-strings. In C++, std::string is giving me a headache. Randomly, when using a C++ string, it will cause my game to crash. Maybe it's something simple, but honestly, I've never had this problem before. It only happens when I try to set one string variable equal to another, like so:
void game_app_t::add_new_hint( std::string str )
{
struct hint_t* h = (struct hint_t*) malloc( sizeof( struct hint_t ) );
/* Add a new hint to the screen */
h->pos = m_user.pos;
h->str = str;
h->timer = 60;
h->alpha = 255.0f;
h->pos.v[0] += 32.0f;
list_add_beginning( &m_hints, h );
}
/* Example usage */
add_new_hint( "Avoid this" );
I've had this problem with random crashes before, and I ended up saying "screw it, I'll use C-strings", and that was the end of the crashes. Now it's happening again, and I'd rather find a solution as opposed to another work around fix. Any ideas? Thanks.
Shogun.
EDIT: Not sure if it matters, but I'm using XCode and this game is being dev'ed on Mac OSX Lion.