Don't crash when culling volume position is too large

This commit is contained in:
Ashley Rogers 2025-01-24 15:42:45 -05:00
parent 07676373c3
commit e16c56228b
5 changed files with 31 additions and 126 deletions

122
.vscode/settings.json vendored
View File

@ -1,122 +0,0 @@
{
"files.associations": {
"variant": "cpp",
"cmath": "cpp",
"xutility": "cpp",
"random": "cpp",
"optional": "cpp",
"type_traits": "cpp",
"algorithm": "cpp",
"array": "cpp",
"atomic": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"clocale": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"deque": "cpp",
"exception": "cpp",
"forward_list": "cpp",
"fstream": "cpp",
"functional": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"numeric": "cpp",
"ostream": "cpp",
"queue": "cpp",
"ratio": "cpp",
"regex": "cpp",
"set": "cpp",
"sstream": "cpp",
"stack": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"system_error": "cpp",
"thread": "cpp",
"tuple": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"utility": "cpp",
"valarray": "cpp",
"vector": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"pointers": "cpp",
"gsl_util": "cpp",
"span": "cpp",
"string_span": "cpp",
"gsl_algorithm": "cpp",
"gsl_byte": "cpp",
"span_ext": "cpp",
"multi_span": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cwctype": "cpp",
"memory_resource": "cpp",
"string_view": "cpp",
"shared_mutex": "cpp",
"gsl_assert": "cpp",
"compare": "cpp",
"resumable": "cpp",
"codecvt": "cpp",
"ranges": "cpp",
"scoped_allocator": "cpp",
"typeindex": "cpp",
"any": "cpp",
"csignal": "cpp",
"filesystem": "cpp",
"stop_token": "cpp",
"xmemory0": "cpp",
"charconv": "cpp",
"format": "cpp",
"coroutine": "cpp",
"*.idl": "cpp",
"assert": "cpp",
"cfenv": "cpp",
"ktxint.h": "c",
"texture.h": "c",
"gl_format.h": "c",
"complex": "cpp",
"expected": "cpp"
},
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"cmake.configureOnOpen": true
}

View File

@ -175,7 +175,7 @@ private:
const double _sseDenominator;
const std::optional<CesiumGeospatial::Cartographic> _positionCartographic;
const CullingVolume _cullingVolume;
const CesiumGeometry::CullingVolume _cullingVolume;
};
} // namespace Cesium3DTilesSelection

View File

@ -2,7 +2,7 @@
#include <CesiumGeometry/Plane.h>
namespace Cesium3DTilesSelection {
namespace CesiumGeometry {
/**
* @brief A culling volume, defined by four planes.

View File

@ -5,7 +5,9 @@
#include <glm/geometric.hpp>
#include <glm/trigonometric.hpp>
namespace Cesium3DTilesSelection {
#include <cmath>
namespace CesiumGeometry {
CullingVolume createCullingVolume(
const glm::dvec3& position,
@ -18,7 +20,8 @@ CullingVolume createCullingVolume(
const double r = glm::tan(0.5 * fovx);
const double l = -r;
const double n = 1.0;
const double positionLen = glm::length(position);
const double n = std::max(1.0, std::nextafter(positionLen, std::numeric_limits<double>::max()) - positionLen);
// TODO: this is all ported directly from CesiumJS, can probably be refactored
// to be more efficient with GLM.

View File

@ -0,0 +1,24 @@
#include <CesiumGeometry/CullingVolume.h>
#include <CesiumUtility/Math.h>
#include <doctest/doctest.h>
#include <glm/ext/matrix_transform.hpp>
#include <glm/ext/vector_double3.hpp>
#include <glm/fwd.hpp>
#include <glm/gtx/euler_angles.hpp>
#include <cmath>
using namespace doctest;
using namespace CesiumGeometry;
using namespace CesiumUtility;
TEST_CASE("CullingVolume::createCullingVolume") {
SUBCASE("Shouldn't crash when too far from the globe") {
CHECK_NOTHROW(createCullingVolume(glm::dvec3(1e20, 1e20, 1e20), glm::dvec3(0, 0, 1), glm::dvec3(0, 1, 0), Math::PiOverTwo, Math::PiOverTwo));
}
SUBCASE("Shouldn't crash at the center of the globe") {
CHECK_NOTHROW(createCullingVolume(glm::dvec3(0, 0, 0), glm::dvec3(0, 0, 1), glm::dvec3(0, 1, 0), Math::PiOverTwo, Math::PiOverTwo));
}
}