- Fixed emulator crash on sample loading failure

This commit is contained in:
shashclp 2009-07-19 01:23:43 +00:00
parent 6c00a49806
commit 2d6477ce1b
3 changed files with 32 additions and 12 deletions

View File

@ -25,7 +25,7 @@ extern int MicButtonPressed;
#ifdef WIN32 #ifdef WIN32
static char MicSampleName[256]; static char MicSampleName[256];
char* LoadSample(const char *name); bool LoadSample(const char *name);
#endif #endif
extern int MicDisplay; extern int MicDisplay;

View File

@ -3798,7 +3798,14 @@ LRESULT CALLBACK MicrophoneSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
WritePrivateProfileInt("Use Mic Sample", "UseMicSample", ((UseMicSample == true) ? 1 : 0), IniName); WritePrivateProfileInt("Use Mic Sample", "UseMicSample", ((UseMicSample == true) ? 1 : 0), IniName);
WritePrivateProfileString("Use Mic Sample", "MicSampleFile", MicSampleName, IniName); WritePrivateProfileString("Use Mic Sample", "MicSampleFile", MicSampleName, IniName);
LoadSample(MicSampleName);
if (UseMicSample)
{
if (!LoadSample(MicSampleName))
{
MessageBox(hDlg, "Unable to read the sample", "DeSmuME", (MB_OK | MB_ICONEXCLAMATION));
}
}
} }
} }
case IDCANCEL: case IDCANCEL:

View File

@ -57,23 +57,36 @@ static int CALLBACK waveInProc(HWAVEIN wavein, UINT msg, DWORD instance, DWORD p
return 0; return 0;
} }
static char* samplebuffer; static char* samplebuffer = NULL;
static int samplebuffersize; static int samplebuffersize = 0;
static FILE* fp; static FILE* fp = NULL;
char* LoadSample(const char *name) bool LoadSample(const char *name)
{ {
std::ifstream fl(name); std::ifstream fl(name);
if (!fl.is_open())
{
return false;
}
fl.seekg( 0, std::ios::end ); fl.seekg( 0, std::ios::end );
size_t len = fl.tellg(); size_t len = fl.tellg();
samplebuffersize=len;
char *ret = new char[len]; // Avoid mem leaks
if (samplebuffer != NULL)
delete[] samplebuffer;
samplebuffersize = len;
samplebuffer = new char[len];
fl.seekg(0, std::ios::beg); fl.seekg(0, std::ios::beg);
fl.read(ret, len); fl.read (samplebuffer, len);
samplebuffer=ret; fl.close();
SampleLoaded=1; SampleLoaded=1;
return ret;
return true;
} }
BOOL Mic_Init() { BOOL Mic_Init() {