Fix a VGM crash when loading unsupported files.

This commit is contained in:
Chris Moeller 2016-07-02 17:08:41 -07:00
parent b262dfa508
commit 5006d05222
2 changed files with 7 additions and 1 deletions

View file

@ -29,13 +29,14 @@ Vgm_Emu::Vgm_Emu()
set_type( gme_vgm_type ); set_type( gme_vgm_type );
set_max_initial_silence( 1 ); set_max_initial_silence( 1 );
set_silence_lookahead( 1 ); // tracks should already be trimmed set_silence_lookahead( 1 ); // tracks should already be trimmed
voice_names_assigned_ = false;
} }
Vgm_Emu::~Vgm_Emu() Vgm_Emu::~Vgm_Emu()
{ {
// XXX ugly use of deprecated functions to free allocated voice names // XXX ugly use of deprecated functions to free allocated voice names
const char ** voice_names_ = voice_names(); const char ** voice_names_ = voice_names();
if (voice_names_) if (voice_names_assigned_ && voice_names_)
{ {
for (int i = 0; i < 32; ++i) for (int i = 0; i < 32; ++i)
{ {
@ -512,7 +513,10 @@ blargg_err_t Vgm_Emu::load_mem_( const byte* in, int file_size )
break; break;
} }
if (i == voice_count) if (i == voice_count)
{
set_voice_names(voice_names); set_voice_names(voice_names);
voice_names_assigned_ = true;
}
else else
{ {
for (i = 0; i < voice_count; i++) for (i = 0; i < voice_count; i++)

View file

@ -55,6 +55,8 @@ private:
track_info_t metadata; track_info_t metadata;
track_info_t metadata_j; track_info_t metadata_j;
bool voice_names_assigned_;
void check_end(); void check_end();
}; };