mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-31 20:29:04 +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:
@@ -23,7 +23,7 @@ bool ui::scenerylist_panel::on_key(int key, int action)
|
||||
if (it == keyboard.keytonamemap.end())
|
||||
return false;
|
||||
|
||||
if (Global.ctrlState && it->second == "delete")
|
||||
if (Global.ctrlState && it->second == "delete" && selected_trainset != nullptr)
|
||||
purge_selected_trainset();
|
||||
|
||||
return true;
|
||||
@@ -117,7 +117,7 @@ void ui::scenerylist_panel::draw_launch_box()
|
||||
{
|
||||
ImGui::NextColumn();
|
||||
|
||||
ImGui::TextWrapped(selected_trainset->description.c_str());
|
||||
ImGui::TextWrapped("%s", selected_trainset->description.c_str());
|
||||
|
||||
ImGui::Checkbox(STR_C("Trainset turned around"), &selected_trainset->reversed);
|
||||
if (ImGui::IsItemHovered())
|
||||
@@ -283,7 +283,8 @@ void ui::scenerylist_panel::draw_trainset(trainset_desc &trainset)
|
||||
draw_droptarget(trainset, position++);
|
||||
ImGui::SameLine(15.0f);
|
||||
|
||||
for (auto &dyn_desc : trainset.vehicles) {
|
||||
for (std::size_t index = 0; index < trainset.vehicles.size(); ++index) {
|
||||
auto &dyn_desc = trainset.vehicles[index];
|
||||
deferred_image *mini = nullptr;
|
||||
|
||||
if (dyn_desc.skin && dyn_desc.skin->mini.get() != deferred_image::invalid_id)
|
||||
@@ -345,16 +346,19 @@ void ui::scenerylist_panel::draw_droptarget(trainset_desc &trainset, int positio
|
||||
if (payload) {
|
||||
skin_set *ptr = *reinterpret_cast<skin_set **>(payload->Data);
|
||||
std::shared_ptr<skin_set> skin;
|
||||
for (auto &s : ptr->vehicle.lock()->matching_skinsets)
|
||||
if (s.get() == ptr)
|
||||
skin = s;
|
||||
if (auto const vehicle = ptr->vehicle.lock())
|
||||
for (auto &s : vehicle->matching_skinsets)
|
||||
if (s.get() == ptr)
|
||||
skin = s;
|
||||
|
||||
trainset.vehicles.emplace(trainset.vehicles.begin() + position);
|
||||
dynamic_desc &desc = trainset.vehicles[position];
|
||||
if (skin) {
|
||||
trainset.vehicles.emplace(trainset.vehicles.begin() + position);
|
||||
dynamic_desc &desc = trainset.vehicles[position];
|
||||
|
||||
desc.name = skin->skin + "_" + std::to_string((int)LocalRandom(0.0, 10000000.0));
|
||||
desc.vehicle = skin->vehicle.lock();
|
||||
desc.skin = skin;
|
||||
desc.name = skin->skin + "_" + std::to_string((int)LocalRandom(0.0, 10000000.0));
|
||||
desc.vehicle = skin->vehicle.lock();
|
||||
desc.skin = skin;
|
||||
}
|
||||
}
|
||||
|
||||
payload = ImGui::AcceptDragDropPayload("vehicle_set");
|
||||
@@ -368,7 +372,7 @@ void ui::scenerylist_panel::draw_droptarget(trainset_desc &trainset, int positio
|
||||
if (moved->position < position)
|
||||
offset = -1;
|
||||
} else {
|
||||
desc_copy.name = desc_copy.skin->skin + "_" + std::to_string((int)LocalRandom(0.0, 10000000.0));
|
||||
desc_copy.name = (desc_copy.skin ? desc_copy.skin->skin : desc_copy.name) + "_" + std::to_string((int)LocalRandom(0.0, 10000000.0));
|
||||
}
|
||||
|
||||
trainset.vehicles.insert(trainset.vehicles.begin() + position + offset, desc_copy);
|
||||
|
||||
Reference in New Issue
Block a user