From fbc1530fa54f0e0462c222dd5044767d89575842 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 19 Nov 2026 20:55:25 +0100 Subject: [PATCH] Uniform native output path across generators; default view refuses with a clear error; span-lifetime docs Co-Authored-By: Claude Sonnet 5.5 --- docs/soa-world.md | 8 +++++--- native/Ymir.Box3D/CMakeLists.txt | 4 ++-- src/Ymir.Box3D/Box3DSoaWorld.cs | 6 +++--- src/Ymir.Box3D/Ymir.Box3D.csproj | 6 +++--- tests/Ymir.Box3D.Parity/Ymir.Box3D.Parity.csproj | 6 +++--- tests/Ymir.Box3D.Soa.Tests/Box3DSoaWorldTests.cs | 7 +++++++ 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/docs/soa-world.md b/docs/soa-world.md index 8ba0b73..e1a7300 100644 --- a/docs/soa-world.md +++ b/docs/soa-world.md @@ -59,9 +59,11 @@ Unity consumption is unrun; cross-platform bit-identity is unclaimed. - Native library name: `ymir_box3d.dll` on Windows (MinGW needs `PREFIX ""`, set under `if(MINGW)`; MSVC emits it natively), `libymir_box3d.so` on Linux, `libymir_box3d.dylib` on macOS. `Ymir.Box3D.csproj` copies from - `bin\$(Configuration)\` on Windows, which is where a multi-config generator writes. + `bin\$(Configuration)\` on every platform: `CMakeLists.txt` writes `bin/$/` and the csproj passes `-DCMAKE_BUILD_TYPE=$(Configuration)`, so single- and multi-config generators land in the same place. - Windows run: MinGW gcc with `CMAKE_GENERATOR="Ninja Multi-Config" CC=gcc`; `Ymir.Box3D.Soa.Tests` passes. - Linux run (Yggdrasil, default generator, gcc): the same tests pass and emit `bin/libymir_box3d.so`. macOS is unrun. + Linux run (Yggdrasil, default generator, gcc): the same tests pass and emit `bin/Debug/libymir_box3d.so`. macOS is unrun. - `Box3DSoaWorld` is not thread-safe: `Dispose` must not race `Step` or a lane read. A `Box3DSoaView` refuses - lane access (ObjectDisposedException) once its world is disposed. Known limit: an undisposed world leaks its + to hand out a lane (ObjectDisposedException) once its world is disposed, and a `default` view refuses with + InvalidOperationException. The check guards obtaining a span, not a span already held: a span taken from a + view must not be used after the world is disposed. Known limit: an undisposed world leaks its native memory; there is no finalizer or SafeHandle. diff --git a/native/Ymir.Box3D/CMakeLists.txt b/native/Ymir.Box3D/CMakeLists.txt index 1ace1cd..48ff838 100644 --- a/native/Ymir.Box3D/CMakeLists.txt +++ b/native/Ymir.Box3D/CMakeLists.txt @@ -21,8 +21,8 @@ endif() set_target_properties(ymir_box3d PROPERTIES C_VISIBILITY_PRESET hidden - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/$" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/$" ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") if(MINGW) # MinGW would emit libymir_box3d.dll; the managed side loads ymir_box3d.dll. diff --git a/src/Ymir.Box3D/Box3DSoaWorld.cs b/src/Ymir.Box3D/Box3DSoaWorld.cs index fad36f7..fcb6c05 100644 --- a/src/Ymir.Box3D/Box3DSoaWorld.cs +++ b/src/Ymir.Box3D/Box3DSoaWorld.cs @@ -151,17 +151,17 @@ internal static unsafe partial class Box3DSoaNative public readonly unsafe struct Box3DSoaView { private readonly Box3DSoaViewNative _v; - private readonly Box3DSoaWorld _world; + private readonly Box3DSoaWorld? _world; private ReadOnlySpan Lane(T* p, int n) where T : unmanaged { - _world.ThrowIfDisposed(); + (_world ?? throw new InvalidOperationException("This Box3DSoaView has no world; take it from Box3DSoaWorld.View.")).ThrowIfDisposed(); return new(p, n); } private Span Write(T* p, int n) where T : unmanaged { - _world.ThrowIfDisposed(); + (_world ?? throw new InvalidOperationException("This Box3DSoaView has no world; take it from Box3DSoaWorld.View.")).ThrowIfDisposed(); return new(p, n); } diff --git a/src/Ymir.Box3D/Ymir.Box3D.csproj b/src/Ymir.Box3D/Ymir.Box3D.csproj index 58b2df9..35cb968 100644 --- a/src/Ymir.Box3D/Ymir.Box3D.csproj +++ b/src/Ymir.Box3D/Ymir.Box3D.csproj @@ -27,14 +27,14 @@ Pack="true" PackagePath="runtimes/win-x64/native/ymir_box3d.dll" Condition="'$(OS)' == 'Windows_NT'" /> - - - + diff --git a/tests/Ymir.Box3D.Parity/Ymir.Box3D.Parity.csproj b/tests/Ymir.Box3D.Parity/Ymir.Box3D.Parity.csproj index 0987218..bd866bd 100644 --- a/tests/Ymir.Box3D.Parity/Ymir.Box3D.Parity.csproj +++ b/tests/Ymir.Box3D.Parity/Ymir.Box3D.Parity.csproj @@ -23,11 +23,11 @@ - + - - + + diff --git a/tests/Ymir.Box3D.Soa.Tests/Box3DSoaWorldTests.cs b/tests/Ymir.Box3D.Soa.Tests/Box3DSoaWorldTests.cs index bb537a2..89ee97d 100644 --- a/tests/Ymir.Box3D.Soa.Tests/Box3DSoaWorldTests.cs +++ b/tests/Ymir.Box3D.Soa.Tests/Box3DSoaWorldTests.cs @@ -159,4 +159,11 @@ public sealed unsafe class Box3DSoaWorldTests Assert.Throws(() => view.ForceX.Length); Assert.Throws(() => view.JointAngle.Length); } + + [Fact] + public void A_default_view_refuses_lane_access() + { + var view = default(Box3DSoaView); + Assert.Throws(() => view.PositionY.Length); + } }