Skip to content

Commit 8591713

Browse files
committedFeb 23, 2016
Sheet Ore: Eliminate crash caused by PcgRandom range max < min
In the calculation of y_start, when 'column height max' was large it caused nmin.Y + max_height > nmax.Y - max_height Now, in this situation y_start is set to the midpoint between nmin.Y and nmax.Y Limit y0 and y1 to between nmin.Y and nmax.Y, otherwise index calculation, which has no checks for limits, places them at unwanted locations in the voxelmanip
1 parent 1474254 commit 8591713

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed
 

‎src/mg_ore.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,12 @@ void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed,
179179
MapNode n_ore(c_ore, 0, ore_param2);
180180

181181
u16 max_height = column_height_max;
182-
int y_start = pr.range(nmin.Y + max_height, nmax.Y - max_height);
182+
int y_start_min = nmin.Y + max_height;
183+
int y_start_max = nmax.Y - max_height;
184+
185+
int y_start = y_start_min < y_start_max ?
186+
pr.range(y_start_min, y_start_max) :
187+
(y_start_min + y_start_max) / 2;
183188

184189
if (!noise) {
185190
int sx = nmax.X - nmin.X + 1;
@@ -204,10 +209,10 @@ void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed,
204209

205210
u16 height = pr.range(column_height_min, column_height_max);
206211
int ymidpoint = y_start + noiseval;
207-
int y0 = ymidpoint - height * (1 - column_midpoint_factor);
208-
int y1 = y0 + height;
212+
int y0 = MYMAX(nmin.Y, ymidpoint - height * (1 - column_midpoint_factor));
213+
int y1 = MYMIN(nmax.Y, y0 + height - 1);
209214

210-
for (int y = y0; y < y1; y++) {
215+
for (int y = y0; y <= y1; y++) {
211216
u32 i = vm->m_area.index(x, y, z);
212217
if (!vm->m_area.contains(i))
213218
continue;

0 commit comments

Comments
 (0)