Register - Login
Views: 99831344
Main - Memberlist - Active users - Calendar - Wiki - IRC Chat - Online users
Ranks - Rules/FAQ - Stats - Latest Posts - Color Chart - Smilies
05-03-22 09:25:02 PM
Jul - Computers and Technology - Having a problem with a C++ function New poll - New thread - New reply
Next newer thread | Next older thread
Sukasa

Level: 123


Posts: 1051/4326
EXP: 20936863
For next: 294403

Since: 07-07-07


Since last post: 1.1 years
Last activity: 1.1 years

Posted on 06-06-09 06:14:20 PM Link | Quote
Me PM
Apparently this function in SDL_Mixer keeps dying, and I'm not sure why. Does anyone have any ideas? (For the record, It's not my function, it's just where the crash is occuring)

static void add_music_decoder(const char *decoder)
{
void *ptr = realloc(music_decoders, num_decoders * sizeof (const char **));
if (ptr == NULL) {
return; /* oh well, go on without it. */
}
music_decoders = (const char **) ptr;
music_decoders[num_decoders++] = decoder;
}

I'm using Visual Studio 2008, and music_decoders and num_decoders are both correct. ptr is 0x00000000, and the best I can tell, the crash seems to be in the realloc() function. Does anyone have any idea how I could handle this crash problem?

____________________
paulguy

Green Birdo
Level: 93


Posts: 203/2294
EXP: 8032816
For next: 19994

Since: 09-14-07

From: Buffalo, NY

Since last post: 9.7 years
Last activity: 9.7 years

Posted on 06-06-09 09:53:53 PM Link | Quote
I think I can see why it's crashing, but as far as dealing with it... update SDL or just make your own DLL with the fixes and ship your program with that.

As for why, it's only allocating enough space for the original size of the array. it's not enlarging it at all. If the function began with num_decoders++, then removed the one later on, it would probably work. Unless I'm completely missing something, which is usually the case!
Next newer thread | Next older thread
Jul - Computers and Technology - Having a problem with a C++ function New poll - New thread - New reply


Rusted Logic

Acmlmboard - commit 47be4dc [2021-08-23]
©2000-2022 Acmlm, Xkeeper, Kaito Sinclaire, et al.

29 database queries.
Query execution time: 0.122374 seconds
Script execution time: 0.004036 seconds
Total render time: 0.126410 seconds