Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice
  2. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

Adding 3 images to runtime reference library but only 2 get added

Discussion in 'AR' started by jokigenki, May 16, 2020.

  1. jokigenki

    jokigenki

    Joined:
    Jul 19, 2014
    Posts:
    28
    I have a method that adds 3 images to the runtime library, but only 2 get added. The method is as follows:
    I can't see what I'm doing wrong.

    Owen

    Code (CSharp):
    1. private void AddTexturesToLibrary(MutableRuntimeReferenceImageLibrary mLib, Texture2D[] images)
    2.         {
    3.             _addingImages = images;
    4.             var handles = new List<JobHandle>();
    5.             var tasks = new List<UniTask>();
    6.             foreach (Texture2D tex in images)
    7.             {
    8.                 Debug.Log($"Add Texture To Library {tex.name} {tex.format} {tex.isReadable} {tex.width}x{tex.height}");
    9.                 if (mLib.IsTextureFormatSupported(tex.format))
    10.                 {
    11.                     var jobHandle = mLib.ScheduleAddImageJob (tex, tex.name, 0.21f);
    12.                     handles.Add(jobHandle);
    13.                     tasks.Add(jobHandle.ToUniTask());
    14.                 }
    15.                 else
    16.                 {
    17.                     Debug.LogWarning($"Texture format {tex.format} is not supported"); // never called
    18.                 }
    19.             }
    20.            
    21.             Debug.Log($"Scheduled {tasks.Count} {handles.Count} jobs"); // 3 and 3
    22.             JobHandle.ScheduleBatchedJobs();
    23.            
    24.             UniTask.WhenAll(tasks).ToObservable().ObserveOn(Scheduler.MainThread).Subscribe(result =>
    25.                 {
    26.  
    27.                     Debug.Log($"Completed {tasks.Count} {handles.Count} jobs"); // 3 and 3
    28.                     for (var i = 0; i < handles.Count; i++)
    29.                     {
    30.                         JobHandle handle = handles[i];
    31.                         handle.Complete();
    32.                         Debug.Log($"handle {handle.IsCompleted}"); // only called twice
    33.                     }
    34.  
    35.                     Debug.Log($"BUILT RUNTIME LIBRARY with {mLib.count} images "); // 2
    36.                 }
    37.             );
    38.         }
     
  2. jokigenki

    jokigenki

    Joined:
    Jul 19, 2014
    Posts:
    28
    Update: seems to work ok on iOS but not Android.
     
unityunity