static int _md3_canload( PM_PARAMS_CANLOAD )
{
- md3_t *md3;
+ const md3_t *md3;
- /* to keep the compiler happy */
- *fileName = *fileName;
-
/* sanity check */
- if( bufSize < ( sizeof( *md3 ) * 2) )
+ if( (size_t) bufSize < ( sizeof( *md3 ) * 2) )
return PICO_PMV_ERROR_SIZE;
/* set as md3 */
- md3 = (md3_t*) buffer;
+ md3 = (const md3_t*) buffer;
/* check md3 magic */
- if( *((int*) md3->magic) != *((int*) MD3_MAGIC) )
+ if( *((const int*) md3->magic) != *((const int*) MD3_MAGIC) )
return PICO_PMV_ERROR_IDENT;
/* check md3 version */
static picoModel_t *_md3_load( PM_PARAMS_LOAD )
{
int i, j;
- picoByte_t *bb;
+ picoByte_t *bb, *bb0;
md3_t *md3;
md3Surface_t *surface;
md3Shader_t *shader;
/* set as md3 */
- bb = (picoByte_t*) buffer;
- md3 = (md3_t*) buffer;
+ bb0 = bb = (picoByte_t*) _pico_alloc(bufSize);
+ memcpy(bb, buffer, bufSize);
+ md3 = (md3_t*) bb;
/* check ident and version */
if( *((int*) md3->magic) != *((int*) MD3_MAGIC) || _pico_little_long( md3->version ) != MD3_VERSION )
{
/* not an md3 file (todo: set error) */
+ _pico_free(bb0);
return NULL;
}
if( md3->numFrames < 1 )
{
_pico_printf( PICO_ERROR, "MD3 with 0 frames" );
+ _pico_free(bb0);
return NULL;
}
if( frameNum < 0 || frameNum >= md3->numFrames )
{
_pico_printf( PICO_ERROR, "Invalid or out-of-range MD3 frame specified" );
+ _pico_free(bb0);
return NULL;
}
if( picoModel == NULL )
{
_pico_printf( PICO_ERROR, "Unable to allocate a new model" );
+ _pico_free(bb0);
return NULL;
}
{
_pico_printf( PICO_ERROR, "Unable to allocate a new model surface" );
PicoFreeModel( picoModel ); /* sea */
+ _pico_free(bb0);
return NULL;
}
{
_pico_printf( PICO_ERROR, "Unable to allocate a new model shader" );
PicoFreeModel( picoModel );
+ _pico_free(bb0);
return NULL;
}
}
/* return the new pico model */
+ _pico_free(bb0);
return picoModel;
}