mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-27 14:07: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:
@@ -144,14 +144,26 @@ void editor_mode::sweep_scan_models()
|
||||
tool.scanned = true;
|
||||
changed = true;
|
||||
std::error_code error;
|
||||
for (auto const &entry : std::filesystem::recursive_directory_iterator("models", std::filesystem::directory_options::skip_permission_denied, error))
|
||||
for (std::filesystem::recursive_directory_iterator entry{"models", std::filesystem::directory_options::skip_permission_denied, error}, end; entry != end; entry.increment(error))
|
||||
{
|
||||
if (false == entry.is_regular_file(error))
|
||||
std::error_code status;
|
||||
if (false == entry->is_regular_file(status))
|
||||
continue;
|
||||
auto const extension{lower(entry.path().extension().string())};
|
||||
if (extension != ".e3d" && extension != ".t3d")
|
||||
std::string extension;
|
||||
std::string name;
|
||||
try
|
||||
{
|
||||
extension = lower(entry->path().extension().string());
|
||||
if (extension != ".e3d" && extension != ".t3d")
|
||||
continue;
|
||||
name = std::filesystem::relative(entry->path(), "models", status).generic_string();
|
||||
}
|
||||
catch (std::exception const &)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (name.size() < extension.size())
|
||||
continue;
|
||||
auto name{std::filesystem::relative(entry.path(), "models", error).generic_string()};
|
||||
name.erase(name.size() - extension.size());
|
||||
tool.models.push_back(name);
|
||||
}
|
||||
@@ -799,9 +811,17 @@ void editor_mode::render_sweep_ui()
|
||||
auto const start{prefix.substr(slash + 1)};
|
||||
std::set<std::string> variants;
|
||||
std::error_code error;
|
||||
for (auto const &entry : std::filesystem::directory_iterator(folder, error))
|
||||
for (std::filesystem::directory_iterator entry{folder, error}, end; entry != end; entry.increment(error))
|
||||
{
|
||||
auto const stem{lower(entry.path().stem().string())};
|
||||
std::string stem;
|
||||
try
|
||||
{
|
||||
stem = lower(entry->path().stem().string());
|
||||
}
|
||||
catch (std::exception const &)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (stem.size() > start.size() + suffix.size() && stem.compare(0, start.size(), start) == 0 && (suffix.empty() || stem.compare(stem.size() - suffix.size(), suffix.size(), lower(suffix)) == 0))
|
||||
variants.insert(stem.substr(start.size(), stem.size() - start.size() - suffix.size()));
|
||||
}
|
||||
@@ -1405,12 +1425,10 @@ void editor_mode::bend_selection()
|
||||
snap.rotation = model->Angles();
|
||||
snap.scale = model->Scale();
|
||||
snap.uuid = model->uuid;
|
||||
nullify_history_pointers(model);
|
||||
remove_from_hierarchy(model);
|
||||
m_node = nullptr;
|
||||
m_dragging = false;
|
||||
ui()->set_node(nullptr);
|
||||
simulation::State.delete_model(model);
|
||||
erase_model(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1463,9 +1481,7 @@ void editor_mode::restore_bend(EditorSnapshot &Snapshot, bool const Undo)
|
||||
}
|
||||
else if (auto *model{dynamic_cast<TAnimModel *>(find_node_by_any(Snapshot.node_ptr, Snapshot.uuid.to_string(), Snapshot.node_name))})
|
||||
{
|
||||
nullify_history_pointers(model);
|
||||
remove_from_hierarchy(model);
|
||||
simulation::State.delete_model(model);
|
||||
erase_model(model);
|
||||
Snapshot.node_ptr = nullptr;
|
||||
m_node = nullptr;
|
||||
ui()->set_node(nullptr);
|
||||
|
||||
Reference in New Issue
Block a user