qbsp: fix leak in base1leak test

This commit is contained in:
Eric Wasylishen 2022-05-05 01:01:33 -06:00
parent 235c6cb025
commit b06736dea4
2 changed files with 12 additions and 0 deletions

View File

@ -21,6 +21,7 @@
#pragma once
#include <qbsp/winding.hh>
#include <common/qvec.hh>
#include <atomic>
@ -37,5 +38,6 @@ class mapentity_t;
void DetailToSolid(node_t *node);
void PruneNodes(node_t *node);
bool WindingIsTiny(const winding_t &w);
twosided<std::unique_ptr<brush_t>> SplitBrush(std::unique_ptr<brush_t> brush, const qplane3d &split);
node_t *SolidBSP(mapentity_t *entity, bool midsplit);

View File

@ -544,6 +544,9 @@ static void CutNodePortals_r(node_t *node, portal_state_t *state)
FError("Mislinked portal");
winding = winding->clip(clipplane, ON_EPSILON, true)[SIDE_FRONT];
if (winding && WindingIsTiny(*winding)) {
winding = std::nullopt;
}
if (!winding) {
logging::funcprint("WARNING: New portal was clipped away near ({:.3} {:.3} {:.3})\n", portal->winding->at(0)[0],
portal->winding->at(0)[1], portal->winding->at(0)[2]);
@ -574,6 +577,13 @@ static void CutNodePortals_r(node_t *node, portal_state_t *state)
/* cut the portal into two portals, one on each side of the cut plane */
auto windings = portal->winding->clip(plane, ON_EPSILON);
if (windings[SIDE_BACK] && WindingIsTiny(*windings[SIDE_BACK])) {
windings[SIDE_BACK] = std::nullopt;
}
if (windings[SIDE_FRONT] && WindingIsTiny(*windings[SIDE_FRONT])) {
windings[SIDE_FRONT] = std::nullopt;
}
if (!windings[SIDE_FRONT]) {
if (side == SIDE_FRONT)
AddPortalToNodes(portal, back, other_node);