mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-03 01:30:16 +01:00
fix(editor): guard the places where the editor could crash outright
Found with an address and undefined behaviour sanitizer build, random monkey sessions on the test sceneries and broken inputs: - A deleted model left its pointer in the pick list of the renderer, the bound node of the panels, the bindings of the infrastructure and the selection: the next pick or panel frame read freed memory. The renderer forgets it, and one erase_model does the cleaning for all the places which deleted a model by hand. - The plan band of a route read the vertex before the first one in the frame a drag was let go. - A scenery which can't be opened goes back to the launcher with the reason in the log, a track of an unknown type or a tributary loads as a normal track or a river with a message, and a spline with no finite length or step gets a sane number of segments. - Typed numbers which aren't (NaN, inf, ends 0 m or 1000 km apart, a vector of 1e30, a diverging track part of 5 km, a curve threshold of 0, a zero history size, radius norms below zero) are refused or clamped, where they made the geometry run away or divide by zero. - Folders which can't be read and file names which aren't valid in the locale no longer throw out of the scans of sceneries, textures, sweeps, roads and signal plates; the scans skip them. - The launcher: Ctrl+Del with no trainset selected, a dropped vehicle whose skin is gone and a text with a percent sign. - A terrain mesh made for another resolution of its chunk isn't put into the chunk, and a slot is reused only for a mesh of the same size. - Vehicles on a track changed by the editor are moved over a copy of the list they leave. - The table of the keyboard shortcuts gives its stretched column a weight, else ImGui divides 0 by 0 in the first frame of the window.
This commit is contained in:
@@ -1345,6 +1345,7 @@ void editor_mode::render_path_ui()
|
||||
}
|
||||
};
|
||||
|
||||
auto const finite = [](glm::dvec3 const &Point) { return std::isfinite(Point.x) && std::isfinite(Point.y) && std::isfinite(Point.z); };
|
||||
if (ImGui::CollapsingHeader(track->eType == tt_Switch ? STR_C("Geometry of the paths") : STR_C("Geometry")))
|
||||
{
|
||||
for (int i = 0; i < static_cast<int>(track->m_paths.size()); ++i)
|
||||
@@ -1381,7 +1382,7 @@ void editor_mode::render_path_ui()
|
||||
if (editor_track::is_end(kind))
|
||||
{
|
||||
auto position = path.points[kind == editor_track::point_kind::start ? segment_data::point::start : segment_data::point::end];
|
||||
if (ImGui::DragScalarN("x, y, z##point", ImGuiDataType_Double, glm::value_ptr(position), 3, 0.01f, nullptr, nullptr, "%.3f"))
|
||||
if (ImGui::DragScalarN("x, y, z##point", ImGuiDataType_Double, glm::value_ptr(position), 3, 0.01f, nullptr, nullptr, "%.3f") && finite(position))
|
||||
editor_track::move_point(*track, m_track_point, position);
|
||||
item_tooltip("Drag to move, Ctrl+click to type the value");
|
||||
finish_edit(rebuild::geometry);
|
||||
@@ -1389,7 +1390,9 @@ void editor_mode::render_path_ui()
|
||||
else
|
||||
{
|
||||
auto &vector{path.points[kind == editor_track::point_kind::control1 ? segment_data::point::control1 : segment_data::point::control2]};
|
||||
ImGui::DragScalarN(STR_C("vector##point"), ImGuiDataType_Double, glm::value_ptr(vector), 3, 0.01f, nullptr, nullptr, "%.3f");
|
||||
auto typed{vector};
|
||||
if (ImGui::DragScalarN(STR_C("vector##point"), ImGuiDataType_Double, glm::value_ptr(typed), 3, 0.01f, nullptr, nullptr, "%.3f") && finite(typed) && glm::length(typed) < 1e5)
|
||||
vector = typed;
|
||||
item_tooltip("Control vector, relative to its end; zero for a straight");
|
||||
finish_edit(rebuild::geometry);
|
||||
}
|
||||
@@ -1399,11 +1402,13 @@ void editor_mode::render_path_ui()
|
||||
if (begin_fields("##cantradius", 0.3f))
|
||||
{
|
||||
field_row("Roll (deg)");
|
||||
ImGui::DragFloat2("##roll", path.rolls.data(), 0.01f, -15.0f, 15.0f, "%.2f");
|
||||
if (auto rolls{path.rolls}; ImGui::DragFloat2("##roll", rolls.data(), 0.01f, -15.0f, 15.0f, "%.2f") && std::isfinite(rolls[0]) && std::isfinite(rolls[1]))
|
||||
path.rolls = rolls;
|
||||
item_tooltip("Cant at the start and at the end as the roll angle of the track");
|
||||
finish_edit(rebuild::geometry);
|
||||
field_row("Radius");
|
||||
ImGui::InputFloat("##radius", &path.radius, 0.0f, 0.0f, "%.1f");
|
||||
if (auto radius{path.radius}; ImGui::InputFloat("##radius", &radius, 0.0f, 0.0f, "%.1f") && std::isfinite(radius))
|
||||
path.radius = radius;
|
||||
item_tooltip("Radius stored with the path in the scenery; the shape itself comes from the control vectors");
|
||||
finish_edit(rebuild::geometry);
|
||||
ImGui::EndTable();
|
||||
|
||||
Reference in New Issue
Block a user