17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-28 19:17:28 +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

@@ -5638,6 +5638,13 @@ void opengl33_renderer::Pick_Node_Callback(std::function<void(scene::basic_node
m_node_pick_requests.push_back(callback);
}
void opengl33_renderer::Forget_Node(scene::basic_node const *Node)
{
if (m_picksceneryitem == Node)
m_picksceneryitem = nullptr;
std::replace_if(m_picksceneryitems.begin(), m_picksceneryitems.end(), [Node](scene::basic_node const *Item) { return Item == Node; }, nullptr);
}
glm::dvec3 opengl33_renderer::Update_Mouse_Position()
{
if (!m_depth_pointer_pbo->is_busy())

View File

@@ -116,6 +116,8 @@ class opengl33_renderer : public gfx_renderer {
Pick_Control() const override { return m_pickcontrolitem; }
scene::basic_node const *
Pick_Node() const override { return m_picksceneryitem; }
void
Forget_Node( scene::basic_node const *Node ) override;
glm::dvec3
Mouse_Position() const override { return m_worldmousecoordinates; }
bool

View File

@@ -1902,6 +1902,15 @@ opengl_renderer::Pick_Node_Callback( std::function<void( scene::basic_node * )>
m_node_pick_requests.emplace_back( Callback );
}
void
opengl_renderer::Forget_Node( scene::basic_node const *Node ) {
if( m_picksceneryitem == Node ) {
m_picksceneryitem = nullptr;
}
std::replace_if( m_picksceneryitems.begin(), m_picksceneryitems.end(), [Node]( scene::basic_node const *Item ) { return Item == Node; }, nullptr );
}
void
opengl_renderer::Render( scene::basic_region *Region ) {

View File

@@ -104,6 +104,8 @@ public:
Pick_Control() const override { return m_pickcontrolitem; }
scene::basic_node const *
Pick_Node() const override { return m_picksceneryitem; }
void
Forget_Node( scene::basic_node const *Node ) override;
glm::dvec3
Mouse_Position() const override { return m_worldmousecoordinates; }
glm::mat4

View File

@@ -96,6 +96,7 @@ public:
virtual void Pick_Node_Callback( std::function<void( scene::basic_node * )> Callback ) = 0;
virtual auto Pick_Control() const -> TSubModel const * = 0;
virtual auto Pick_Node() const -> scene::basic_node const * = 0;
virtual void Forget_Node( scene::basic_node const *Node ) {}
virtual auto Mouse_Position() const -> glm::dvec3 = 0;
virtual auto Mouse_Hit() const -> bool { return true; }