@@ -1716,8 +1716,8 @@ static uint8_t se_detect_system_type(const char* path) {
17161716 if (sb_path_has_file_ext (path , ".gbc" )) return 1 ; // GBC
17171717 if (sb_path_has_file_ext (path , ".gba" )) return 2 ; // GBA
17181718 if (sb_path_has_file_ext (path , ".nds" )) return 3 ; // NDS
1719- if ( sb_path_has_file_ext ( path , ".zip" )) return 255 ; // ZIP (unknown until extracted)
1720- return 255 ;
1719+ // Note: ZIP files are intentionally excluded from library as they require extraction to determine system type
1720+ return 255 ; // Unknown/unsupported
17211721}
17221722
17231723static void se_scan_directory_for_games (const char * dir_path , bool recursive ) {
@@ -1780,8 +1780,6 @@ static void se_scan_game_library() {
17801780static int se_game_library_alpha_comparator (const void * a , const void * b ) {
17811781 int ia = * (const int * )a ;
17821782 int ib = * (const int * )b ;
1783- if (ia == -1 ) return 1 ;
1784- if (ib == -1 ) return -1 ;
17851783 return strcmp (gui_state .game_library .entries [ia ].name , gui_state .game_library .entries [ib ].name );
17861784}
17871785
@@ -1790,15 +1788,17 @@ static int se_game_library_rev_alpha_comparator(const void* a, const void* b) {
17901788}
17911789
17921790static void se_sort_game_library () {
1793- int size = 0 ;
1794- for (int i = 0 ; i < SE_MAX_GAME_LIBRARY_ENTRIES ; ++ i ) {
1795- if (i >= gui_state .game_library .num_entries ) {
1796- gui_state .game_library .sorted_entries [i ] = -1 ;
1797- } else {
1798- gui_state .game_library .sorted_entries [i ] = i ;
1799- size = i + 1 ;
1800- }
1791+ int size = gui_state .game_library .num_entries ;
1792+
1793+ for (int i = 0 ; i < size ; ++ i ) {
1794+ gui_state .game_library .sorted_entries [i ] = i ;
18011795 }
1796+ // Mark remaining entries as invalid
1797+ for (int i = size ; i < SE_MAX_GAME_LIBRARY_ENTRIES ; ++ i ) {
1798+ gui_state .game_library .sorted_entries [i ] = -1 ;
1799+ }
1800+
1801+ if (size == 0 ) return ;
18021802
18031803 if (gui_state .game_library .library_sort_type == SE_SORT_ALPHA_ASC ) {
18041804 qsort (gui_state .game_library .sorted_entries , size , sizeof (int ), se_game_library_alpha_comparator );
@@ -5351,12 +5351,14 @@ void se_load_rom_overlay(bool visible){
53515351
53525352 igSameLine (0 ,5 );
53535353 const char * lib_icon = ICON_FK_SORT_ALPHA_ASC ;
5354+ // Validate and correct sort type once if invalid
5355+ if (gui_state .game_library .library_sort_type < SE_SORT_ALPHA_ASC ||
5356+ gui_state .game_library .library_sort_type > SE_SORT_ALPHA_DESC ) {
5357+ gui_state .game_library .library_sort_type = SE_SORT_ALPHA_ASC ;
5358+ }
53545359 switch (gui_state .game_library .library_sort_type ){
53555360 case SE_SORT_ALPHA_ASC : lib_icon = ICON_FK_SORT_ALPHA_ASC ;break ;
53565361 case SE_SORT_ALPHA_DESC :lib_icon = ICON_FK_SORT_ALPHA_DESC ;break ;
5357- default :
5358- gui_state .game_library .library_sort_type = SE_SORT_ALPHA_ASC ;
5359- se_sort_game_library ();
53605362 }
53615363 if (se_button (lib_icon ,(ImVec2 ){40 - 4 ,0 })){
53625364 gui_state .game_library .library_sort_type ++ ;
0 commit comments