Removed alloca calls from sound reader classes because putting it inside a loop tends to cause a stack overflow.

Removed alloca call from png loading because it does not work with setjmp and longjmp.  png loading now uses exceptions instead when an error occurs.
This commit is contained in:
Kyzentun Keeslala
2016-06-21 19:23:37 -06:00
parent 5fca435b43
commit d4926506f9
4 changed files with 23 additions and 13 deletions
+19 -8
View File
@@ -50,7 +50,10 @@ void PNG_Error( png_struct *png, const char *error )
strncpy( info->err, error, 1024 );
info->err[1023] = 0;
LOG->Trace( "loading \"%s\": err: %s", info->fn, info->err );
longjmp( png_jmpbuf(png), 1 );
// This exception is just thrown to go to the catch block for cleanup. The
// message has already been printed, so the exception value can be ignored.
// -Kyz
throw int(1);
}
void PNG_Warning( png_struct *png, const char *warning )
@@ -87,12 +90,10 @@ static RageSurface *RageSurface_Load_PNG( RageFile *f, const char *fn, char erro
RageSurface *volatile img = NULL;
CHECKPOINT_M("Potential issue with png jump about to be analyzed.");
if( setjmp(png_jmpbuf(png) ))
png_byte** row_pointers= NULL;
try
{
png_destroy_read_struct( &png, &info_ptr, NULL );
delete img;
return NULL;
}
png_set_read_fn( png, f, RageFile_png_read );
@@ -227,8 +228,7 @@ static RageSurface *RageSurface_Load_PNG( RageFile *f, const char *fn, char erro
}
ASSERT( img != NULL );
/* alloca to prevent memleaks if libpng longjmps us */
png_byte **row_pointers = (png_byte **) alloca( sizeof(png_byte*) * height );
row_pointers = new png_byte*[height];
CHECKPOINT_M( ssprintf("%p",row_pointers) );
for( unsigned y = 0; y < height; ++y )
@@ -241,6 +241,17 @@ static RageSurface *RageSurface_Load_PNG( RageFile *f, const char *fn, char erro
png_read_end( png, info_ptr );
png_destroy_read_struct( &png, &info_ptr, NULL );
}
catch(int e)
{
png_destroy_read_struct(&png, &info_ptr, NULL);
delete img;
if(row_pointers != NULL)
{
delete[] row_pointers;
}
return NULL;
}
return img;
}