I have the job below that makes a calls to a method from a native plugin. Without burst it works fine, but once I add the burst tags, I get an Unable to Load Plugin error following by warnings that burst is now disabled for all my other jobs.
Should I be able to do this or am I doing something incorrectly?
using System;
using System.Runtime.InteropServices;
using Unity.Burst;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Jobs;
[BurstCompile]
public unsafe static class PolygonClip {
const string clipperDll = "Assets/Scripts/Plugins/Clipper/Clipper2_64";
[DllImport(clipperDll)]
static extern int BooleanOpF(byte clipType, float* subjects, float* clips, out IntPtr solution);
private static JobHandle _jobHandle;
private static PolygonClipJob _clipJob;
private static bool _jobRunning = false;
public static bool JobRunning => _jobRunning;
public static void StartJob(byte clipType, float* clipPathPtr, float* subjectPathPtr) {
if (!_jobRunning) {
var solutionIntPtr = new NativeReference<IntPtr>(Allocator.TempJob);
_clipJob = new PolygonClipJob() {
clipType = clipType,
clipPathPtr = clipPathPtr,
subjectPathPtr = subjectPathPtr,
solutionIntPtr = solutionIntPtr
};
_jobHandle = _clipJob.Schedule();
_jobRunning = true;
}
}
public static bool CompleteJob(out NativeArray<float> solution) {
solution = default;
if (_jobRunning && _jobHandle.IsCompleted) {
_jobHandle.Complete();
_jobRunning = false;
var resultIntPtr = _clipJob.solutionIntPtr.Value;
_clipJob.solutionIntPtr.Dispose();
if (Clipper.SolutionFromIntPtr(resultIntPtr, out var sol)) {
solution = sol;
return true;
}
}
return false;
}
[BurstCompile]
unsafe struct PolygonClipJob : IJob {
[ReadOnly] public byte clipType;
[NativeDisableUnsafePtrRestriction] public float* clipPathPtr;
[NativeDisableUnsafePtrRestriction] public float* subjectPathPtr;
[NativeDisableUnsafePtrRestriction, WriteOnly] public NativeReference<IntPtr> solutionIntPtr;
[BurstCompile]
public void Execute() {
BooleanOpF(clipType, subjectPathPtr, clipPathPtr, out IntPtr solution);
solutionIntPtr.Value = solution;
}
}
}