[Bug] Burst Inspector Exception (for custom jobs and mismatching generic arguments)

I have a custom job,

[JobProducerType(typeof(JobNativeMultiHashMapVisitUniqueKey.NativeMultiHashMapVisitUniqueKeyJobStruct<,,>))]
public interface IJobNativeMultiHashMapVisitUniqueKey<TKey>
    where TKey : struct, IEquatable<TKey>
{
    void Execute(TKey key);
}

Implemented with

internal struct NativeMultiHashMapVisitUniqueKeyJobStruct<TJob, TKey, TValue>
            where TJob : struct, IJobNativeMultiHashMapVisitUniqueKey<TKey>
            where TKey : struct, IEquatable<TKey>
            where TValue : struct
        {

But when loading the Burst Inspector it throws this exception

However if I add a dummy parameter

[JobProducerType(typeof(JobNativeMultiHashMapVisitUniqueKey.NativeMultiHashMapVisitUniqueKeyJobStruct<,,>))]
public interface IJobNativeMultiHashMapVisitUniqueKey<TKey, TValue>
    where TKey : struct, IEquatable<TKey>
    where TValue : struct
{
    void Execute(TKey key);
}

It know throws an exception about missing an execute method.

As I’m assuming it’s expecting an Execute method to match the parameters of the generic arguments.

===================

This version
IJobNativeMultiHashMapVisitUniqueKey
Seems to compile fine with burst in editor but fails to compile with burst at runtime.

But
IJobNativeMultiHashMapVisitUniqueKey<TKey, TValue>
Compiles fine even at runtime even though the value generic is not used.

If NativeMultiHashMapVisitUniqueKeyJobStruct<TJob, TKey, TValue> is expecting TValue, it has to be part of IXXXJob interface.

But also implementing a custom job requires the actual Execute method (the real one that will be used as an entry point) to be declared on the struct behind JobProducerType… You can have a look at how it is working for IJob by using ILSpy, but I’m not sure custom jobs are something publicly exposed today as “ready for end-user usage”

Thanks for the reply. I wasn’t sure why the single generic method didn’t work, or why the generic interfaces had to match but I should have emphasized that I was actually using the dual generic interface which appeared to work fine just threw that missing Execute method when loading burst inspector.

[JobProducerType(typeof(JobNativeMultiHashMapVisitUniqueKey.NativeMultiHashMapVisitUniqueKeyJobStruct<,,>))]
public interface IJobNativeMultiHashMapVisitUniqueKey<TKey, TValue>
    where TKey : struct, IEquatable<TKey>
    where TValue : struct
{
    void Execute(TKey key);
}

I did just figure out my issue though. I thought the error was relating to Execute method on the interface but it’s actually the Execute method on the JobProducer

internal struct NativeMultiHashMapVisitUniqueKeyJobStruct<TJob, TKey, TValue>

The issue was simply that my execute method

public static unsafe void Execute(
                ref NativeMultiHashMapVisitUniqueKeyJobStruct<TJob, TKey, TValue> fullData,
                IntPtr additionalPtr,
                IntPtr bufferRangePatchData,
                ref JobRanges ranges,
                int jobIndex)
            {

was private. While the BurstReflection class expected it to be public

var executeType = foundProducer.MakeGenericType(genericParams.ToArray());
var executeMethod = executeType.GetMethod("Execute"); // will not return private methods
if (executeMethod == null)
{
    throw new InvalidOperationException($"Burst reflection error. The type `{executeType}` does not contain an `Execute` method");
}
1 Like

Indeed, good catch, that’s an oversight, we will improve this error message.