From: sfan5 Date: Tue, 16 Jul 2019 21:18:27 +0000 (+0200) Subject: Fix potential crash when few loot items are registered X-Git-Tag: 5.1.0~47 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=773011fd854e4beb1958db27a660b52b7eb325d8;p=oweals%2Fminetest_game.git Fix potential crash when few loot items are registered --- diff --git a/mods/dungeon_loot/mapgen.lua b/mods/dungeon_loot/mapgen.lua index 4a19f3cf..624e9a85 100644 --- a/mods/dungeon_loot/mapgen.lua +++ b/mods/dungeon_loot/mapgen.lua @@ -76,8 +76,8 @@ local function populate_chest(pos, rand, dungeontype) local item_list = dungeon_loot._internal_get_loot(pos.y, dungeontype) -- take random (partial) sample of all possible items - assert(#item_list >= dungeon_loot.STACKS_PER_CHEST_MAX) - item_list = random_sample(rand, item_list, dungeon_loot.STACKS_PER_CHEST_MAX) + local sample_n = math.min(#item_list, dungeon_loot.STACKS_PER_CHEST_MAX) + item_list = random_sample(rand, item_list, sample_n) -- apply chances / randomized amounts and collect resulting items local items = {}