| @@ -112,6 +112,10 @@ static int select_rom(menu_state* menu, | |||||
| cart_info* cur_cart) { | cart_info* cur_cart) { | ||||
| int status = 0; | int status = 0; | ||||
| cart_info cart = {0}; | cart_info cart = {0}; | ||||
| cart_info ref_cart = { | |||||
| .filename = cur_cart->filename, | |||||
| .file = cur_cart->file, | |||||
| }; | |||||
| nes_cart new_cart = {0}; | nes_cart new_cart = {0}; | ||||
| while (0 == status && NULL == cart.file) { | while (0 == status && NULL == cart.file) { | ||||
| @@ -125,22 +129,22 @@ static int select_rom(menu_state* menu, | |||||
| // Program closed inside modal | // Program closed inside modal | ||||
| status = input_Result_Quit; | status = input_Result_Quit; | ||||
| } | } | ||||
| free(cart.filename); | |||||
| cart.filename = NULL; | |||||
| } | } | ||||
| if (0 == status) { | if (0 == status) { | ||||
| cart.filename = run_main_menu(menu, comp, cur_cart); | |||||
| char* new_filename = run_main_menu(menu, comp, | |||||
| &ref_cart); | |||||
| if ((char*)-1 == cart.filename) { | |||||
| // This means that we quit | |||||
| if ((char*)-1 == new_filename) { | |||||
| status = input_Result_Quit; | status = input_Result_Quit; | ||||
| } else if (NULL == cart.filename) { | |||||
| // This means we didn't press "cancel" | |||||
| } else if (NULL == new_filename) { | |||||
| status = input_Result_Cancel; | status = input_Result_Cancel; | ||||
| } else { | } else { | ||||
| free(cart.filename); | |||||
| cart.filename = new_filename; | |||||
| ref_cart.filename = new_filename; | |||||
| cart.file = nes_load_cart(&new_cart, | cart.file = nes_load_cart(&new_cart, | ||||
| cart.filename); | cart.filename); | ||||
| } | } | ||||
| @@ -157,6 +161,9 @@ static int select_rom(menu_state* menu, | |||||
| *cur_cart = cart; | *cur_cart = cart; | ||||
| nes_setup_cart(comp->sys); | nes_setup_cart(comp->sys); | ||||
| } else { | |||||
| free(cart.filename); | |||||
| } | } | ||||
| return status; | return status; | ||||