AnnulusGames / LitMotion

Lightning-fast and Zero Allocation Tween Library for Unity.
https://annulusgames.github.io/LitMotion/
MIT License
828 stars 66 forks source link

error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type #116

Closed c3-hoge-fuga-piyo closed 8 months ago

c3-hoge-fuga-piyo commented 8 months ago

When installing the latest version (b2684c12023392b689e83465e89a8c1d46172328) in a new project created with Unity 2022.3.21f1 or Unity 2023.3.9f1, a compile error occurs at the following location.

This did not occur at 83b455a547e64a26da963d6067906b8c76866a36

https://github.com/AnnulusGames/LitMotion/blob/b2684c12023392b689e83465e89a8c1d46172328/src/LitMotion/Assets/LitMotion/Runtime/MotionUpdateJob.cs#L22

Library\PackageCache\com.annulusgames.lit-motion@b2684c1202\Runtime\MotionUpdateJob.cs(22,82): error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('MotionData<TValue, TOptions>')

https://github.com/AnnulusGames/LitMotion/blob/b2684c12023392b689e83465e89a8c1d46172328/src/LitMotion/Assets/LitMotion/Runtime/MotionUpdateJob.cs#L168

Library\PackageCache\com.annulusgames.lit-motion@b2684c1202\Runtime\MotionUpdateJob.cs(168,52): error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('MotionDataCore')
AnnulusGames commented 8 months ago

It appears that this is an error that depends on the version of the Collections package.

NativeContainer has its own safety checks, which are implemented differently depending on the version of Collections. 1.x uses a reference type called DisposeSentinel to perform the checks, so NativeContainer is a managed structure, whereas in 2.x it is unmanaged because only the AtomicSafetyHandle is used. Therefore, in 1.x, the pointer cannot be obtained and an error is occurring.

The solution is to change the code to use the version with the safety check removed depending on the version of Collections. This would compromise safety, but since there are already enough checks in between, it should not be a problem.

AnnulusGames commented 8 months ago

Fixed in #118.