Skip to content

Commit

Permalink
Fix issue with reparenting module in root namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
BeanCheeseBurrito committed Nov 15, 2024
1 parent 7d4e7d5 commit ebcb1fb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/Flecs.NET.Tests/Cpp/ModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,17 @@ private void RenameNamespaceNested()
Assert.True(nsChild != 0);
Assert.True(nsChild.Has(Ecs.Module));
}

[Fact]
private void RenameReparentRootModule()
{
using World world = World.Create();

Entity m = world.Import<ReparentRootModule>();
Entity p = m.Parent();

Assert.True(p != 0);
Assert.Equal("Namespace", p.Name());
Assert.Equal("ReparentRootModule", m.Name());
}
}
8 changes: 8 additions & 0 deletions src/Flecs.NET.Tests/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ public void InitModule(World world)
}
}

public class ReparentRootModule : IFlecsModule
{
public void InitModule(World world)
{
world.Module<ReparentRootModule>("Namespace.ReparentRootModule");
}
}

namespace Namespace
{
public struct NestedNameSpaceType;
Expand Down
4 changes: 2 additions & 2 deletions src/Flecs.NET/Core/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3076,7 +3076,7 @@ public Entity ToEntity<T>(T value) where T : Enum
// Module was reparented, cleanup old parent(s)
Entity current = prevParent;

do
while (current != 0)
{
Entity next = current.Parent();

Expand All @@ -3086,7 +3086,7 @@ public Entity ToEntity<T>(T value) where T : Enum
current.Destruct();

current = next;
} while (current != 0);
}

return Entity(result);
}
Expand Down

0 comments on commit ebcb1fb

Please sign in to comment.