Skip to content

Commit 9f108b5

Browse files
paramatsfan5
authored andcommittedJan 25, 2017
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.
1 parent 0891116 commit 9f108b5

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
 

‎src/dungeongen.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ void DungeonGen::makeCorridor(v3s16 doorplace, v3s16 doordir,
415415
if (partcount != 0)
416416
p.Y += make_stairs;
417417

418-
if (vm->m_area.contains(p) && vm->m_area.contains(p + v3s16(0, 1, 0)) &&
419-
vm->m_area.contains(v3s16(p.X - dir.X, p.Y - 1, p.Z - dir.Z))) {
418+
// Check segment of minimum size corridor is in voxelmanip
419+
if (vm->m_area.contains(p) && vm->m_area.contains(p + v3s16(0, 1, 0))) {
420420
if (make_stairs) {
421421
makeFill(p + v3s16(-1, -1, -1),
422422
dp.holesize + v3s16(2, 3, 2),
@@ -444,11 +444,13 @@ void DungeonGen::makeCorridor(v3s16 doorplace, v3s16 doordir,
444444

445445
for (u16 st = 0; st < stair_width; st++) {
446446
u32 vi = vm->m_area.index(ps.X - dir.X, ps.Y - 1, ps.Z - dir.Z);
447-
if (vm->m_data[vi].getContent() == dp.c_wall)
447+
if (vm->m_area.contains(ps + v3s16(-dir.X, -1, -dir.Z)) &&
448+
vm->m_data[vi].getContent() == dp.c_wall)
448449
vm->m_data[vi] = MapNode(dp.c_stair, 0, facedir);
449450

450451
vi = vm->m_area.index(ps.X, ps.Y, ps.Z);
451-
if (vm->m_data[vi].getContent() == dp.c_wall)
452+
if (vm->m_area.contains(ps) &&
453+
vm->m_data[vi].getContent() == dp.c_wall)
452454
vm->m_data[vi] = MapNode(dp.c_stair, 0, facedir);
453455

454456
ps += swv;

0 commit comments

Comments
 (0)
Please sign in to comment.