From e1c31bb790b04cf5d4e8646b2f43fa4aa5a89277 Mon Sep 17 00:00:00 2001 From: codereader Date: Mon, 23 Mar 2020 05:56:02 +0100 Subject: [PATCH] Fix the crash described in #5132. Patches were submitting UndoMementos to the undo system even though they ended up not being added to the scene. The new approach is to only add them to the scene after it's clear they are going to be kept. --- radiant/patch/Patch.cpp | 3 --- radiant/patch/algorithm/General.cpp | 14 +++++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/radiant/patch/Patch.cpp b/radiant/patch/Patch.cpp index a063097806..6baa9a3aa6 100644 --- a/radiant/patch/Patch.cpp +++ b/radiant/patch/Patch.cpp @@ -2539,9 +2539,6 @@ void Patch::createThickenedWall(const Patch& sourcePatch, // Notify the patch about the change controlPointsChanged(); - - // Texture the patch "naturally" - NaturalTexture(); } void Patch::stitchTextureFrom(Patch& sourcePatch) { diff --git a/radiant/patch/algorithm/General.cpp b/radiant/patch/algorithm/General.cpp index 523d0e8cf9..1e0bf5d68f 100644 --- a/radiant/patch/algorithm/General.cpp +++ b/radiant/patch/algorithm/General.cpp @@ -53,10 +53,6 @@ void thicken(const PatchNodePtr& sourcePatch, float thickness, bool createSeams, // Now create the four walls for (int i = 0; i < 4; i++) { - // Insert each node into the same parent as the existing patch - // It's vital to do this first, otherwise these patches won't have valid shaders - parent->addChildNode(nodes[i]); - // Retrieve the contained patch from the node Patch* wallPatch = Node_getPatch(nodes[i]); @@ -65,15 +61,19 @@ void thicken(const PatchNodePtr& sourcePatch, float thickness, bool createSeams, if (!wallPatch->isDegenerate()) { + // Insert each node into the same parent as the existing patch + // It's vital to do this first, otherwise these patches won't have valid shaders + parent->addChildNode(nodes[i]); + + // Now the shader is realised, apply natural scale + wallPatch->NaturalTexture(); + // Now select the newly created patch Node_setSelected(nodes[i], true); } else { rMessage() << "Thicken: Discarding degenerate patch." << std::endl; - - // Remove again - parent->removeChildNode(nodes[i]); } } }