17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-09 02:50:59 +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:
maj00r
2026-10-21 08:42:29 +02:00
parent 9696b5f795
commit 4512ed4e0b
36 changed files with 311 additions and 111 deletions

View File

@@ -160,10 +160,12 @@ std::string checked(std::vector<part> const &Parts)
return "The diverging track has no parts";
for (auto const &part : Parts)
{
if (part.length < 0.05)
if (false == (part.length >= 0.05))
return "A part of the diverging track is shorter than 5 cm";
if (part.length > 1000.0)
return "A part of the diverging track is longer than 1000 m";
for (auto const radius : {part.radius1, part.radius2})
if (radius != 0.0 && std::abs(radius) < kMinRadius)
if (std::isnan(radius) || (radius != 0.0 && std::abs(radius) < kMinRadius))
return "A radius of the diverging track is under 10 m";
}
return {};
@@ -362,9 +364,9 @@ shape build(design const &Design, std::string &Error)
bool const mirrored{Design.type == "Rps"};
if (Error.empty() && twofold && false == mirrored && false == Design.parts2.empty())
Error = checked(Design.parts2);
if (Error.empty() && (Design.lead < 0.0 || Design.lead > 30.0))
if (Error.empty() && false == (Design.lead >= 0.0 && Design.lead <= 30.0))
Error = "The pre-blade stretch has to be between 0 and 30 m";
if (Error.empty() && (Design.entry < 0.0 || Design.entry > 5.0))
if (Error.empty() && false == (Design.entry >= 0.0 && Design.entry <= 5.0))
Error = "The angle of the blade has to be between 0 and 5 degrees";
if (false == Error.empty())
return result;