4.3.33 Pro error with Burst 1.3.5 on Andriod with IL2CPP build

MarshalDirectiveException: Cannot marshal P/Invoke call through delegate of type '.CalculateBoundsDelegate' 
System.Func`9[T1,T2,T3,T4,T5,T6,T7,T8,TResult].EndInvoke (System.IAsyncResult result) (at :0) 
Pathfinding.Recast.RecastMeshGathererBurst..cctor () (at :0) 
Pathfinding.RecastGraph.CollectMeshesBurst (UnityEngine.Bounds bounds) (at :0) 
Pathfinding.RecastGraph+d__53.MoveNext () (at :0) 
Pathfinding.RecastGraph+d__46.MoveNext () (at :0) 
AstarPath+d__143.MoveNext () (at :0) 
AstarPath+d__142.MoveNext () (at :0) 
Code.Utils.AStartNavGenUtils+d__4.MoveNext () (at :0) 
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at :0) 
Rethrow as TypeInitializationException: The type initializer for 'Pathfinding.Recast.RecastMeshGathererBurst' threw an exception. Pathfinding.RecastGraph.CollectMeshesBurst (UnityEngine.Bounds bounds) (at :0) 
Pathfinding.RecastGraph+d__53.MoveNext () (at :0) 
Pathfinding.RecastGraph+d__46.MoveNext () (at :0) 
AstarPath+d__143.MoveNext () (at :0) 
AstarPath+d__142.MoveNext () (at :0) 
Code.Utils.AStartNavGenUtils+d__4.MoveNext () (at :0) 
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at :0) 

in editor and andriod mono build works fine. but IL2CPP build got an error when try to generate navmesh.

hope it can be fix soon.

thanks.

meantime which burst version i should use ?

try with

  • Burst 1.3.0
  • Collections 0.9.0-preview.6
  • Entitise 0.11.1-preview.4

still get the same error.

i can’t use Entitise 0.8.0-preview.8 . because it’s an error for Android platform.

@see : https://forum.unity.com/threads/entities-0-8-compile-error-in-android-platform.846583/

hope it can be fix soon.

thanks.

Hi

That’s odd. There is some code specifically to prevent that error in 4.3.33.

Can you check your RecastMeshGathererBurst script and see if the CalculateBounds method has a AOT.MonoPInvokeCallback attribute?

yes the RecastMeshGathererBurst have the AOT attribute.

and i try it with an empty project . still have the same error.

Env:
Unity 2020.1.3f1c1
Burst : 1.3.5
Collections : 0.12.0-preview.13
Entities: 0.14.0-preview.18
MacOS

Code:

using System.Collections;
using Pathfinding;
using UnityEngine;
using UnityEngine.UI;

public class TestCode : MonoBehaviour
{
    public GameObject AgentPrefab;

    void Start() { GameObject.Find("Canvas/Button").GetComponent<Button>().onClick.AddListener(OnClickTestBtn); }

    private void OnClickTestBtn()
    {
        Debug.Log("Click TestBtn");
        var btn = GameObject.Find("Canvas/Button");
        Destroy(btn);
        StartCoroutine(InitAStartPathFindSync());
    }


    private IEnumerator InitAStartPathFindSync()
    {
        Debug.Log("start add A* Root");
        //Init AStartSystem
        var go = new GameObject();
        var aStart = go.AddComponent<AstarPath>();
        aStart.threadCount = ThreadCount.AutomaticHighLoad;
        aStart.scanOnStartup = false;
        aStart.navmeshUpdates.updateInterval = -1; 

        yield return new WaitForSeconds(0.1f);

        Debug.Log("start add recast graph");

        AddNewRecastGraph();

        yield return new WaitForSeconds(0.1f);

        Debug.Log("start gen nav mesh");

        var r0 = AstarPath.active.data.graphs[0] as RecastGraph;
        r0.SnapForceBoundsToScene();
        foreach (var progress in AstarPath.active.ScanAsync(r0))
        {
            Debug.Log("gen nav mesh tick");
            yield return new WaitForSeconds(0.1f);
        }

        yield return new WaitForSeconds(0.1f);


        Debug.Log("start let demo agent move to aim target");

        var agentGo = Instantiate(AgentPrefab);
        agentGo.transform.position = Vector3.zero;

        var agent = agentGo.GetComponent<RichAI>();
        var aimTarget = GameObject.Find("AimTarget");
        agent.destination = aimTarget.transform.position;
    }


    private static void AddNewRecastGraph()
    {
        var rg = AstarPath.active.data.AddGraph(typeof(RecastGraph)) as RecastGraph;
        rg.cellSize = 0.25f;
        rg.useTiles = false;
        rg.minRegionSize = 3;
        rg.characterRadius = 0.5f;
        rg.maxSlope = 0f;
        rg.rasterizeColliders = false;
        rg.rasterizeTerrain = false;
        rg.rasterizeTrees = false;
        rg.rasterizeMeshes = true;
    }
}

Result:

it seem the fourth progress (var progress in AstarPath.active.ScanAsync(r0)) get the error.

and it only appear in IL2CPP build .

Hi Aron

i have try the 4.3.34 version with Burst 1.3.6 still got the same error.

and i also upgrade my unity version to 2020.1.4f1c1. still no luck.

=====

which version Burst and unity you used?

thanks

Eran.

I have no idea what is causing it. As far as I can tell all necessary attributes are there.

The minimum supported burst version is 1.3.0-preview.7.

AStartBugDemo.unitypackage

Can you try to build this demo in your PC to see is there have the same issue? thanks

it require free version LunarConsole (can find in AssetStore).

the build target is

Android IL2CPP build with MinimumAPI Level 19(Android 4.4 KitKat)

Do you get the same error in a non-android IL2CPP build?

no, works fine in mono build . only got error in IL2CPP build.

Yes but does it work fine in a non-android IL2CPP build?

no IL2CPP Mac build got the same error :frowning:

I managed to replicate the bug and fix it.
A fix will be included in the next beta version update.

Thanks!

cool ! thanks. looking forward for the next version !

Hi, ran into same issue with 4.3.34. Is it a small fix that I could just patch in?

@Crembo Here’s the diff https://pastebin.com/8u4RcXLc