Help regarding calls to native plugin from burst enabled job

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;
    }

  }

}

DllImport of non-platform native libraries is documented as supported. Specifying a path in DllImport is not very common (see also Mono docs for their DllImport support), so Burst may not be taking that into account. Try removing the path information and keep it to just the library name.

1 Like

Yep! That did it. No longer greyed out in the burst inspector.

Thank you!