18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-03 10:05:23 +01:00

fix(editor): the brush keeps its models when the step of the stroke is gone from the history (Sonar)

A stroke held long enough for its step to be trimmed from the history took the step as null and the next model crashed the
editor (Sonar S2259 in editormodebrush.cpp). The rest of the stroke now goes to a step of its own, which Ctrl+Z takes back.

The other notes of the analysis, with no change of behaviour: the fill loops test their counter only and stop on the limit
inside (S886), brush_on_line() is const, the step is found with std::to_address, the line shape of the brush is
shape::along_line (it shadowed the line settings, S1117), and the test of the picks without finite settings is a helper
(S134), with std::numbers::pi in the density test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1p6qPUo2Cgx4KaVYU
This commit is contained in:
miloszunio
2026-12-01 20:29:37 +01:00
parent a87a94d36d
commit 1a6d2bbc2f
6 changed files with 47 additions and 25 deletions
+11 -5
View File
@@ -21,6 +21,7 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/translation.h"
#include <algorithm>
#include <memory>
#include <array>
#include <cmath>
#include <numbers>
@@ -82,7 +83,7 @@ void editor_mode::brush_press()
m_brush_has_last = false;
m_brush_done = {};
auto const &settings{ui()->brush()};
if (settings.way != brush_object_list::kind::single && settings.stroke == brush_object_list::shape::line)
if (settings.way != brush_object_list::kind::single && settings.stroke == brush_object_list::shape::along_line)
{
// a point of the line, read once the renderer has the depth under the cursor
GfxRenderer->Pick_Node_Callback([this](scene::basic_node * /*node*/) { brush_line_point(); });
@@ -160,6 +161,8 @@ void editor_mode::brush_dab()
// the step of the stroke is looked up by its serial for each model, never taken for the last one of the history: a
// step another key pushed while the button is held (Del) doesn't get the models of the stroke
auto *stroke{brush_step(true)};
if (stroke == nullptr)
continue;
EditorSnapshot::array_copy copy;
copy.model = model;
copy.uuid = model->uuid;
@@ -174,7 +177,10 @@ editor_mode::EditorSnapshot *editor_mode::brush_step(bool const Make)
{
// from the end: the step of the stroke is the last one, or among the last
auto const found{std::ranges::find_if(m_history.rbegin(), m_history.rend(), [this](EditorSnapshot const &Step) { return Step.serial == m_brush_step; })};
return found != m_history.rend() ? &*found : nullptr;
if (found != m_history.rend())
return std::to_address(found);
// the step is gone from the history (trimmed while the button is held): the rest of the stroke goes to a step of its own
m_brush_step = 0;
}
if (false == Make)
return nullptr;
@@ -214,10 +220,10 @@ void editor_mode::end_brush_stroke()
ui()->set_status(format(STR_C("Brush: %zu models put; Ctrl+Z takes the whole stroke back"), step->copies.size()));
}
bool editor_mode::brush_on_line()
bool editor_mode::brush_on_line() const
{
auto const &settings{ui()->brush()};
return ui()->mode() == nodebank_panel::BRUSH && settings.way == brush_object_list::kind::multi && settings.stroke == brush_object_list::shape::line;
return ui()->mode() == nodebank_panel::BRUSH && settings.way == brush_object_list::kind::multi && settings.stroke == brush_object_list::shape::along_line;
}
void editor_mode::brush_line_point()
@@ -313,7 +319,7 @@ void editor_mode::draw_brush_cursor()
{
auto const &settings{ui()->brush()};
auto const many{settings.way == brush_object_list::kind::multi};
auto const on_line{many && settings.stroke == brush_object_list::shape::line};
auto const on_line{many && settings.stroke == brush_object_list::shape::along_line};
glm::dvec3 centre;
auto const on_ground{brush_ground(centre)};
if (on_line)