Uniform native output path across generators; default view refuses with a clear error; span-lifetime docs

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-19 20:55:25 +01:00
commit fbc1530fa5
6 changed files with 23 additions and 14 deletions

View file

@ -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/$<CONFIG>/` 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.

View file

@ -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/$<CONFIG>"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/$<CONFIG>"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
if(MINGW)
# MinGW would emit libymir_box3d.dll; the managed side loads ymir_box3d.dll.

View file

@ -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<T> Lane<T>(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<T> Write<T>(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);
}

View file

@ -27,14 +27,14 @@
Pack="true"
PackagePath="runtimes/win-x64/native/ymir_box3d.dll"
Condition="'$(OS)' == 'Windows_NT'" />
<None Include="$(NativeBuildDir)\bin\libymir_box3d.so"
<None Include="$(NativeBuildDir)\bin\$(Configuration)\libymir_box3d.so"
Link="libymir_box3d.so"
CopyToOutputDirectory="PreserveNewest"
CopyToPublishDirectory="PreserveNewest"
Pack="true"
PackagePath="runtimes/linux-x64/native/libymir_box3d.so"
Condition="'$(OS)' != 'Windows_NT' and !$([MSBuild]::IsOSPlatform('OSX'))" />
<None Include="$(NativeBuildDir)\bin\libymir_box3d.dylib"
<None Include="$(NativeBuildDir)\bin\$(Configuration)\libymir_box3d.dylib"
Link="libymir_box3d.dylib"
CopyToOutputDirectory="PreserveNewest"
CopyToPublishDirectory="PreserveNewest"
@ -51,7 +51,7 @@
<Target Name="BuildYmirBox3DNative"
BeforeTargets="PrepareForBuild;GetCopyToOutputDirectoryItems;GetCopyToPublishDirectoryItems"
Condition="'$(DesignTimeBuild)' != 'true'">
<Exec Command="&quot;$(CMakeExe)&quot; -S &quot;$(NativeSourceDir)&quot; -B &quot;$(NativeBuildDir)&quot; -DBUILD_SHARED_LIBS=OFF" />
<Exec Command="&quot;$(CMakeExe)&quot; -S &quot;$(NativeSourceDir)&quot; -B &quot;$(NativeBuildDir)&quot; -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=$(Configuration)" />
<Exec Command="&quot;$(CMakeExe)&quot; --build &quot;$(NativeBuildDir)&quot; --config $(Configuration) --target ymir_box3d" />
</Target>

View file

@ -23,11 +23,11 @@
</ItemGroup>
<Target Name="BuildBox3DParityOracle" BeforeTargets="Build" Condition="'$(DesignTimeBuild)' != 'true'">
<Exec Command="&quot;$(CMakeExe)&quot; -S &quot;$(NativeSourceDir)&quot; -B &quot;$(NativeBuildDir)&quot; -DBUILD_SHARED_LIBS=OFF" />
<Exec Command="&quot;$(CMakeExe)&quot; -S &quot;$(NativeSourceDir)&quot; -B &quot;$(NativeBuildDir)&quot; -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=$(Configuration)" />
<Exec Command="&quot;$(CMakeExe)&quot; --build &quot;$(NativeBuildDir)&quot; --config $(Configuration) --target ymir_box3d" />
<Copy SourceFiles="$(NativeBuildDir)\bin\$(Configuration)\ymir_box3d.dll" DestinationFolder="$(OutDir)" Condition="'$(OS)' == 'Windows_NT'" />
<Copy SourceFiles="$(NativeBuildDir)\bin\libymir_box3d.so" DestinationFolder="$(OutDir)" Condition="'$(OS)' != 'Windows_NT' and !$([MSBuild]::IsOSPlatform('OSX'))" />
<Copy SourceFiles="$(NativeBuildDir)\bin\libymir_box3d.dylib" DestinationFolder="$(OutDir)" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<Copy SourceFiles="$(NativeBuildDir)\bin\$(Configuration)\libymir_box3d.so" DestinationFolder="$(OutDir)" Condition="'$(OS)' != 'Windows_NT' and !$([MSBuild]::IsOSPlatform('OSX'))" />
<Copy SourceFiles="$(NativeBuildDir)\bin\$(Configuration)\libymir_box3d.dylib" DestinationFolder="$(OutDir)" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
</Target>
</Project>

View file

@ -159,4 +159,11 @@ public sealed unsafe class Box3DSoaWorldTests
Assert.Throws<ObjectDisposedException>(() => view.ForceX.Length);
Assert.Throws<ObjectDisposedException>(() => view.JointAngle.Length);
}
[Fact]
public void A_default_view_refuses_lane_access()
{
var view = default(Box3DSoaView);
Assert.Throws<InvalidOperationException>(() => view.PositionY.Length);
}
}