diff options
author | paramat <mat.gregory@virginmedia.com> | 2017-01-25 15:23:29 +0000 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2017-01-25 20:34:03 +0100 |
commit | 9f108b56d35cb607b538562ac369c457cd129eaa (patch) | |
tree | 5e79323313fa472f9cab12f99faa8806aa921ed5 | |
parent | 08911160aa5294883a7ebfb681fbf0c1a858dc78 (diff) | |
download | minetest-9f108b56d35cb607b538562ac369c457cd129eaa.tar.gz minetest-9f108b56d35cb607b538562ac369c457cd129eaa.tar.bz2 minetest-9f108b56d35cb607b538562ac369c457cd129eaa.zip |
Dungeongen: Fix out-of-voxelmanip access segfault
My recent dungeon commit allowed stairs to be placed across the full
width of corridors, but some of the new node positions accessed were
missing checks for being within the voxelmanip, causing occasional
segfaults near dungeons with corridors wider than 1 node.
Add 'vm->m_area.contains(pos)' checks just before stair position
voxelmanip access. This allows an earlier check to be removed as it
is now redundant.
-rw-r--r-- | src/dungeongen.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/dungeongen.cpp b/src/dungeongen.cpp index 5dc87f8b0..b8ee2b924 100644 --- a/src/dungeongen.cpp +++ b/src/dungeongen.cpp @@ -415,8 +415,8 @@ void DungeonGen::makeCorridor(v3s16 doorplace, v3s16 doordir, if (partcount != 0) p.Y += make_stairs; - if (vm->m_area.contains(p) && vm->m_area.contains(p + v3s16(0, 1, 0)) && - vm->m_area.contains(v3s16(p.X - dir.X, p.Y - 1, p.Z - dir.Z))) { + // Check segment of minimum size corridor is in voxelmanip + if (vm->m_area.contains(p) && vm->m_area.contains(p + v3s16(0, 1, 0))) { if (make_stairs) { makeFill(p + v3s16(-1, -1, -1), dp.holesize + v3s16(2, 3, 2), @@ -444,11 +444,13 @@ void DungeonGen::makeCorridor(v3s16 doorplace, v3s16 doordir, for (u16 st = 0; st < stair_width; st++) { u32 vi = vm->m_area.index(ps.X - dir.X, ps.Y - 1, ps.Z - dir.Z); - if (vm->m_data[vi].getContent() == dp.c_wall) + if (vm->m_area.contains(ps + v3s16(-dir.X, -1, -dir.Z)) && + vm->m_data[vi].getContent() == dp.c_wall) vm->m_data[vi] = MapNode(dp.c_stair, 0, facedir); vi = vm->m_area.index(ps.X, ps.Y, ps.Z); - if (vm->m_data[vi].getContent() == dp.c_wall) + if (vm->m_area.contains(ps) && + vm->m_data[vi].getContent() == dp.c_wall) vm->m_data[vi] = MapNode(dp.c_stair, 0, facedir); ps += swv; |