fix crash on play/start with empty world list
authorsapier <Sapier at GMX dot net>
Mon, 8 Jul 2013 19:02:42 +0000 (21:02 +0200)
committerkwolekr <kwolekr@minetest.net>
Mon, 8 Jul 2013 23:58:03 +0000 (19:58 -0400)
make enter button work in create world dialog

builtin/mainmenu.lua
src/main.cpp

index 6670a5eb81765e556d3d34780047d1101c3b2885..30cff823e5b99a5335e13a12f32fac300b947d56 100644 (file)
@@ -332,6 +332,10 @@ function menu.filtered_index_to_plain(filtered_index)
        
        local temp_idx = 0
        
+       if menu.worldlist == nil then
+               return -1
+       end
+       
        for i=1,#menu.worldlist,1 do
                if menu.worldlist[i].gameid == current_game.id then
                        temp_idx = temp_idx +1
@@ -418,6 +422,10 @@ function menu.update_last_game(world_idx)
        if gamedata.selected_world <= #menu.worldlist then
                local world = menu.worldlist[gamedata.selected_world]
                
+               if world == nil then
+                       return
+               end
+               
                for i=1,#gamemgr.games,1 do             
                        if gamemgr.games[i].id == world.gameid then
                                menu.last_game = i
@@ -574,7 +582,8 @@ end
 --------------------------------------------------------------------------------
 function tabbuilder.handle_create_world_buttons(fields)
        
-       if fields["world_create_confirm"] then
+       if fields["world_create_confirm"] or
+               fields["key_enter"] then
                
                local worldname = fields["te_world_name"]
                local gameindex = engine.get_textlist_index("games")
index 02bffa84d5253bbf03639ad17c9dcc130d20e8fd..580260adea7ffd3c10928d00365a48a1436a6d8a 100644 (file)
@@ -1667,7 +1667,8 @@ int main(int argc, char *argv[])
                                }
                                
                                // Set world path to selected one
-                               if(menudata.selected_world != -1){
+                               if ((menudata.selected_world >= 0) &&
+                                       (menudata.selected_world < worldspecs.size())) {
                                        worldspec = worldspecs[menudata.selected_world];
                                        infostream<<"Selected world: "<<worldspec.name
                                                        <<" ["<<worldspec.path<<"]"<<std::endl;