• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ikeo · Jun 03, 2011 at 05:08 PM · exceptionsqliteaotjitexecutionengineexception

Custom functions in SQLite and Unity

I'm using Mono.Data.Sqlite to access sqlite database files with Unity and iOS. The function I'm using calculates a distance based on values in a table. I did this because, as best I can tell, most of the useful math operations are not available with Sqlite. The function is defined as follows:

 [SqliteFunctionAttribute(Name = "distance", Arguments = 6, FuncType = FunctionType.Scalar)]
 class SqliteDistance : SqliteFunction
 {
     public override object Invoke(object[] args)
     {
         double x1 = System.Convert.ToDouble(args[0]);
         double y1 = System.Convert.ToDouble(args[1]);
         double z1 = System.Convert.ToDouble(args[2]);
         double x2 = System.Convert.ToDouble(args[3]);
         double y2 = System.Convert.ToDouble(args[4]);
         double z2 = System.Convert.ToDouble(args[5]);
         
         return Math.Sqrt(Math.Pow(x1-x2,2) + Math.Pow(y1-y2,2) + Math.Pow(z1-z2,2));
     }
 }

When I run this in the editor, it works great. When I attempt to run the same code on the device, get a my favorite mono exception:

ExecutionEngineException: Attempting to JIT compile method '(wrapper native-to-managed) Mono.Data.Sqlite.SqliteFunction:ScalarCallback (intptr,int,intptr)' while running with --aot-only.

This suggests to me that mono can't aot compile my custom function. Has anyone been able to make a custom function work using SQLite and Unity with iOS?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ikeo · Jun 03, 2011 at 07:04 PM

I figured out an acceptable workaround for this one. Although I couldn't get the custom function to work, I was able to use distance comparison of sorts. SQLite contains the '*' operator, so I simply used the squared distance and dropped the square root altogether. I am using three values from each record, "center_x," center_y", and "center_z". I'm filtering the query results based on the distance between this "center" and my main camera position. This is the final SQLite query syntax:

 Vector3 camPos = Camera.main.transform.position;
     
 string xTerm = "(center_x-(" + camPos.x + ")) * (center_x-(" + camPos.x+"))";
 string yTerm = "(center_y-(" + camPos.y + ")) * (center_y-(" + camPos.y+"))";
 string zTerm = "(center_z-(" + camPos.x + ")) * (center_z-(" + camPos.z+"))";
 string sqDist = "(" + xTerm + " + " + yTerm + " + " + zTerm + ")";
 string sqTol = "(" + _nearTolerance + "*" + _nearTolerance + ")";
 string meshTableQuery = "SELECT Id, vertices, triangles, material_id FROM meshes WHERE " + sqDist + "<" + sqTol + ";";
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Sqlite databases getting locked by Unity. 2 Answers

Why does SQLite throw InvalidOperationException in Unity 5.3? 1 Answer

JIT exception with ToArray() Linq 2 Answers

Saving Data on IOS produces JIT Error in Xcode 2 Answers

Create AOT checklist for IOS (ExecutionEngineException) 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges