Highly Complete: Add exception handling for NCSF
SSEQPlayer throws exceptions, there should be exception handling to catch them and fail gracefully. Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
parent
7777e50f03
commit
d835c252fa
1 changed files with 80 additions and 49 deletions
|
@ -1062,14 +1062,18 @@ static int usf_info(void *context, const char *name, const char *value) {
|
|||
|
||||
if(state.state) free(state.state);
|
||||
} else if(type == 0x25) {
|
||||
struct ncsf_loader_state *state = new struct ncsf_loader_state;
|
||||
struct ncsf_loader_state *state = NULL;
|
||||
Player *player = NULL;
|
||||
|
||||
try {
|
||||
state = new struct ncsf_loader_state;
|
||||
|
||||
if(psf_load([currentUrl UTF8String], &source_callbacks, 0x25, ncsf_loader, state, 0, 0, 0) <= 0) {
|
||||
delete state;
|
||||
return NO;
|
||||
}
|
||||
|
||||
Player *player = new Player;
|
||||
player = new Player;
|
||||
|
||||
player->interpolation = INTERPOLATION_SINC;
|
||||
|
||||
|
@ -1088,6 +1092,14 @@ static int usf_info(void *context, const char *name, const char *value) {
|
|||
|
||||
emulatorCore = (uint8_t *)player;
|
||||
emulatorExtra = state;
|
||||
} catch (std::exception &e) {
|
||||
ALog(@"Exception caught creating NCSF player: %s", e.what());
|
||||
emulatorCore = NULL;
|
||||
emulatorExtra = NULL;
|
||||
delete player;
|
||||
delete state;
|
||||
return NO;
|
||||
}
|
||||
} else if(type == 0x41) {
|
||||
struct qsf_loader_state *state = (struct qsf_loader_state *)calloc(1, sizeof(*state));
|
||||
|
||||
|
@ -1281,6 +1293,7 @@ static int usf_info(void *context, const char *name, const char *value) {
|
|||
NDS_state *state = (NDS_state *)emulatorCore;
|
||||
state_render(state, (s16 *)buf, frames);
|
||||
} else if(type == 0x25) {
|
||||
try {
|
||||
Player *player = (Player *)emulatorCore;
|
||||
ncsf_loader_state *state = (ncsf_loader_state *)emulatorExtra;
|
||||
std::vector<uint8_t> &buffer = state->outputBuffer;
|
||||
|
@ -1294,6 +1307,10 @@ static int usf_info(void *context, const char *name, const char *value) {
|
|||
buf = ((uint8_t *)buf) + frames_this_run * sizeof(int16_t) * 2;
|
||||
frames_to_do -= frames_this_run;
|
||||
}
|
||||
} catch (std::exception &e) {
|
||||
ALog(@"Exception caught while playing NCSF: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
} else if(type == 0x41) {
|
||||
uint32_t howmany = frames;
|
||||
qsound_execute(emulatorCore, 0x7fffffff, (int16_t *)buf, &howmany);
|
||||
|
@ -1367,8 +1384,12 @@ static int usf_info(void *context, const char *name, const char *value) {
|
|||
state_deinit(state);
|
||||
free(state);
|
||||
} else if(type == 0x25) {
|
||||
try {
|
||||
Player *player = (Player *)emulatorCore;
|
||||
delete player;
|
||||
} catch (std::exception &e) {
|
||||
ALog(@"Exception caught deleting NCSF player: %s", e.what());
|
||||
}
|
||||
} else {
|
||||
free(emulatorCore);
|
||||
}
|
||||
|
@ -1387,8 +1408,12 @@ static int usf_info(void *context, const char *name, const char *value) {
|
|||
free(emulatorExtra);
|
||||
emulatorExtra = nil;
|
||||
} else if(type == 0x25 && emulatorExtra) {
|
||||
try {
|
||||
struct ncsf_loader_state *state = (struct ncsf_loader_state *)emulatorExtra;
|
||||
delete state;
|
||||
} catch (std::exception &e) {
|
||||
ALog(@"Exception caught deleting NCSF state: %s", e.what());
|
||||
}
|
||||
emulatorExtra = nil;
|
||||
} else if(type == 0x41 && emulatorExtra) {
|
||||
struct qsf_loader_state *state = (struct qsf_loader_state *)emulatorExtra;
|
||||
|
@ -1497,6 +1522,7 @@ static int usf_info(void *context, const char *name, const char *value) {
|
|||
|
||||
framesRead = frame;
|
||||
} else if(type == 0x25) {
|
||||
try {
|
||||
Player *player = (Player *)emulatorCore;
|
||||
ncsf_loader_state *state = (ncsf_loader_state *)emulatorExtra;
|
||||
std::vector<uint8_t> &buffer = state->outputBuffer;
|
||||
|
@ -1513,6 +1539,11 @@ static int usf_info(void *context, const char *name, const char *value) {
|
|||
}
|
||||
|
||||
framesRead = frame;
|
||||
} catch (std::exception &e) {
|
||||
ALog(@"Exception caught while seeking in NCSF: %s", e.what());
|
||||
framesRead = 0;
|
||||
return -1;
|
||||
}
|
||||
} else if(type == 0x41) {
|
||||
do {
|
||||
uint32_t howmany = (uint32_t)(frame - framesRead);
|
||||
|
|
Loading…
Reference in a new issue