Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

AR Foundation Remote | Test and debug your AR project in the Editor

Discussion in 'Assets and Asset Store' started by KyryloKuzyk, May 26, 2020.

  1. JudahMantell

    JudahMantell

    Joined:
    Feb 28, 2017
    Posts:
    476
    Adding that scripting define and changing the build type to APK worked! Thanks!
     
    KyryloKuzyk likes this.
  2. Fangh

    Fangh

    Joined:
    Apr 19, 2013
    Posts:
    274
    When I use the Unity Cloud Build, sometime I have this error, sometime not :


    Why should I add AR_COMPANION to my app ? Maybe the unity cloud build think my app is the companion app. But my app is not the companion app.
     
    KyryloKuzyk likes this.
  3. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    Yes, I can confirm this is a bug. I'll fix it in the next plugin version, thanks for reporting it!
     
  4. dogsaregreat

    dogsaregreat

    Joined:
    Sep 5, 2018
    Posts:
    21
    when i do a live mesh scan in the editor+phone when it play mode, is there a way to save the mesh data after exiting play mode?
     
  5. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    There is no built-in way to save the mesh, you have to write it yourself.
    I can recommend using the FBX Exporter to save the mesh.
    https://docs.unity3d.com/Packages/com.unity.formats.fbx@2.0/manual/index.html

    Also, to debug the code that saves the mesh, you can select all scanned meshes inside the Unity Editor by pressing ctrl+c. Then exit play mode and paste the copied objects to your scene.
     
  6. Bersaelor

    Bersaelor

    Joined:
    Oct 8, 2016
    Posts:
    110
    Dear @KirillKuzyk ,

    thank you for the Remote 2.0, I checked it out today.

    So, for my current project I only want to use the AR Remote when the editor is switched to iOS or Android, but not when testing the Standalone-Desktop-Builds. The game runs normal 3D on desktop screens, but in AR on mobile devices.
    Of course the AR Foundation Remote Plugin needs to be enabled under XR Plugin Management for Standalone, to work in the Editor, can I make it so it it doesn't run when starting actual desktop mode in the Editor?
     
    KyryloKuzyk likes this.
  7. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    Yes, I agree that the plugin should only work when the build target is switched to iOS/Android. The only reason I decided to run the plugin in the Standalone target is the potential support for HoloLens/Magic Leap in the future.
    I will fix this in the next plugin version.
     
    Bersaelor likes this.
  8. Fangh

    Fangh

    Joined:
    Apr 19, 2013
    Posts:
    274
    Hello.
    What should I do as a workaround ?
    Because now, my Companion app is called "AppName" and my app is call "ARCompanionAppName"
     
  9. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    Sorry, I've already fixed the issue with building non-ARCompanion apps in UCB but forgot to tell you about it. Could you please update the plugin to the latest version and tell me if the fix works for you?
    Also, please check your repository has the correct app name before making a new UCB build, the plugin should not modify the app name now.
     
    Fangh likes this.
  10. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    Done! Please update to the latest plugin version.
     
    Bersaelor likes this.
  11. plb3d

    plb3d

    Joined:
    Jun 15, 2018
    Posts:
    3
    Hello, I can't connect my android smartphone. I wrote the ip displayed on my smartphone in the ip companion field but when I click on play nothing happens.
    I am connected by usb cable and not wifi.






    Here is the messages from the console:



    Client Recv Exception: System.Exception: Connection to 100.64.69.27 failed with exception: System.AggregateException: One or more errors occurred. (Une tentative de connexion a échoué car le parti connecté n’a pas répondu convenablement au-delà d’une certaine durée ou une connexion établie a échoué car l’hôte de connexion n’a pas répondu.

    UnityEngine.Debug:LogError (object)
    ARFoundationRemote.Runtime.TelepathyConnection/<>c:<Awake>b__12_1 (string) (at Library/PackageCache/com.kyrylokuzyk.arfoundationremote@efd3f754d6ca/Runtime/Connection/TelepathyConnection.cs:63)
    Telepathy.Client:ReceiveThreadFunction (string,int) (at Library/PackageCache/com.kyrylokuzyk.arfoundationremote@efd3f754d6ca/Runtime/Connection/Telepathy/Client.cs:107)
    Telepathy.Client/<>c__DisplayClass11_0:<Connect>b__0 () (at Library/PackageCache/com.kyrylokuzyk.arfoundationremote@efd3f754d6ca/Runtime/Connection/Telepathy/Client.cs:171)
    System.Threading.ThreadHelper:ThreadStart ()




    AR Foundation Remote: connection to AR Companion app failed. Please check that:
    1. Unity Editor and AR Device are on the same Wi-Fi network.
    2. AR Companion is running and device is unlocked.
    3. The IP is correct in Assets/Plugins/ARFoundationRemoteInstaller/Resources/Settings

    If the connection is still failing, please try to configure your AR Device's Wi-Fi to have a static IP.
    iOS: https://www.mobi-pos.com/web/guide/settings/static-ip-configuration
    Android: https://service.uoregon.edu/TDClient/2030/Portal/KB/ArticleDet?ID=33742

    OR
    Try to create a hotspot on your AR device and then connect your computer to it.

    OR
    Try a wired connection (see Documentation).

    UnityEngine.Debug:LogError (object)
    ARFoundationRemote.RuntimeEditor.TelepathyReceiverConnection/<startConnectionCor>d__1:MoveNext () (at Library/PackageCache/com.kyrylokuzyk.arfoundationremote@efd3f754d6ca/Runtime/Connection/TelepathyReceiverConnection.cs:31)
    UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)



    I don't understand what the problem is.

    Do you have any ideas to help me please?

    Patrick
     

    Attached Files:

  12. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    Please see the documentation for a wired connection setup:
     
  13. plb3d

    plb3d

    Joined:
    Jun 15, 2018
    Posts:
    3
    Thank you.
    How to open the adb tool on my android device ?

    on windows cmd :
    C:\Users\123>adb devices
    List of devices attached
    RZ8R506H08B device


    C:\Users\123>adb tcpip PORT
    adb.exe: tcpip: invalid port: PORT

    :(
     
    Last edited: Apr 17, 2022
  14. Bersaelor

    Bersaelor

    Joined:
    Oct 8, 2016
    Posts:
    110
    Thank you for the fast update, I did and it works!
    I also agree that the warning to switch the editor to `iOS/Android` to get AR Remote working is nice, this way we remember why the remote is not starting.
     
    KyryloKuzyk likes this.
  15. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    adb is a desktop tool that comes with Android SDK. You can install Android SDK yourself or use the one that comes with Unity installation.

    For example, on macOS adb can be found at this path: /Applications/Unity/Hub/Editor/2021.3.0f1/PlaybackEngines/AndroidPlayer/SDK/platform-tools/adb

    Have you tried executing this command?
    adb forward tcp:44819 tcp:44819
     
  16. plb3d

    plb3d

    Joined:
    Jun 15, 2018
    Posts:
    3
    C:\Users\123>adb forward tcp:44819 tcp:44819
    44819

    I don't see any change.

    BUT

    I managed to connect via the wifi hotspot of my pc.

    I will work with the wifi mode and abandon the wired usb mode.

    Thanks for your help.
     
    Last edited: Apr 18, 2022
    KyryloKuzyk likes this.
  17. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    After executing the
    adb forward tcp
    command you should be able to connect to the AR Companion by entering the '127.0.0.1' in the plugin's settings.
     
  18. pwojciechowski

    pwojciechowski

    Joined:
    Jun 15, 2019
    Posts:
    4
    Camera.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2)) is not returning good values in newest release.
    In Editor - all the time vector3 value is vector3(0,0,1)

    Any ideas? Does anything changed here from last release?

    In previous release everything was working fine, now impossible to test in editor. In build it is working correct
     
    Last edited: Apr 28, 2022
  19. pwojciechowski

    pwojciechowski

    Joined:
    Jun 15, 2019
    Posts:
    4
    BTW using ar foundation remote 2 for debugging on USB drain phone battery a lot. Is there a way to optimize it to be less power consumption ?
     
  20. BlackclawsK

    BlackclawsK

    Joined:
    Jan 9, 2019
    Posts:
    100
    We've run into an issue when trying to use this tool, namely it doesn't seem to support the graphics apis available on Linux.

    When running the application the general connection and everything works, however I get the error:

    AR Foundation Remote: camera video and occlusion are not supported on current Editor Graphics API: Vulkan.
    Please set the 'Project Settings/Player/Settings for PC.../Graphics Api for YOUR_PLATFORM' to one of these APIs and restart Unity Editor:
    Metal, Direct3D11

    UnityEngine.Debug:LogError (object)

    Well Metal and Direct3D11 are both not available on Linux so I guess this tool simply doesn't work on Linux?
     
  21. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    Hmm, the plugin should not influence the non-AR Foundation APIs. Are you sure nothing has changed except the plugin version since the last time the Camera.ScreenPointToRay() worked for you?

    Could you please share more info so I can replicate your issue on my side?
    1. Unity version. Windows or macOS?
    2. Send me your Packages/manifest.json and Packages/packages-lock.json files.
    3. Your AR device and its OS version.
    4. Plugin version. You can find it in the Packages/AR Foundation Remote/package.json file.

    Also a small reproducible project would be perfect to have!

    The AR is a very battery-intensive feature, but you can try to lower the AR Companion app framerate in the plugin's setting (AR Companion Setting/Target Frame Rate). But please note that some AR features may stop working under a low framerate. For example, Face Tracking doesn't work on Android if the framerate is 15 or lower.
     
  22. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    With the help of @BlackclawsK I was able to reproduce the issue and fix it internally.

    The issue is only applicable to Linux Unity Editor because the plugin only supports Metal and Direct3D11, but Linux Editor doesn't support these graphics APIs.

    The issue was in the depth buffer direction. Metal uses reversed direction, while OpenGLCore uses a traditional direction. The plugin's camera shader only supports the reversed direction, so it writes incorrect values to the depth buffer, overwriting all visible geometry.

    The fix is coming in the next plugin's release as soon as BlackclawsK confirms the fix works on Linux.

    Huge thanks for finding the bug!
     
  23. ondrevo

    ondrevo

    Joined:
    May 4, 2020
    Posts:
    2
    Hello,

    when I use your plugin I've got this error. Any idea how to fix it? I'd prefer to add no extra code to my project because of the plugin.

    Code (CSharp):
    1. Exception: AR Foundation Remote: please don't call blocking methods while AR Companion is not connected. You can check if the AR Companion app is connected with this property: ARFoundationRemote.Runtime.Connection.Instance.isConnected
    2. ARFoundationRemote.Runtime.TelepathyConnection.ARFoundationRemote.Runtime.IConnection.BlockUntilReceive[ResponseType] (System.Guid guid) (at Library/PackageCache/com.kyrylokuzyk.arfoundationremote@ff7bc758562c/Runtime/Connection/TelepathyConnection.cs:255)
    3. ARFoundationRemote.Runtime.Connection.BlockUntilReceive[ResponseType] (ARFoundationRemote.Runtime.BlockingMessage payload) (at Library/PackageCache/com.kyrylokuzyk.arfoundationremote@ff7bc758562c/Runtime/Connection/Connection.cs:80)
    4. ARFoundationRemote.Runtime.SessionSubsystem+ARemoteSessionSubsystemProvider.GetConfigurationDescriptors (Unity.Collections.Allocator allocator) (at Library/PackageCache/com.kyrylokuzyk.arfoundationremote@ff7bc758562c/Runtime/SessionSubsystem.cs:147)
    5. UnityEngine.XR.ARSubsystems.XRSessionSubsystem.GetConfigurationDescriptors (Unity.Collections.Allocator allocator) (at Library/PackageCache/com.unity.xr.arsubsystems@4.2.2/Runtime/SessionSubsystem/XRSessionSubsystem.cs:194)
    6. UnityEngine.XR.ARSubsystems.XRSessionSubsystem.DetermineConfiguration (UnityEngine.XR.ARSubsystems.Feature features) (at Library/PackageCache/com.unity.xr.arsubsystems@4.2.2/Runtime/SessionSubsystem/XRSessionSubsystem.cs:92)
    7. UnityEngine.XR.ARSubsystems.XRSessionSubsystem.Update (UnityEngine.XR.ARSubsystems.XRSessionUpdateParams updateParams) (at Library/PackageCache/com.unity.xr.arsubsystems@4.2.2/Runtime/SessionSubsystem/XRSessionSubsystem.cs:124)
    8. UnityEngine.XR.ARFoundation.ARSession.Update () (at Library/PackageCache/com.unity.xr.arfoundation@4.2.2/Runtime/AR/ARSession.cs:415)
     
  24. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    Could you please tell me the plugin version? This issue should be fixed a long ago.
     
  25. ondrevo

    ondrevo

    Joined:
    May 4, 2020
    Posts:
    2
    It's Version 2.0.21-release.2 But today I tried again and it works. I don't understand why.
     
    Last edited: May 10, 2022
  26. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    I'll double-check this. Please send me any additional info that can help me to debug the issue.
     
  27. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    KirillKuzyk Hi,

    Ive got AR Foundation Editor Remote 4.8.22 and have just updated Unity to 2021.3.3f1 and now are getting errors, is this compatible or do I need to upgrade?

    Also how would I remove AR Foundation Editor Remote? would I just go into packet manager choose AR Foundation Editor Remote and use the Remove button?

    Thanks, Kevin.

    Packages/com.kyrylokuzyk.arfoundationremote/Runtime/FaceSubsystem/FaceSubsystemSender.cs(76,50): error CS0104: 'NotNull' is an ambiguous reference between 'JetBrains.Annotations.NotNullAttribute' and 'System.Diagnostics.CodeAnalysis.NotNullAttribute'

    Packages/com.kyrylokuzyk.arfoundationremote/Runtime/FaceSubsystem/FaceSubsystemSender.cs(202,10): error CS0104: 'NotNull' is an ambiguous reference between 'JetBrains.Annotations.NotNullAttribute' and 'System.Diagnostics.CodeAnalysis.NotNullAttribute'

    Packages/com.kyrylokuzyk.arfoundationremote/Runtime/FaceSubsystem/FaceSubsystemSender.cs(203,10): error CS0104: 'NotNull' is an ambiguous reference between 'JetBrains.Annotations.NotNullAttribute' and 'System.Diagnostics.CodeAnalysis.NotNullAttribute'

    Packages/com.kyrylokuzyk.arfoundationremote/Runtime/FaceSubsystem/FaceSubsystemSender.cs(209,10): error CS0104: 'NotNull' is an ambiguous reference between 'JetBrains.Annotations.NotNullAttribute' and 'System.Diagnostics.CodeAnalysis.NotNullAttribute'
     
    Last edited: May 21, 2022
  28. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    Hi,

    Please update to the latest plugin version, this error is already fixed.
     
  29. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    Hi, Ive installed version 1.4.21 but still getting errors, stuck at picture below.

    I've tried downloading it again and re importing it, but says nothing to import.

    Screenshot 2022-05-22 at 10.04.56.png
     
  30. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    Just tested the latest plugin version with Unity 2021.3.3f1 and everything works fine. Please try to uninstall the plugin completely before updating it to a newer version. The difference between version 4.8.22 and 2.0.21-release.2 is big, so Package Manager can't handle the update correctly.
     
  31. JanetGilbertPraxis

    JanetGilbertPraxis

    Joined:
    May 6, 2022
    Posts:
    22
    Why does this plugin install com.unity.xr.arfoundation@4.0.12 into my packages folder? My AR foundation version is already 4.0.12
     
  32. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    Please ensure you're using the latest plugin version. The latest plugin version does not embed the AR Foundation package automatically. Now, embedding is only required in a few rare cases:
    1. The project uses the URP package until this feature request is completed: https://github.com/Unity-Technologies/arfoundation-samples/issues/961.
    2. The project uses raycasts against point clouds, see this bug report: https://github.com/Unity-Technologies/arfoundation-samples/issues/960.
    3. The project uses face tracking with AR Foundation < 4.1 (newer versions of AR Foundation will work out of the box).
    4. With older versions of Unity that crash on calling the CommandBuffer.IssuePluginEvent in the ARCameraBackground: https://forum.unity.com/threads/arfoundation-arcamerabackground-commandbuffer-freezes-editor.1019461
     
    Last edited: Jun 13, 2022
  33. JanetGilbertPraxis

    JanetGilbertPraxis

    Joined:
    May 6, 2022
    Posts:
    22
    Yes, my project uses URP.

    I don't want to install anything in my project that will affect any other users, as I'm the only one in a large team who uses AR Foundation Remote. I'm worried that installing things into packages may break other developers' code.

    Aside from that it works great.
     
  34. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    I created a Q&A post on the plugin's support page, please feel free to ask more questions on the topic here:
    https://github.com/KirillKuzyk/AR-Foundation-Remote-support/discussions/3
     
  35. JanetGilbertPraxis

    JanetGilbertPraxis

    Joined:
    May 6, 2022
    Posts:
    22
    My question is, how can I install the plugin only on my computer without having to commit anything to Git? The rest of my team do not use this plugin. I don't want them to have to install it or else the build is broken.
     
  36. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    The plugin doesn't influence regular builds and doesn't add performance overhead in production. You can safely build your project with the plugin installed.

    I would not recommend doing this for consistency reasons, but here is how:
    1. Ignore the Packages/com.unity.xr.arfoundation@x.x.x folder.
    2. Ignore the Packages/packages-lock.json file because it changes when you embed a package.
    3. Ignore the Assets/Plugins/ARFoundationRemoteInstaller folder.
     
  37. JanetGilbertPraxis

    JanetGilbertPraxis

    Joined:
    May 6, 2022
    Posts:
    22
    I can't ignore the packages-lock.json file as it is used in our project.
    I guess I could ignore everything else and just remember to revert that file every time I commit.
     
    KyryloKuzyk likes this.
  38. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    Not the most elegant solution, but this will work. Or you can just leave the file in 'Unstaged files' and don't add it to your commits.
     
    JanetGilbertPraxis likes this.
  39. Ikaro88

    Ikaro88

    Joined:
    Jun 6, 2016
    Posts:
    296
    With this plugin I can also connect an Apple 12 pro with a windows machine?
     
  40. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    Ikaro88 likes this.
  41. Ikaro88

    Ikaro88

    Joined:
    Jun 6, 2016
    Posts:
    296
    KyryloKuzyk likes this.
  42. kidsfab

    kidsfab

    Joined:
    Oct 16, 2018
    Posts:
    19
    Hi ! so I have recently updated my project from 2019 to 2021 and I got AR foundation remote to work OK in editor but on an IOS build I get a weird old TV tuner glitch instead of the camera background.

    It seems to happen only with UI. if I disable Ui, I get the camera feed as expected. I believe something is off with URP. Anyone any thoughts ?


    glitchOnIOSbuildAR.jpg
     
  43. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    Version 2.0 adds three new features: Session Recording and Playback, ARCore Cloud Anchors support, and Input System (New) support. You can find more details in this blog post.
    Both versions are identical in terms of performance, supported AR Foundation/Unity versions, and the quality of provided support.
     
  44. bambamyi

    bambamyi

    Joined:
    Nov 26, 2008
    Posts:
    90
    I have a problem... I built the ARCompanion app and deplpyed to my iPhone12 PRO and my project works fine on Mac with meshing. Now on Windows, the same project and same branch, the unity editor crashes. I discovered that, if I turn off meshing on AR Session Origin, the windows unity editor does not crash anymore. Any thoughts?
     
  45. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    Please check if you're using the latest version of the plugin.

    If you are, and the crash is still occurring, please submit a bug report here:
    https://github.com/KirillKuzyk/AR-Foundation-Remote-support/issues/new/choose
    Please also attach your Editor.log file, you can find it here:
    https://docs.unity3d.com/Manual/LogFiles.html
     
  46. Nereus248B

    Nereus248B

    Joined:
    Jan 10, 2020
    Posts:
    1
    I'm having the same issue. Setup:
    • Unity 2020.3.34f1
    • Win10
    • ARFoundationRemote 2.0.23-release0
    • ARFoundation 4.1.10
    • ARKit XR Plugin 4.1.10
    From the crash log:

    Stacktrace:
    =================================================================
    Got a SIGILL while executing native code. This usually indicates
    a fatal error in the mono runtime or one of the native libraries
    used by your application.
    =================================================================

    ========== OUTPUTTING STACK TRACE ==================
    0x00007FFCE00129AF (libARFRemote) SetUnscaledTime
    0x00007FF7E75915A6 (Unity) XRMeshingSubsystem::AcquireMeshRouter
    0x00007FF7E7592DAA (Unity) xr::processMeshJob
    0x00007FF7E6D72EBB (Unity) JobQueue::Exec
    0x00007FF7E6D74B12 (Unity) JobQueue::Steal
    0x00007FF7E6D73260 (Unity) JobQueue::ExecuteJobFromQueue
    0x00007FF7E6D736CB (Unity) JobQueue::processJobs
    0x00007FF7E6D754FF (Unity) JobQueue::WorkLoop
    0x00007FF7E6F41E96 (Unity) Thread::RunThreadWrapper
    0x00007FFD043C7034 (KERNEL32) BaseThreadInitThunk
    0x00007FFD04E82651 (ntdll) RtlUserThreadStart
    ========== END OF STACKTRACE ===========
     
  47. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    I believe I've fixed the issue. Please send me your Invoice Number in private messages or in an email (kuzykkirill@gmail.com) and I'll send you a pre-release version with a fix.
    I'll post a detailed report about the bug a bit later when I confirm the fix works on all platforms.
     
  48. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    PLUGIN UPDATE POST #13

    So. For me, yesterday was a full-day marathon of chasing a Unity crash caused by the plugin and a meshing feature. And I think it is worth telling more about it.

    Can you spot a potential place where a crash may occur? This code is called from multiple threads:
    Code (CSharp):
    1.  
    2. generatedMeshesMutex.lock();
    3. if (!generatedMeshes.empty()) {
    4.     auto data = generatedMeshes.front();
    5.     if (data->meshId0 == meshId->idPart[0] && data->meshId1 == meshId->idPart[1]) {
    6.         logMeshId("mesh data found", *meshId);
    7.         if (data->isSuccess) {
    8.             auto allAttributesExceptColors = (UnityXRMeshVertexAttributeFlags) ~kUnityXRMeshVertexAttributeFlagsColors;
    9.             auto* meshDesc = s_XrMesh->MeshDataAllocator_AllocateMesh(allocator, data->numVertices, data->numIndices, kUnityXRIndexFormat16Bit, allAttributesExceptColors, kUnityXRMeshTopologyTriangles);
    10.             for (int j = 0; j < data->numVertices; ++j) {
    11.                 meshDesc->positions[j] = data->vertices[j];
    12.             }
    13.             for (int j = 0; j < data->numIndices; ++j) {
    14.                 meshDesc->indices16[j] = data->indices[j];
    15.             }
    16.             for (int j = 0; j < data->numNormals; ++j) {
    17.                 meshDesc->normals[j] = data->normals[j];
    18.             }
    19.             for (int j = 0; j < data->numTangents; ++j) {
    20.                 meshDesc->tangents[j] = data->tangents[j];
    21.             }
    22.             for (int j = 0; j < data->numUvs; ++j) {
    23.                 meshDesc->uvs[j] = data->uvs[j];
    24.             }
    25.             result = kUnitySubsystemErrorCodeSuccess;
    26.         } else {
    27.             result = kUnitySubsystemErrorCodeFailure;
    28.         }
    29.  
    30.         logMeshId("generatedMeshes.erase", *meshId);
    31.         generatedMeshes.pop();
    32.         meshFound = true;
    33.     }
    34. }
    35. generatedMeshesMutex.unlock();
    36.  

    I bet the first thing that comes to mind is a multithreading problem. It's always multithreading, right?
    And if it's not multithreading, there are a lot of places for the out-of-bounds crash to happen.
    Oh boy, I was wrong!

    Another question is why the code crashes only on Windows and works fine on macOS. The only difference was in the compiler I used to compile native libraries for different platforms. I compiled macOS libs on my mac using GCC compiler, but for Windows/Linux I used Zig cross-compiler. I tried to compile a macOS lib with Zig and reproduced the crash my clients were experiencing. At least some progress.

    The problem with native code is that you will not get a proper crash report even if the library is compiled with debug symbols. So I didn't know where the crash was coming from, I knew only the method name and have to manually test each line one by one.

    Let's see where the crash actually came from. You'll never guess it was this innocent line:
    Code (CSharp):
    1. auto allAttributesExceptColors = (UnityXRMeshVertexAttributeFlags) ~kUnityXRMeshVertexAttributeFlagsColors;
    Yes, It's a bad piece of code in the first place, because it casts a negative value to UnityXRMeshVertexAttributeFlags enum. Also, it doesn't account that UnityXRMeshVertexAttributeFlags enum may change in the future.

    But, apart from being a questionable code, why does it crash with one compiler and not the other?
    I don't have an exact answer to this question, but I found a similar issue. Apparently, different compilers may result in different runtime behavior of the program.

    In any case, casting an invalid value to enum is a bad practice and we should always be explicit about our intent. Changing the code to the following fixed the crash:
    Code (CSharp):
    1. auto allAttributesExceptColors = (UnityXRMeshVertexAttributeFlags) (kUnityXRMeshVertexAttributeFlagsNormals | kUnityXRMeshVertexAttributeFlagsTangents | kUnityXRMeshVertexAttributeFlagsUvs);
    The bug affected clients on Windows and Linux who used ARKit Meshing. The fix is available in version 1.4.23-release.1/2.0.23-release.1. Please tell me if it works.


     
    Last edited: Jul 14, 2022
  49. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    Hi
    I have a question about using Unity Remote 5 with AR Foundation Remote 2

    I've opened a new project and set it up for AR installed AR Foundation Remote 2, installed Unity Remote 5 on my iPhone, loaded the demo scenes and opened one, Unity Remote 5 shows the game scene view but is not accessing the camera, am I missing something? If I build and use AR Companion App all works fine, how do I get Unity Remote 5 to work? Thanks.
     
  50. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    Unity Remote app doesn’t support camera or AR Foundation. That’s the primary reason why the AR Foundation Remote plugin exists.
     
    Griffo likes this.