mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-05 08:44:32 +01:00
fix(editor): no crash laying track with the mouse outside the window
- with no position of the mouse the ray gave NaN and the ground under it was looked up in a grid cell out of range; the lay and drag tools keep the last cursor then, the ground is not asked about points which are not numbers
This commit is contained in:
@@ -567,6 +567,8 @@ std::vector<double> editor_mode::ground_heights(std::vector<glm::dvec3> const &P
|
|||||||
for (std::size_t i = 0; i < Points.size(); ++i)
|
for (std::size_t i = 0; i < Points.size(); ++i)
|
||||||
{
|
{
|
||||||
auto const &p = Points[i];
|
auto const &p = Points[i];
|
||||||
|
if (false == std::isfinite(p.x) || false == std::isfinite(p.y) || false == std::isfinite(p.z))
|
||||||
|
continue;
|
||||||
std::pair<int, int> const key{static_cast<int>(std::floor(p.x / ground_tile_size)), static_cast<int>(std::floor(p.z / ground_tile_size))};
|
std::pair<int, int> const key{static_cast<int>(std::floor(p.x / ground_tile_size)), static_cast<int>(std::floor(p.z / ground_tile_size))};
|
||||||
auto &tile = ground_tiles[key];
|
auto &tile = ground_tiles[key];
|
||||||
bool const missing = (tile.grid == nullptr);
|
bool const missing = (tile.grid == nullptr);
|
||||||
|
|||||||
@@ -3866,9 +3866,11 @@ void editor_mode::update_build_tools()
|
|||||||
m_join_radius = 0.0;
|
m_join_radius = 0.0;
|
||||||
m_join_variant = 0;
|
m_join_variant = 0;
|
||||||
};
|
};
|
||||||
|
bool const pointing{m_cursor_override.has_value() || ImGui::IsMousePosValid()};
|
||||||
if (m_extend.active)
|
if (m_extend.active)
|
||||||
{
|
{
|
||||||
m_extend.mouse = cursor_terrain(m_extend.point.y);
|
if (pointing)
|
||||||
|
m_extend.mouse = cursor_terrain(m_extend.point.y);
|
||||||
typed_extend();
|
typed_extend();
|
||||||
m_extend.snap = m_typed.empty() && m_extend.track != nullptr ? snap_free_end(m_extend.mouse, cursor, m_extend.track, m_extend.track->iCategoryFlag & 15, {m_extend.track}) : editor_track::snap_target{};
|
m_extend.snap = m_typed.empty() && m_extend.track != nullptr ? snap_free_end(m_extend.mouse, cursor, m_extend.track, m_extend.track->iCategoryFlag & 15, {m_extend.track}) : editor_track::snap_target{};
|
||||||
if (m_extend.snap.track == nullptr)
|
if (m_extend.snap.track == nullptr)
|
||||||
@@ -3885,7 +3887,8 @@ void editor_mode::update_build_tools()
|
|||||||
return;
|
return;
|
||||||
// geometric ray, same as extend: Mouse_Position() is a delayed depth pick and lags the cursor
|
// geometric ray, same as extend: Mouse_Position() is a delayed depth pick and lags the cursor
|
||||||
double const height{false == lay.points.empty() ? lay.points.back().y : lay.start.track != nullptr ? lay.start.position.y : ground.y};
|
double const height{false == lay.points.empty() ? lay.points.back().y : lay.start.track != nullptr ? lay.start.position.y : ground.y};
|
||||||
lay.mouse = typed_lay(cursor_terrain(height));
|
if (pointing)
|
||||||
|
lay.mouse = typed_lay(cursor_terrain(height));
|
||||||
lay.mouse_snap = m_typed.empty() ? snap_free_end(lay.mouse, cursor, nullptr, kRailCategory, {}) : editor_track::find_free_end(nullptr, kRailCategory, lay.mouse, kLaySnapRadius, {});
|
lay.mouse_snap = m_typed.empty() ? snap_free_end(lay.mouse, cursor, nullptr, kRailCategory, {}) : editor_track::find_free_end(nullptr, kRailCategory, lay.mouse, kLaySnapRadius, {});
|
||||||
if (lay.mouse_snap.track == nullptr)
|
if (lay.mouse_snap.track == nullptr)
|
||||||
lay.mouse = lay_bed(lay.mouse);
|
lay.mouse = lay_bed(lay.mouse);
|
||||||
@@ -3988,7 +3991,7 @@ glm::dvec3 editor_mode::cursor_ground() const
|
|||||||
glm::dvec3 editor_mode::cursor_terrain(double const Height)
|
glm::dvec3 editor_mode::cursor_terrain(double const Height)
|
||||||
{
|
{
|
||||||
auto point{cursor_level(Height)};
|
auto point{cursor_level(Height)};
|
||||||
for (int i = 0; i < 5; ++i)
|
for (int i = 0; i < 5 && std::isfinite(point.x) && std::isfinite(point.z); ++i)
|
||||||
{
|
{
|
||||||
std::vector<char> found;
|
std::vector<char> found;
|
||||||
auto const heights{ground_heights({point}, true, &found)};
|
auto const heights{ground_heights({point}, true, &found)};
|
||||||
|
|||||||
Reference in New Issue
Block a user