Comments (15)
I'll look into them
from sharpgltf.
For now I still need to keep supporting down to NetStandard2.0 because some users are using this library in plugins for platforms that target net4.7.1 , so changing the interfaces is not an option.
recently, I did some changes to the vertexutils with attribute decoration that are supposed to fix the issue; could you try cloning the repo and using the latest source code and see if the issue remains?
If the issue persist, I can look further into the issue
from sharpgltf.
I did notice your improvements, especially relating to _JsonArray
.
There remains other issues to resolve:
ILC : Trim analysis warning IL2075: SharpGLTF.Geometry.VertexTypes.VertexUtils.GetVertexAttributes(IVertexBuilder,Int32,PackedEncoding): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields' in call to 'System.Type.GetFields()'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
ILC : Trim analysis warning IL2077: SharpGLTF.Schema2.ExtensionsFactory.Create(JsonSerializable,String): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in call to 'System.Activator.CreateInstance(Type,BindingFlags,Binder,Object[],CultureInfo)'. The field 'System.ValueTuple`3<String,Type,Type>.Item3' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
There is a third warning, but I don't think it should have any significant impact.
ILC : Trim analysis warning IL2075: SharpGLTF.Validation.ModelException._CreateBaseMessage(JsonSerializable,String): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
from sharpgltf.
I've pushed some changes that might solve the remaining trimming issues.
For some odd reason I don't understand, the analyzers don't expose the issues you mentioned, so I checked them blindly.
So, could you check the latest changes?
from sharpgltf.
So, could you check the latest changes?
I looked them over, and they appear fine. However, due to my build process, it's difficult for me to test without you posting a NuGet release.
the analyzers don't expose the issues you mentioned
On .NET 6, you can enable the analyzers with <IsTrimmable>true</IsTrimmable>
.
On .NET 8, additional analyzers can be enabled with <IsAotCompatible>true</IsAotCompatible>
.
https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming
https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/?tabs=net8plus
from sharpgltf.
could you try cloning the repo and using the latest source code and see if the issue remains?
I did, and unfortunately I still get exceptions at runtime:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Internal.Runtime.CompilerHelpers.ThrowHelpers.ThrowIndexOutOfRangeException() + 0x24
at SharpGLTF.Geometry.VertexTypes.VertexUtils.CreateVertexMemoryAccessors[TVertex](IReadOnlyList`1, PackedEncoding) + 0x165
at SharpGLTF.Geometry.PackedPrimitiveBuilder`1.SetStridedVertices(IPrimitiveReader`1, PackedEncoding) + 0x3e
at SharpGLTF.Geometry.PackedMeshBuilder`1.Create(IMeshBuilder`1, PackedEncoding, EncodingType, SceneBuilderSchema2Settings) + 0x332
at SharpGLTF.Geometry.PackedMeshBuilder`1.<CreatePackedMeshes>d__0.MoveNext() + 0x1a8
at System.Collections.Generic.List`1..ctor(IEnumerable`1) + 0xed
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1) + 0x3d
at SharpGLTF.Schema2.Toolkit.CreateMeshes[TMaterial](ModelRoot, Converter`2, SceneBuilderSchema2Settings, IMeshBuilder`1[]) + 0x274
at SharpGLTF.Scenes.Schema2SceneBuilder.AddGeometryResources(ModelRoot, IEnumerable`1, SceneBuilderSchema2Settings) + 0x368
at SharpGLTF.Scenes.SceneBuilder.ToGltf2(IEnumerable`1, SceneBuilderSchema2Settings) + 0x64
at SharpGLTF.Scenes.SceneBuilder.ToGltf2() + 0x40
and warnings at compile time:
ILC : Trim analysis warning IL2077: SharpGLTF.Schema2.ExtensionsFactory.Create(JsonSerializable,String): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in call to 'System.Activator.CreateInstance(Type,BindingFlags,Binder,Object[],CultureInfo)'. The field 'System.ValueTuple`3<String,Type,Type>.Item3' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
ILC : Trim analysis warning IL2075: SharpGLTF.Geometry.VertexTypes.VertexUtils.GetVertexAttributes(IVertexBuilder,Int32,PackedEncoding): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields' in call to 'System.Type.GetFields()'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
ILC : Trim analysis warning IL2075: SharpGLTF.Validation.ModelException._CreateBaseMessage(JsonSerializable,String): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
I have a potential solution:
interface IVertexGeometry
{
FieldInfo[] GetFields();
}
interface IVertexMaterial
{
FieldInfo[] GetFields();
}
interface IVertexSkinning
{
FieldInfo[] GetFields();
}
struct VertexPosition : IVertexGeometry
{
readonly FieldInfo[] IVertexGeometry.GetFields() => typeof(VertexPosition).GetFields();
}
This should avoid the trimming issues and allow you to remove the DynamicallyAccessedMembers
guards you put in.
If ReadOnlySpan<T>
is permissible, it can be optimized with static fields:
interface IVertexGeometry
{
ReadOnlySpan<FieldInfo> GetFields();
}
struct VertexPosition : IVertexGeometry
{
private static readonly FieldInfo[] _fields = typeof(VertexPosition).GetFields();
readonly ReadOnlySpan<FieldInfo> IVertexGeometry.GetFields() => _fields;
}
If that's too verbose, the fields can be stored in a generic static class:
internal static class FieldCache<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>
{
private static readonly FieldInfo[] _fields = typeof(T).GetFields();
public static ReadOnlySpan<FieldInfo> GetFields() => _fields;
}
struct VertexPosition : IVertexGeometry
{
readonly ReadOnlySpan<FieldInfo> IVertexGeometry.GetFields() => FieldCache<VertexPosition>.GetFields();
}
What would you prefer?
from sharpgltf.
What keeps ticking me is that I am not seeing these warnings you mention, which is preventing me finding these problems early, and I have to fix them blindly.
I am still looking for alternatives to this problem, but ultimately if I don't find a solution, I'll have to bite the bullet and fix this in line with what you're proposing.
I also think part of the problem is that it is not possible to run the unit tests in AOT mode to expose these issues, and the only way to surface them is with proper AOT demo applications.
do you have a shareable proof of concept application for me to test?
from sharpgltf.
What keeps ticking me is that I am not seeing these warnings you mention, which is preventing me finding these problems early, and I have to fix them blindly.
Something is strange, for lack of a better word, about your project. Whenever I build your project, I don't see these warnings, which is in line with your experience. I only see them when I publish my project.
However, for other projects, I see the warnings in the IDE. I think something in the SharpGLTF repository is suppressing these trim warnings.
I noticed something significant while investigating your code. I can get Aot warnings in the IDE with your project, which are new with .NET 8. Perhaps, the trim warnings were just disabled a long time ago by accident.
do you have a shareable proof of concept application for me to test?
You could add <PublishAot>true</PublishAot>
to your example project. That would cover a lot of the code.
from sharpgltf.
Something is strange, for lack of a better word, about your project. Whenever I build your project, I don't see these warnings, which is in line with your experience. I only see them when I publish my project.
I am aware of that, normal builds don't show up these warnings, but rebuilds do, which is what I usually do to surface as many warnings as possible. Maybe another one is building in debug/release.
from sharpgltf.
I've figured out that a plain GetType call does not work even if you decorate a method/class with DynamicallyAccessedMembers
what it does work is to introduce this method into the struct:
#if NET6_0_OR_GREATER
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicFields)]
#endif
public Type GetVertexType() { return typeof(VertexPositionNormal); }
So instead of calling GetType().GetFields()
which does not work, now you would call GetVertexType().GetFields()
which does work.
But then, the whole point of using attributes was to make it easy to define custom vertex formats. If now an additional weird method is required, it defeats the purporse of the attribute. And relying on these DynamicallyAccessedMembers feels weak to say the least. So I'll do some more research.
from sharpgltf.
The bloat from #if NET6_0_OR_GREATER
and #endif
can be removed if you add a (nontransitive) reference to PolySharp and include this property:
<PolySharpIncludeRuntimeSupportedAttributes>true</PolySharpIncludeRuntimeSupportedAttributes>
from sharpgltf.
I've refactored things so now attribute information is retrieved using an interface. please, try it now and let me know if it works
from sharpgltf.
I greatly appreciate this and will check as soon as possible.
from sharpgltf.
Everything appears to be working on my end. I still get two warnings in my build log, but they don't seem to have any impact on my project.
I'm not using any extensions:
ILC : Trim analysis warning IL2077: SharpGLTF.Schema2.ExtensionsFactory.Create(JsonSerializable,String): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in call to 'System.Activator.CreateInstance(Type,BindingFlags,Binder,Object[],CultureInfo)'. The field 'System.ValueTuple`3<String,Type,Type>.Item3' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
A trimming issue at this location, at worst, could cause a different exception to be thrown:
ILC : Trim analysis warning IL2075: SharpGLTF.Validation.ModelException._CreateBaseMessage(JsonSerializable,String): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
from sharpgltf.
I built with your recent commit for the extensions factory, and everything seems good. Thank you so much!
from sharpgltf.
Related Issues (20)
- [Question] Vertex Normals HOT 1
- [Feature request] Export image with its name rather than just the GLTF's name + number HOT 1
- Automaticaly Generate Normals HOT 1
- Expose accessor bounds
- FileLoadException in Navisworks plug-in HOT 3
- [enhancement] make LogicalBufferIndex field public in file gltf.BufferView.cs
- Use generated C# files from CodeGen HOT 6
- [Question] Mesh Vertex with UVW are exploded HOT 2
- CodeGen Tool generates JsonNode not the object itself HOT 1
- No tag for the alpha0031 release from nuget.org HOT 2
- [Questions] Some questions regarding correct procedure for reading HOT 6
- [BUG] VerifyAccessorBounds does not support component type other than FLOAT HOT 3
- Use FileStream to write json gltf HOT 5
- Mesh Extras not supporting custom encodersettings, to avoid special character serialization HOT 1
- CodeGen - Self referencing array in json schema results in stackoverflow HOT 3
- Should SharpGLTF throw an exception when an unsupported extension is required? HOT 5
- [Feature Request] Switch to using System.IO.Abstractions for file logic HOT 1
- [BUG] Unable to retrieve vertices from morph target when using SceneBuilder HOT 1
- Support for EXT_meshopt_compression HOT 1
- [QUESTION] How to read values from a Property Table? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sharpgltf.