speps / LibTessDotNet

C# port of the famous GLU Tessellator - prebuilt binaries now available in "releases" tab
https://www.nuget.org/packages/LibTessDotNet
Other
316 stars 60 forks source link

DefaultTypePool requires JIT compilation #51

Open morgoth990 opened 2 years ago

morgoth990 commented 2 years ago

I'm compiling the library in a project without JIT compilation. On an older version everything was working fine but now I'm receiving an exception in DefaultTypePool.Creator.

private static readonly Func<T> Creator = Expression.Lambda<Func<T>>(Expression.New(typeof(T))).Compile();

public object Get()
{
    lock (_pool)
    {
            if (_pool.Count > 0)
            {
                return _pool.Dequeue();
            }
    }
    return Creator();
}

The Creator is compiling at runtime but without JIT compilation can't work. Is the Creator needed? Can't DefaultTypePool.Get() just return new T() ?

speps commented 2 years ago

You can implement IPool yourself and pass an instance of it to the Tess constructor. I don't know if using JIT or not is detectable to remove this code from the DefaultTypePool at compile time and return new T() instead, I can accept a PR if you find a way to do that.

speps commented 2 years ago

Just read your issue again, I'm also not sure why Creator can't be replaced with new T().

morgoth990 commented 2 years ago

I have tested some cases with hundreds of complex contours and seem to work fine without any noticeable performance changes

rickomax commented 1 year ago

+1 Compiling this library for Unity on WebGL causes issues because of the Pool class.

zyowo commented 1 year ago

+1

291614  03-23 11:09:14.573 11793 11880 E Unity   : System.TypeInitializationException: The type initializer for 'LibTessDotNet.DefaultTypePool<LibTessDotNet.Mesh>' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.
System.TypeInitializationException: The type initializer for 'LibTessDotNet.DefaultTypePool<LibTessDotNet.Mesh>' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.
291787  03-23 11:09:14.576 11793 11880 E Unity   : System.NullReferenceException: Object reference not set to an instance of an object.
Spongert commented 1 year ago

+1

291614    03-23 11:09:14.573 11793 11880 E Unity   : System.TypeInitializationException: The type initializer for 'LibTessDotNet.DefaultTypePool<LibTessDotNet.Mesh>' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.
System.TypeInitializationException: The type initializer for 'LibTessDotNet.DefaultTypePool<LibTessDotNet.Mesh>' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.
291787    03-23 11:09:14.576 11793 11880 E Unity   : System.NullReferenceException: Object reference not set to an instance of an object.

I am in this repos for different reasons, but also working in a Unity WebGL project. Have not seen this problem yet, but likely it might be aggressive stripping. Did you try to manually inform the compiler to keep some of the classes? The same can happen if you add a SphereCollider with code only for example.

https://docs.unity3d.com/Manual/ManagedCodeStripping.html