From 400e7eb9a675614d11434891e2981104d9e14bf6 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Thu, 29 Jan 2015 15:04:16 +0100 Subject: [PATCH] fix glitch in map editor that allowed to violate map borders Also, provide a more detailed error message in case of client fatal due to bad map (with non-solid borders). --- source/src/editing.cpp | 21 +++++++++++++++++++-- source/src/world.cpp | 4 +++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/source/src/editing.cpp b/source/src/editing.cpp index 1dd923a2..8d5e1ff9 100644 --- a/source/src/editing.cpp +++ b/source/src/editing.cpp @@ -175,6 +175,12 @@ COMMANDF(showtagclipfocus, "d", (bool on) { showtagclipfocus = on; } ); VAR(showtagclips, 0, 1, 1); FVAR(tagcliplinewidth, 0.2, 1, 3); +inline void forceinsideborders(int &xy) +{ + if(xy < MINBORD) xy = MINBORD; + if(xy >= ssize - MINBORD) xy = ssize - MINBORD - 1; +} + void cursorupdate() // called every frame from hud { flrceil = ((int)(camera1->pitch>=0))*2; @@ -188,7 +194,13 @@ void cursorupdate() // called every frame fr cx = (int)x; cy = (int)y; - if(OUTBORD(cx, cy)) return; + if(OUTBORD(cx, cy)) + { + forceinsideborders(cx); + forceinsideborders(cy); + return; + } + sqr *s = S(cx,cy); if(fabs(sheight(s,s,z)-z)>1) // selected wall @@ -199,7 +211,12 @@ void cursorupdate() // called every frame fr cx = (int)x; cy = (int)y; - if(OUTBORD(cx, cy)) return; + if(OUTBORD(cx, cy)) + { + forceinsideborders(cx); + forceinsideborders(cy); + return; + } } if(dragging) makesel(false); diff --git a/source/src/world.cpp b/source/src/world.cpp index 332b18af..6a1c7bb6 100644 --- a/source/src/world.cpp +++ b/source/src/world.cpp @@ -457,6 +457,7 @@ void calcmapdims() { if(!SOLID(s)) { + if(OUTBORD(x, y)) conoutf("non-solid cube in world border found: x %d, y %d", x, y); // will also go fatal() below if(x < mapdims.x1) mapdims.x1 = x; if(x > mapdims.x2) mapdims.x2 = x; if(y < mapdims.y1) mapdims.y1 = y; @@ -473,7 +474,8 @@ void calcmapdims() mapdims.minfloor = 0; mapdims.maxceil = 16; } - if(mapdims.x1 < 2 || mapdims.y1 < 2 || mapdims.x2 > ssize - 3 || mapdims.y2 > ssize - 3) fatal("calcmapdims(): border violation"); + if(mapdims.x1 < MINBORD || mapdims.y1 < MINBORD || mapdims.x2 >= ssize - MINBORD || mapdims.y2 >= ssize - MINBORD) + fatal("calcmapdims(): world border violation (x:%d..%d, y:%d..%d)", mapdims.x1, mapdims.x2, mapdims.y1, mapdims.y2); mapdims.xspan = mapdims.x2 - mapdims.x1 + 1; mapdims.yspan = mapdims.y2 - mapdims.y1 + 1; mapdims.xm = mapdims.x1 + mapdims.xspan / 2.0f;