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

Unity 2019.4.12f1 native pointer issue with JobMetaLoader #3

Open
emilianavt opened this issue Nov 9, 2020 · 2 comments
Open

Unity 2019.4.12f1 native pointer issue with JobMetaLoader #3

emilianavt opened this issue Nov 9, 2020 · 2 comments

Comments

@emilianavt
Copy link

Hi!

Thank you for your work on this! I have tested the MetaLoader class and found a 3.6x speedup compared to using VRMImporterContext.

I also wanted to try the jobs based loader, but it refused to run due to the unsafe native pointer restriction introduced in Unity. After decorating the loader pointers with [NativeDisableUnsafePtrRestrictionAttribute] (documentation), there no longer was an error, but instead Unity crashed. Do you think it is possible to make the JobMetaLoader work on the current Unity version?

I added [NativeDisableUnsafePtrRestrictionAttribute] before these lines:

@m2wasabi
Copy link
Owner

m2wasabi commented Nov 16, 2020

Hello emilianavt , thanks your comment.

JobMetaLoader using unsafe codes.
To enable unsafe features, please install asmdef file.

VRMQuickMetaLoader.0.1.0.asmdef.unitypackage

@emilianavt
Copy link
Author

Thank you for your response!

I have imported it now, but when running the following code:

using(var metaLoader = new JobMetaLoader(filename, preloadThumbnail: true))
{
    VRMMetaObject meta = metaLoader.Read();
    nameText.text = meta.Title;
    thumbnail.texture =  metaLoader.LoadThumbnail();
}

I get the following exception:

InvalidOperationException: InterpretMagicAndLoadJsonJob.loader uses unsafe Pointers which is not allowed. Unsafe Pointers can lead to crashes and no safety against race conditions can be provided.
If you really need to use unsafe pointers, you can disable this check using [NativeDisableUnsafePtrRestriction].
Unity.Jobs.LowLevel.Unsafe.JobsUtility.CreateJobReflectionData (System.Type type, Unity.Jobs.LowLevel.Unsafe.JobType jobType, System.Object managedJobFunction0, System.Object managedJobFunction1, System.Object managedJobFunction2) (at <a4546799a4ab426788e4204c69507924>:0)
Unity.Jobs.IJobExtensions+JobStruct`1[T].Initialize () (at <a4546799a4ab426788e4204c69507924>:0)
Unity.Jobs.IJobExtensions.Schedule[T] (T jobData, Unity.Jobs.JobHandle dependsOn) (at <a4546799a4ab426788e4204c69507924>:0)
VRM.QuickMetaLoader.JobMetaLoaderInternal.ScheduleJob (VRM.QuickMetaLoader.JobMetaLoaderInternal* answer) (at Assets/VRM.QuickMetaLoader/Scripts/JobMetaLoaderInternal.cs:103)
VRM.QuickMetaLoader.JobMetaLoaderInternal.Create (System.String path) (at Assets/VRM.QuickMetaLoader/Scripts/JobMetaLoaderInternal.cs:86)
VRM.QuickMetaLoader.JobMetaLoader..ctor (System.String path, System.Boolean preloadThumbnail) (at Assets/VRM.QuickMetaLoader/Scripts/JobMetaLoader.cs:25)
AvatarSelect.Start () (at Assets/VSeeFace/AvatarSelect.cs:37)

The asmdef is installed and Allow 'unsafe' code is also enabled in the player settings for other components.

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

2 participants