Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5336: Construct a unit test scenario to check whether the CSG merge …
…algorithm joins brushes of different entities
- Loading branch information
1 parent
65179d4
commit 4e06dd6
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,42 @@ | ||
#include "RadiantTest.h" | ||
|
||
#include "imap.h" | ||
#include "ibrush.h" | ||
#include "entitylib.h" | ||
#include "algorithm/Scene.h" | ||
|
||
// Issue #5336: Crash when using CSG Merge on brushes that are entities | ||
TEST_F(RadiantTest, CSGMergeWithFuncStatic) | ||
{ | ||
loadMap("csg_merge_with_func_static.map"); | ||
|
||
// Locate the first worldspawn brush | ||
scene::INodePtr firstBrush = test::algorithm::getNthChild(GlobalMapModule().getWorldspawn(), 0); | ||
ASSERT_TRUE(firstBrush); | ||
|
||
// Locate the func_static in the map | ||
EntityNodeFindByClassnameWalker walker("func_static"); | ||
GlobalSceneGraph().root()->traverse(walker); | ||
|
||
auto entityNode = walker.getEntityNode(); | ||
ASSERT_TRUE(entityNode); | ||
ASSERT_TRUE(entityNode->hasChildNodes()); | ||
|
||
// Select both of them, the order is important | ||
Node_setSelected(firstBrush, true); | ||
Node_setSelected(entityNode, true); | ||
|
||
// CSG merge | ||
GlobalCommandSystem().executeCommand("CSGMerge"); | ||
|
||
// No merge should have happened since the brushes | ||
// are not part of the same entity | ||
// So assume the scene didn't change | ||
ASSERT_TRUE(test::algorithm::getNthChild(GlobalMapModule().getWorldspawn(), 0) == firstBrush); | ||
|
||
EntityNodeFindByClassnameWalker walker2("func_static"); | ||
GlobalSceneGraph().root()->traverse(walker2); | ||
|
||
ASSERT_TRUE(walker.getEntityNode()); | ||
ASSERT_TRUE(walker.getEntityNode()->hasChildNodes()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <cstddef> | ||
#include "inode.h" | ||
#include "ientity.h" | ||
|
||
namespace test::algorithm | ||
{ | ||
|
||
// Returns the n-th child of the given parent node | ||
inline scene::INodePtr getNthChild(const scene::INodePtr& parent, std::size_t index) | ||
{ | ||
std::size_t n = 0; | ||
scene::INodePtr candidate; | ||
|
||
parent->foreachNode([&](const scene::INodePtr& node) | ||
{ | ||
if (n == index) | ||
{ | ||
candidate = node; | ||
return false; | ||
} | ||
|
||
++n; | ||
return true; | ||
}); | ||
|
||
return candidate; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup> | ||
<ClCompile Include="..\..\..\test\CSG.cpp" /> | ||
<ClCompile Include="..\..\..\test\HeadlessOpenGLContext.cpp" /> | ||
<ClCompile Include="..\..\..\test\test.cpp" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="..\..\..\test\HeadlessOpenGLContext.h" /> | ||
<ClInclude Include="..\..\..\test\RadiantTest.h" /> | ||
<ClInclude Include="..\..\..\test\TestContext.h" /> | ||
<ClInclude Include="..\..\..\test\algorithm\Scene.h"> | ||
<Filter>algorithm</Filter> | ||
</ClInclude> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Filter Include="algorithm"> | ||
<UniqueIdentifier>{519b0a02-8afc-4b67-9fa3-aeed09412562}</UniqueIdentifier> | ||
</Filter> | ||
</ItemGroup> | ||
</Project> |