18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-14 03:07:59 +01:00

fix: a deleted model is no longer the picked node, an orthophoto tile isn't swept as a grey stub, the ED brake arrays freed

Deleting a model in the editor left the renderer holding it as the picked node, the next pick used freed memory: the renderer forgets it now (Forget_Node). A texture filled straight from memory (internalsrc:) can't be read again, released by the garbage sweep it came back grey; it stays now, and the units bound with the old name are rebound. The arrays of the ED brake force sharing are vectors, they leaked once per update. The scene hierarchy and the editor menu items go through the translation. Python caches ignored.
This commit is contained in:
maj00r
2026-11-03 21:45:58 +01:00
parent 0d69059448
commit e230d7b902
10 changed files with 47 additions and 17 deletions

2
.gitignore vendored
View File

@@ -24,3 +24,5 @@ vcpkg.json
# Local Python (setup.bat / CMake) for embedding # Local Python (setup.bat / CMake) for embedding
tools/python314/ tools/python314/
__pycache__/
*.pyc

View File

@@ -567,7 +567,7 @@ void ui_layer::render_hierarchy(){
// fitted to the contents when it first appears; no auto resize, which a docked window can't do // fitted to the contents when it first appears; no auto resize, which a docked window can't do
ImGui::SetNextWindowSize(ImVec2(0, 0), ImGuiCond_FirstUseEver); ImGui::SetNextWindowSize(ImVec2(0, 0), ImGuiCond_FirstUseEver);
ImGui::Begin((std::string(STR_C("Scene Hierarchy")) + "###scenehierarchy").c_str(), &m_editor_hierarchy); ImGui::Begin((std::string(STR_C("Scene Hierarchy")) + "###scenehierarchy").c_str(), &m_editor_hierarchy);
ImGui::Text("Registered nodes: %zu", scene::Hierarchy.size()); ImGui::Text(STR_C("Registered nodes: %zu"), scene::Hierarchy.size());
ImGui::BeginChild("hierarchy_list", ImVec2(500, 300), true); ImGui::BeginChild("hierarchy_list", ImVec2(500, 300), true);
for (auto &entry : scene::Hierarchy) for (auto &entry : scene::Hierarchy)
@@ -598,7 +598,7 @@ void ui_layer::render_hierarchy(){
if (ImGui::IsItemHovered()) if (ImGui::IsItemHovered())
{ {
ImGui::SetTooltip("UUID: %s\nNode type: %s", uuid.c_str(), typeid(*node).name()); ImGui::SetTooltip(STR_C("UUID: %s\nNode type: %s"),uuid.c_str(), typeid(*node).name());
} }
} }
} }
@@ -708,14 +708,14 @@ void ui_layer::render_menu_contents()
GfxRenderer->Debug_Ui_State(ret); GfxRenderer->Debug_Ui_State(ret);
} }
if(EditorModeFlag){ if(EditorModeFlag){
ImGui::MenuItem("Hierarchy", nullptr, &m_editor_hierarchy); ImGui::MenuItem(STR_C("Scene Hierarchy"), nullptr, &m_editor_hierarchy);
bool change_history_enabled = editor_mode::change_history(); bool change_history_enabled = editor_mode::change_history();
if (ImGui::MenuItem("Change History", nullptr, &change_history_enabled)) if (ImGui::MenuItem(STR_C("Change History"), nullptr, &change_history_enabled))
{ {
editor_mode::set_change_history(change_history_enabled); editor_mode::set_change_history(change_history_enabled);
} }
bool settings_open = editor_mode::settings_open(); bool settings_open = editor_mode::settings_open();
if (ImGui::MenuItem("Editor Settings", nullptr, &settings_open)) if (ImGui::MenuItem(STR_C("Editor Settings"), nullptr, &settings_open))
{ {
editor_mode::set_settings_open(settings_open); editor_mode::set_settings_open(settings_open);
} }

View File

@@ -706,6 +706,16 @@ void opengl_texture::update_from_memory(size_t width, size_t height, const uint8
if (glGenerateMipmap) if (glGenerateMipmap)
glGenerateMipmap(target); glGenerateMipmap(target);
glFlush(); glFlush();
// the content given straight to the gpu can't be read again: released by the garbage sweep, the texture would come back as
// the grey stub
if (type == "internalsrc:")
{
is_static = true;
is_ready = true;
}
// the name may be a new one, and the unit active took the texture past the unit cache
for (auto &unit : units)
unit = -1;
} }
void void

View File

@@ -5410,6 +5410,13 @@ void opengl33_renderer::Pick_Node_Callback(std::function<void(scene::basic_node
m_node_pick_requests.push_back(callback); 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() glm::dvec3 opengl33_renderer::Update_Mouse_Position()
{ {
if (!m_depth_pointer_pbo->is_busy()) if (!m_depth_pointer_pbo->is_busy())

View File

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

View File

@@ -1888,6 +1888,15 @@ opengl_renderer::Pick_Node_Callback( std::function<void( scene::basic_node * )>
m_node_pick_requests.emplace_back( Callback ); 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 void
opengl_renderer::Render( scene::basic_region *Region ) { opengl_renderer::Render( scene::basic_region *Region ) {

View File

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

View File

@@ -90,6 +90,8 @@ public:
virtual void Pick_Node_Callback( std::function<void( scene::basic_node * )> Callback ) = 0; virtual void Pick_Node_Callback( std::function<void( scene::basic_node * )> Callback ) = 0;
virtual auto Pick_Control() const -> TSubModel const * = 0; virtual auto Pick_Control() const -> TSubModel const * = 0;
virtual auto Pick_Node() const -> scene::basic_node const * = 0; virtual auto Pick_Node() const -> scene::basic_node const * = 0;
// a node deleted from the scene is no longer given as picked
virtual void Forget_Node( scene::basic_node const *Node ) {}
virtual auto Mouse_Position() const -> glm::dvec3 = 0; virtual auto Mouse_Position() const -> glm::dvec3 = 0;
virtual auto Mouse_Hit() const -> bool { return true; } virtual auto Mouse_Hit() const -> bool { return true; }

View File

@@ -30,6 +30,7 @@ http://mozilla.org/MPL/2.0/.
#include "scene/scenelayers.h" #include "scene/scenelayers.h"
#include "vehicle/Train.h" #include "vehicle/Train.h"
#include "application/application.h" #include "application/application.h"
#include "rendering/renderer.h"
#include "utilities/Logs.h" #include "utilities/Logs.h"
#include "vehicle/Driver.h" #include "vehicle/Driver.h"
@@ -561,6 +562,9 @@ std::pair<int, int> state_manager::rebuild_include(scene::instance_handle const
} }
void state_manager::delete_model(TAnimModel *model) { void state_manager::delete_model(TAnimModel *model) {
if (GfxRenderer) {
GfxRenderer->Forget_Node(model);
}
scene::Layers.count(model->layer(), scene::layer_item::model, -1); scene::Layers.count(model->layer(), scene::layer_item::model, -1);
scene::Layers.forget(model); scene::Layers.forget(model);
Region->erase(model); Region->erase(model);

View File

@@ -3381,15 +3381,12 @@ bool TDynamicObject::Update(double dt, double dt1)
&& MoverParameters->eimc[eimc_p_abed] < 0.001) && MoverParameters->eimc[eimc_p_abed] < 0.001)
FzadED = 0; //pętla bezpieczeństwa - bez ED FzadED = 0; //pętla bezpieczeństwa - bez ED
auto const FzadPN = Fzad - FrED * MoverParameters->MED_FrED_factor; auto const FzadPN = Fzad - FrED * MoverParameters->MED_FrED_factor;
//np = 0; std::vector<bool> PrzekrF( np );
// BUG: likely memory leak, allocation per inner loop, deleted only once outside
// TODO: sort this shit out
bool* PrzekrF = new bool[np];
float nPrzekrF = 0; float nPrzekrF = 0;
bool test = true; bool test = true;
float* FzED = new float[np]; std::vector<float> FzED( np );
float* FzEP = new float[np]; std::vector<float> FzEP( np );
float* FmaxEP = new float[np]; std::vector<float> FmaxEP( np );
// 3. ustaw pojazdom sile hamowania ED // 3. ustaw pojazdom sile hamowania ED
// - proporcjonalnie do mozliwosci // - proporcjonalnie do mozliwosci
@@ -3548,11 +3545,6 @@ bool TDynamicObject::Update(double dt, double dt1)
} }
delete[] PrzekrF;
delete[] FzED;
delete[] FzEP;
delete[] FmaxEP;
MED_oldFED = FzadED; MED_oldFED = FzadED;
} }