LibTessDotNet icon indicating copy to clipboard operation
LibTessDotNet copied to clipboard

DefaultTypePool requires JIT compilation

Open morgoth990 opened this issue 2 years ago • 6 comments

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<T>.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<T>.Get() just return new T() ?

morgoth990 avatar Apr 12 '22 09:04 morgoth990

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 avatar Apr 12 '22 09:04 speps

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

speps avatar Apr 12 '22 09:04 speps

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

morgoth990 avatar Apr 12 '22 09:04 morgoth990

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

rickomax avatar Jan 15 '23 23:01 rickomax

+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.

zyowo avatar Mar 23 '23 03:03 zyowo

+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

Spongert avatar May 03 '23 19:05 Spongert