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

System.Reflection.Emit #45

Open
KoalaHao opened this issue Jun 27, 2019 · 14 comments
Open

System.Reflection.Emit #45

KoalaHao opened this issue Jun 27, 2019 · 14 comments

Comments

@KoalaHao
Copy link

I tried to use this project in Unity

but I found out that Jace uses System.Reflection.Emit

this is not allowed in most of the platforms as specified by Unity
https://docs.unity3d.com/Manual/ScriptingRestrictions.html

Is there any workaround to this?

@pieterderycke
Copy link
Owner

The problem is that Jace is using System.Reflection.Emit for its dynamic compiler (to generate and compile dynamically .NET functions) which is what is not possible on Unity. A potential solution could be to use Jace in interpreted mode: it will be slower, but it will not rely on the dynamic compiler.

Would you be able to test this workaround?

@KoalaHao
Copy link
Author

Thanks for the reply
I'll test it out when I get the chance to.
Also, how much performance hit are we talking about with interpreted vs compiled?

@pieterderycke
Copy link
Owner

See the first page of this github repository. But it heavily depends on how many times you reuse the same function. If you don't reuse compiles functions then there will not be a lot of performance difference

@Giorgi
Copy link

Giorgi commented Jul 1, 2019

@KoalaHao If you only need basic arithmetic you can use Math Expression Evaluator which doesn't user Reflection.Emit but still supports compiled mode

@KoalaHao
Copy link
Author

KoalaHao commented Jul 1, 2019

I tried interpreted mode, and I am on the 0.8.5 version, i think it has bugs with interpreted version, will upgrade and try again later

@pieterderycke
Copy link
Owner

I am not aware of bugs with the interpreted mode of 0.8.5, but would it be possible to test a more recent version? In case you have issues, let me know and I will look to investigate it.

@KoalaHao
Copy link
Author

KoalaHao commented Jul 5, 2019

I still havn'nt test the new version yet, but the bug of 0.8.5 is in interpreted mode, all variables gets converted into lower case, then it tries to match with a "not converted to lower case" string, which results in variable not found error

@pieterderycke
Copy link
Owner

version 0.8.5 is 5 years old, so I recommend to upgrade to the newest version. It contains a number of bug fixex.

@pieterderycke
Copy link
Owner

@KoalaHao Did you already had time to try a more recent version of Jace inside a Unity project?

@strangenoora
Copy link

Hey there, I have a similar issue. I have a Unity project using the latest version of Unity and a version of Jace I downloaded in August. Performance is not critical for me, I am using Jace because it's nice to let non-programmers to edit game balancing formulas in text. It worked great for me until I switched the scripting backend from Mono (Unity default) to IL2CPP (which is required to make a x64 build for Android, which is required by Google Play Store since August 1st this year).

Here's the error I get

ExecutionEngineException: Attempting to call method 'System.Linq.Expressions.Interpreter.LightLambda::MakeRun1<Jace.FormulaContext,System.Double>' for which no ahead of time (AOT) code was generated. System.Func2[T,TResult].Invoke (T arg) (at <00000000000000000000000000000000>:0)
System.Linq.Expressions.Expression1[TDelegate].Compile (System.Boolean preferInterpretation) (at <00000000000000000000000000000000>:0) Jace.Execution.DynamicCompiler.BuildFormula (Jace.Operations.Operation operation, Jace.Execution.IFunctionRegistry functionRegistry, Jace.Execution.IConstantRegistry constantRegistry) (at <00000000000000000000000000000000>:0) System.Func2[T,TResult].Invoke (T arg) (at <00000000000000000000000000000000>:0)`

Googling ExecutionEngineException I found this in the Unity manual
https://docs.unity3d.com/Manual/ScriptingRestrictions.html

Could you help me figure out a workaround like this for my project?

@strangenoora
Copy link

After investigating further, I think a workaround won't be possible after all. The manual I linked specifically says namespace System.Reflection.Emit simply isn't supported. I will test Interpreted mode instead.

@strangenoora
Copy link

I tried the interpreted mode and it works like a charm.
Sorry for the spam!

Can I suggest adding a note in the readme for Unity projects (using IL2CPP) to consider using the Interpreted mode?

@pieterderycke
Copy link
Owner

@strangenoora I am happy to read that it solved your issue. I will document it in the readme.

@KoalaHao
Copy link
Author

@KoalaHao Did you already had time to try a more recent version of Jace inside a Unity project?

Sorry I didn't have time to try the new version. I've fixed the caps problem, force use interpreted mode, and it works

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

4 participants