Skip to content

Commit 922e6ff

Browse files
authoredJan 25, 2019
blitToVManip: Check out-of-bounds using node position not index (#8127)
Previously, when using 'place on vmanip' to add a schematic to a lua voxelmanip, if part of the schematic was outside the voxelmanip volume, the outside part would often appear in a strange place elsewhere inside the voxelmanip instead of being trimmed off. This was due to the out-of-bounds check checking the index. A position outside the voxelmanip can have an index that satisfies '0 <= index <= voxelmanip volume', causing the node to be placed at a strange position inside the voxelmanip. Use 'vm->m_area.contains(pos)' instead. Move index calculation to later in the code to optimise.
1 parent bc1e547 commit 922e6ff

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed
 

‎src/mapgen/mg_schematic.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ void Schematic::blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_pla
137137
for (s16 z = 0; z != sz; z++) {
138138
u32 i = z * i_step_z + y * ystride + i_start;
139139
for (s16 x = 0; x != sx; x++, i += i_step_x) {
140-
u32 vi = vm->m_area.index(p.X + x, y_map, p.Z + z);
141-
if (!vm->m_area.contains(vi))
140+
v3s16 pos(p.X + x, y_map, p.Z + z);
141+
if (!vm->m_area.contains(pos))
142142
continue;
143143

144144
if (schemdata[i].getContent() == CONTENT_IGNORE)
@@ -150,6 +150,7 @@ void Schematic::blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_pla
150150
if (placement_prob == MTSCHEM_PROB_NEVER)
151151
continue;
152152

153+
u32 vi = vm->m_area.index(pos);
153154
if (!force_place && !force_place_node) {
154155
content_t c = vm->m_data[vi].getContent();
155156
if (c != CONTENT_AIR && c != CONTENT_IGNORE)

0 commit comments

Comments
 (0)