Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DefaultTypePool requires JIT compilation #51

Open
morgoth990 opened this issue Apr 12, 2022 · 6 comments
Open

DefaultTypePool requires JIT compilation #51

morgoth990 opened this issue Apr 12, 2022 · 6 comments

Comments

@morgoth990
Copy link

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
Copy link
Owner

speps commented Apr 12, 2022

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
Copy link
Owner

speps commented Apr 12, 2022

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

@morgoth990
Copy link
Author

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

@rickomax
Copy link

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

@zyowo
Copy link

zyowo commented Mar 23, 2023

+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
Copy link

Spongert commented May 3, 2023

+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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants