- Fixed emulator crash on sample loading failure
This commit is contained in:
parent
6c00a49806
commit
2d6477ce1b
|
@ -25,7 +25,7 @@ extern int MicButtonPressed;
|
|||
|
||||
#ifdef WIN32
|
||||
static char MicSampleName[256];
|
||||
char* LoadSample(const char *name);
|
||||
bool LoadSample(const char *name);
|
||||
#endif
|
||||
|
||||
extern int MicDisplay;
|
||||
|
|
|
@ -3798,7 +3798,14 @@ LRESULT CALLBACK MicrophoneSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
|
|||
|
||||
WritePrivateProfileInt("Use Mic Sample", "UseMicSample", ((UseMicSample == true) ? 1 : 0), 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:
|
||||
|
|
|
@ -57,23 +57,36 @@ static int CALLBACK waveInProc(HWAVEIN wavein, UINT msg, DWORD instance, DWORD p
|
|||
return 0;
|
||||
}
|
||||
|
||||
static char* samplebuffer;
|
||||
static int samplebuffersize;
|
||||
static FILE* fp;
|
||||
static char* samplebuffer = NULL;
|
||||
static int samplebuffersize = 0;
|
||||
static FILE* fp = NULL;
|
||||
|
||||
char* LoadSample(const char *name)
|
||||
bool LoadSample(const char *name)
|
||||
{
|
||||
|
||||
std::ifstream fl(name);
|
||||
|
||||
if (!fl.is_open())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
fl.seekg( 0, std::ios::end );
|
||||
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.read(ret, len);
|
||||
samplebuffer=ret;
|
||||
fl.read (samplebuffer, len);
|
||||
fl.close();
|
||||
|
||||
SampleLoaded=1;
|
||||
return ret;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL Mic_Init() {
|
||||
|
|
Loading…
Reference in New Issue