mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Fix seg fault if popping from empty stack (L-system trees)
See: https://github.com/minetest/minetest/issues/1525 Background Wuzzy2: If you attempt to spawn a L-system tree with minetest.spawn_tree, you can make Minetest crash if it is attempted to pop an empty stack. ShadowNinja: This shouldn't cause a segmentation fault, but it should throw a Lua error Commit Description This commit throws a Lua error instead of causing a segmentation fault. The server will still "crash" but will include a Lua backtrace. L-Systems fix randomness Unless a random seed is provided (via Lua treedef) seed the PRNG with a different seed for each tree Resolves: https://github.com/minetest/minetest/issues/1469 Fix l-system crash when treedef random_level not set by Lua
This commit is contained in:
parent
996ea60642
commit
f33d31693e
4 changed files with 45 additions and 10 deletions
|
@ -747,7 +747,8 @@ int ModApiEnvMod::l_spawn_tree(lua_State *L)
|
|||
}
|
||||
getintfield(L, 2, "angle", tree_def.angle);
|
||||
getintfield(L, 2, "iterations", tree_def.iterations);
|
||||
getintfield(L, 2, "random_level", tree_def.iterations_random_level);
|
||||
if (!getintfield(L, 2, "random_level", tree_def.iterations_random_level))
|
||||
tree_def.iterations_random_level = 0;
|
||||
getstringfield(L, 2, "trunk_type", tree_def.trunk_type);
|
||||
getboolfield(L, 2, "thin_branches", tree_def.thin_branches);
|
||||
tree_def.fruit_chance=0;
|
||||
|
@ -757,11 +758,20 @@ int ModApiEnvMod::l_spawn_tree(lua_State *L)
|
|||
tree_def.fruitnode=ndef->getId(fruit);
|
||||
getintfield(L, 2, "fruit_chance",tree_def.fruit_chance);
|
||||
}
|
||||
getintfield(L, 2, "seed", tree_def.seed);
|
||||
tree_def.explicit_seed = getintfield(L, 2, "seed", tree_def.seed);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
treegen::spawn_ltree (env, p0, ndef, tree_def);
|
||||
|
||||
treegen::error e;
|
||||
if ((e = treegen::spawn_ltree (env, p0, ndef, tree_def)) != treegen::SUCCESS) {
|
||||
if (e == treegen::UNBALANCED_BRACKETS) {
|
||||
luaL_error(L, "spawn_tree(): closing ']' has no matching opening bracket");
|
||||
} else {
|
||||
luaL_error(L, "spawn_tree(): unknown error");
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue