Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to enable AOT for other platforms besides iOS 2 Answers

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges