Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HoloLens and MapBox issue #734

Closed
nosmirck opened this issue May 4, 2018 · 40 comments
Closed

HoloLens and MapBox issue #734

nosmirck opened this issue May 4, 2018 · 40 comments
Assignees
Labels

Comments

@nosmirck
Copy link

nosmirck commented May 4, 2018

  • Unity version: 2018.1.0.f2
    • Scripting Runtime Version: .Net 4.x Equivalent.
    • Scripting Backend: IL2CPP.
    • Api Compatibility Level: .NET 4.x
  • Mapbox SDK version: 1.4.1
  • The platform you're building to: UWP.
    • Target Device: HoloLens.
    • Build Type: D3D.
  • A description of what you're trying to do:
    Render the prefab "CitySimulatorMap" inside the Mixed Reality experience with HoloLens Device/Simulator.
  • Steps to recreate the bug if appropriate:
    • Create a new project and include HoloToolkit and Examples from here.
    • Follow steps here to configure the app for HoloLens.
    • Import Mapbox 1.4.1. Exclude GoogleARCore, MapboxAR, UnityARInterface and UnityARKitPlugin.
    • Setup Mapbox.
    • Add a new scene.
    • Apply all 3 options in Mixed Reality Toolkit > Configure.
    • Drag the prefab CitySimulatorMap.prefab from Assets/Mapbox/Prefabs to the scene

At this point, everything will work in the Editor.

Trying to compile with above settings will give errors of duplicated/ambiguous use of Description Attribute.

Here is the Console Output from Compilation to Deploy and Debug the App.

@wilhelmberg
Copy link
Contributor

@nosmirck have you set your Mapbox access token?
Your log file contains:

Error setting value to 'AccessToken' on 'Mapbox.Unity.MapboxConfiguration'.

Also, have you set the Internet Capabilities`?
Either in Unity or in the exported VS solution.

@nosmirck
Copy link
Author

nosmirck commented May 8, 2018

have you set your Mapbox access token?

Yes, it works fine on the Unity Editor. I did it during the step Setup Mapbox. from above

Here's a screenshot:
image

Also, have you set the Internet Capabilities`?
Either in Unity or in the exported VS solution.

Yes, during the step Apply all 3 options in Mixed Reality Toolkit > Configure. from above.

I re-checked the permissions on the VS project, this is what I see:

image

@wilhelmberg
Copy link
Contributor

@nosmirck thanks for you detailed feedback.
I'm able to reproduce your problem, tried with Unity@2017.4.2f this time.

I'm getting a System.Reflection.Emit is not supported error in conjunction with Mapbox.Json.Serialization.
My current hunch is still the same as before: some logic is tripped by the change of how Unity now sets defines.

Mapbox.Json is branched off Newtonsoft.Json which is quite a complex piece of software so it probably will take some time to hunt down the exact location where the problem occurs - and I will get to that earliest next week as I'm busy with other stuff (new SDK release coming up 🎉).

@nosmirck
Copy link
Author

@BergWerkGIS great! no problem!

For now, I've been working on the rest of the simulation using a map I saved in runtime with the editor (made the map object once loaded a fbx) and I'm cool with that for now.

Just to share a bit what I'm doing:

I'm rendering a real time map on top of a table using HoloLens. On top of the map some data will be visualized by converting the data into a heat map texture and projected on top of the MapBox based on the location.

So, in the next few weeks I'll be working with all the rest of the project with a mocked map. There's no hurry, I have exactly 4 weeks from tomorrow to finish this project (it's actually a PoC) and I'd love to include the ability to zoom the map and change location.

Thanks for the support!

@Storm-Develop
Copy link

Storm-Develop commented Jun 5, 2018

Hey @nosmirck , were you able to setup project with Hololens and MapBox?

@nosmirck
Copy link
Author

nosmirck commented Jun 6, 2018

@YouAlwaysLoose no, I finished the rest of my PoC using a mocked map that I saved in editor runtime using this handy tool https://github.com/pharan/Unity-MeshSaver/blob/master/MeshSaver/Editor/MeshSaverEditor.cs

For the purpose of my PoC I believe I have enough, I'd like to have MapBox really load the current location and render the map properly so I can zoom in/out, change locations, etc. I'm still waiting for this bug to be fixed though.

@BergWerkGIS is there any ETA for this?

@wilhelmberg
Copy link
Contributor

@BergWerkGIS is there any ETA for this?

Working on it, but no ETA yet.
The change in Unity's behavior touches a lot more places than I had anticipated.
Especially Mapbox.Json (forked from Newtonsoft.Json) is a beast to tackle.

@Storm-Develop
Copy link

Storm-Develop commented Jun 6, 2018

@nosmirck Thank you for the quick reply.
@BergWerkGIS Awesome I am going to wait for it too. Meanwhile, I will try to build & run the simple project involving Mapbox and Hololens.
If need something to test on Hololens please let me know.

@wilhelmberg
Copy link
Contributor

If need something to test on Hololens please let me know.

@Storm-Develop thanks, your help is very much appreciated 😄

@Storm-Develop
Copy link

@BergWerkGIS =) Sorry I am not that familiar with MapBox structure yet to help more. I am just trying first to make it work with the simplest solution possible.
I was able to Build the project by following your #485 steps. And it works great in the Unity.
However, in Hololens, I see nothing=( Seems like the map wasn't generated.

If I downgrade Unity to version 2017.1 is that going to help?

@nosmirck when you referred that map didn't render what exactly you meant? Did you see a map in HoloLens? I can't see anything except skybox.
screen1

@nosmirck
Copy link
Author

nosmirck commented Jun 6, 2018

Exactly, the map doesn't render in the HoloLens (simulator and device) and I get the error I reported above (This is the console output) which seems to be related to the JsonSerializer @BergWerkGIS is talking about

@wilhelmberg
Copy link
Contributor

@Storm-Develop

I was able to Build the project by following your #485 steps. And it works great in the Unity.
However, in Hololens, I see nothing=( Seems like the map wasn't generated.

The problem is that Unity and HoloLens (UWP - Universal Windows Platform) are running on different .Net framework versions which offer a different set of APIs.
Thus if something runs in Unity it is not for granted that the same thing will run on another platform, HoloLens in this case.

Because of the different APIs execution flow through code may follow different paths depending on the framework that's being used.

Take this simple example of string comparison:

#if NETFX_CORE
StringComparison stringComp = StringComparison.OrdinalIgnoreCase;
#elif WINDOWS_UWP
StringComparison stringComp = StringComparison.OrdinalIgnoreCase;
#else
StringComparison stringComp = StringComparison.InvariantCultureIgnoreCase;
#endif

And we have a lot of those #if/#endifs through our code.

Previously WINDOWS_UWP was defined by Unity when exporting to UWP.
That seems to have changed and our code as well as 3rd party libraries (eg Newtonsoft Json) need to be changed to account for that.

If I downgrade Unity to version 2017.1 is that going to help?

Unfortunately I cannot tell: Unity's behavior has changed in one of the 2017.x releases but I don't know which as I haven't tried each and everyone.

@Storm-Develop
Copy link

Storm-Develop commented Jun 7, 2018

@BergWerkGIS I see now, thank you for the detailed answer.
Maybe these can be useful.
https://forum.unity.com/threads/net-scripting-backend-and-visual-studio-2017-3-incompatibility.487833/#post-3191224
https://docs.microsoft.com/en-us/windows/uwp/gaming/missing-dot-net-apis-in-unity-and-uwp
https://docs.unity3d.com/Manual/windowsstore-missingtypes.html
So I guess the real question would be how much time it would take to fix the dependencies? I am guessing the solution could be simpler since the Unity provides the Missing .NET Types.
Is it possible that it can be done sometime next week?

@wilhelmberg
Copy link
Contributor

wilhelmberg commented Jun 8, 2018

So I guess the real question would be how much time it would take to fix the dependencies?
Is it possible that it can be done sometime next week?

@Storm-Develop I really can't tell as I'm hitting a Catch 22-like situation with a very simple problem already.

Open to suggestions how to get past that!


.NET framework version used by UWP doesn't have DescriptionAttribute so we define it ourselves and wrap it within #if UNITY_WSA:

#if UNITY_WSA
	[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
	public class DescriptionAttribute : Attribute {
		private readonly string description;
		public string Description { get { return description; } }
		public DescriptionAttribute(string description) {
			this.description = description;
		}
	}
#endif

That produces the following ambiguous reference error in Editor

 error CS0104: `DescriptionAttribute' is an ambiguous reference between
`System.ComponentModel.DescriptionAttribute' and 
`Mapbox.VectorTile.Geometry.DescriptionAttribute'

as the API of the .NET framework version used by Editor does have the DescriptionAttribute.

So we wrap our definition into #if !UNITY_EDITOR && UNITY_WSA which makes the errors in Editor disappear.

However when I try to build to Universal Windows Platform with these settings
image

I get could not be found error

error CS0246: 
The type or namespace name 'DescriptionAttribute' could not be found 
(are you missing a using directive or an assembly reference?)

as we are still in Editor and #if !UNITY_EDITOR blocks our implementation but export is done using the UWP version of .NET framework which doesn't have DescriptionAttribute.

❓ ❓ ❓


My setup:

  • Deleted all folders related to other AR implementations:
    image
  • Unity@2018.1.3.f1
  • Platform: Universal Windows Platform
  • Other Settings
    • Configuration
  • Publish Settings
    • Capabilites
      • ☑️ InternetClient
      • ☑️ SpatialPerception
  • XR Settings:
    • Virtual Reality Supported:
      • Virtual Reality SDKs: Windows Mixed Reality

@Storm-Develop
Copy link

@BergWerkGIS I see what if we just comment the description text for now?
Also maybe with #UNITY_WSA_10_0 it will work.
OR WITH #if UNITY_WSA && ENABLE_DOTNET && !UNITY_EDITOR
screenshot_19
screenshot_20

@wilhelmberg
Copy link
Contributor

wilhelmberg commented Jun 8, 2018

@Storm-Develop

Also maybe with #UNITY_WSA_10_0 it will work.
OR WITH #if UNITY_WSA && ENABLE_DOTNET && !UNITY_EDITOR

Thanks for the ideas but I've already tried those and others (UNITY_WINRT, NETFX_CORE, ENABLE_WINMD_SUPPORT, !UNITY_EDITOR) and all possible permutations thereof.

Always the same problem: during different stages of the export Unity seems seems to use the Mono compiler and then for some other C# files the Microsoft compiler.

Also tried different runtimes and settings for the .NET Core override:

  • None: C# files are compiled using Mono compiler.
  • Use .Net Core: C# files are compiled using Microsoft compiler and .NET Core, you can use Windows Runtime API, but classes implemented in C# files aren’t accessible from the JS language. Note: when using API from Windows Runtime, it’s advisable to wrap the code with ENABLE_WINMD_SUPPORT define, because the API is only avaible when building to Universal Windows Platform, and it’s not available in Unity Editor.
  • Use .Net Core Partially: C# files not located in Plugins, Standard Assets, Pro Standard Assets folders are compiled using Microsoft compiler and .NET Core, all other C# files are compiled using Mono compiler. The advantage is that classes implemented in C# are accessible from the JS language. Note: You won’t be able to test .NET Core API in Unity Editor, because it doesn’t have access to .NET Core, so you’ll be able to test the API only when running Universal Windows App.

what if we just comment the description text for now?

Yes, I had the same idea 😄 and that got me past the first hurdle.
We are heavy users of [Description()]: https://github.com/mapbox/mapbox-unity-sdk/search?q=%5BDescription%28&type=Code

Now working on module vector-tile-cs.


I'll keep this ticket updated.

@wilhelmberg
Copy link
Contributor

wilhelmberg commented Jun 11, 2018

@Storm-Develop @nosmirck

I think I got an initial version working and it would be great if you could give it a spin and let me know if it works for you too.
Please see below for the settings I used and how to get that branch.

hololens-quest-01


My Settings

  • Unity@2018.1.3.f1
  • Deleted all folders related to other AR implementations:
    image
  • Platform: Universal Windows Platform
  • Other Settings
    • Configuration: scripting backend .NET, IL2CPP does not work!
  • Publish Settings
    • Capabilites
      • ☑️ InternetClient
      • ☑️ SpatialPerception
  • XR Settings:
    • Virtual Reality Supported:
      • Virtual Reality SDKs: Windows Mixed Reality

image


Branch hololens-fixes

As I've changed quite a few things (removed submodules, moved files around, ...) I suggest you clone to a dedicated local repo to avoid any conflicts:

Below command will clone just the hololens-fixes branch into a directory also called hololens-fixes:

git clone --branch hololens-fixes --single-branch --depth 1 git@github.com:mapbox/mapbox-unity-sdk.git hololens-fixes

Simple test

Open the sdkproject folder from the newly cloned repo in Unity and try to build (export) one of the examples (I went with Globe).

Don't forget to add SQLite to the main project when you build the exported project in Visual Studio:

Add Reference -> Universal Windows -> Extensions -> SQLite for Windows Universal Platform

image

@Storm-Develop
Copy link

Storm-Develop commented Jun 11, 2018

@BergWerkGIS Millions of Thanks! It does work!
I tried the Replace Features Example

replacefeautures

Just a small comment I didn't have SQLite for UWP so downloaded from the market place https://marketplace.visualstudio.com/items?itemName=SQLiteDevelopmentTeam.SQLiteforUniversalWindowsPlatform

@wilhelmberg
Copy link
Contributor

wilhelmberg commented Jun 11, 2018

@Storm-Develop Great! 🎉 🎆
Now you got something to work with.

Thanks for testing 🙏

Be aware though that this is still work in progress and might need a few more weeks till it gets into develop branch and hopefully into the next release (still a lot of cleanup necessary).

Just a small comment I didn't have SQLite for UWP so downloaded from the market place

Oh yeah, thanks for the reminder. I forgot to mention that.

@timgoeij
Copy link

@BergWerkGIS

I have tried the same settings as you mentioned above in my own project and in an empty project and got the same atttribute errors in Unity 2018.1.6. Is there a possibillity for my to clone the Hololens-fixes? Last time I tried to clone the branch with above command, but that it wasn't working before I wrote issue #875

@Storm-Develop
Copy link

Storm-Develop commented Jun 25, 2018

@timgoeij Based on your error image you didn't get the hololens-fixes branch. Just download the branch hololens-fixes manually as zip file.

@wilhelmberg
Copy link
Contributor

@timgoeij I agree with @Storm-Develop: looks like you didn't get the hololens-fixes branch.

Either use this git command

git clone --branch hololens-fixes --single-branch --depth 1 git@github.com:mapbox/mapbox-unity-sdk.git hololens-fixes

or download https://github.com/mapbox/mapbox-unity-sdk/archive/hololens-fixes.zip

For both options make sure you are using a new target directory and not save/clone into an existing (SDK) one, which might also lead to those errors.

@mayank-technical
Copy link

@BergWerkGIS You are amazing. Thanks for great help . I am able to run all the samples of mapbox. Thanks a ton.! Just need to know how you people record hololens screen?

@wilhelmberg
Copy link
Contributor

Thanks @mayank-technical 🙏

Just need to know how you people record hololens screen?

By hitting Record in the Device Portal 😄:
https://docs.microsoft.com/en-us/windows/mixed-reality/using-the-windows-device-portal#mixed-reality-capture

@mayank-technical
Copy link

mayank-technical commented Jul 10, 2018 via email

@emartinDesignInteractive

Is there any update on when this will be rolled up? Creating a cross platform app for mobile and hololens using World Scale AR. Thanks!

@wilhelmberg wilhelmberg mentioned this issue Aug 8, 2018
6 tasks
@wilhelmberg
Copy link
Contributor

@emartinDesignInteractive PR is up #945 but not yet merged.

@BrentKingma
Copy link

@BergWerkGIS hey, thanks for the work that you have been doing but do you know how long it will be for the mapbox to work with unity's il2cpp compiler?

@wilhelmberg
Copy link
Contributor

Closing - PR #945 UWP fixes (and more) was merged.

NOTE:
UWP (Desktop, HoloLens, Windows Phone, ...) builds with Scripting Backend: IL2CPP still don't work - only .NET backend does.
Blocker here is https://github.com/mapbox/Mapbox.Json-unity (a fork of Newtonsoft.Json) which emits dynamic compiler code which does not work with IL2CPP.

@LukeHackett12
Copy link

LukeHackett12 commented Mar 3, 2019

Hi, I was wondering if this is still an ongoing issue. I am attempting to use mapbox on hololens and have tried everything in this thread and I still get this error:

Exception thrown: 'SQLite4Unity3d.SQLiteException' in Assembly-CSharp.dll
error:14090086:lib(20):func(144):reason(134)
Setting up 1 worker threads for Enlighten.

  Thread -> id: 634 -> priority: 1 

Mapbox.Unity.MapboxAccess+InvalidTokenException: StatusNotYetSet

Any help would be appreciated!

@Toducs
Copy link

Toducs commented Apr 11, 2019

Hi, I was trying the same and after digging for a few hours... i found that the problem is that the PRAGMA command send to the sqlite was actually returning a row, and because it get executed with ExecuteNonQuery command it was not expecting a row results, what cause raise the error. I was able to pass that by chaging the line 2152 of the \Assets\Mapbox\Core\mapbox-sdk-cs\Platform\SQLite\SQLite.cs file as if (r == SQLite3.Result.Done || r == SQLite3.Result.Row).
However now I have other problem and is that for some reason the webrequest to get the token is not working. It seem to be related to the UnityWebRequest getting Unknow error... I am trying to figure it out.

@LukeHackett12
Copy link

You have to substitute unityWebRequests with normal c# HttpRequests, at least that's what I've done elsewhere and it's worked to get Web information.

@Toducs
Copy link

Toducs commented Apr 12, 2019

Hooo that make sense. Thank you very much.

@lukemadera
Copy link

@BergWerkGIS Thanks for your work on this; any update on IL2CPP, or is Mapbox still not usable for UWP?

@NHarishGit
Copy link

NHarishGit commented Oct 23, 2021

UNITY 2019.4.31f with MAPBOX v2.1.1 SDK, still the same errors, cannot build for UWP with I2LCPP (mandated by UNITY):

"Assets\Mapbox\Core\mapbox-sdk-cs\MapMatching\MapMatchingParameters.cs(15,4): error CS0104: 'Description' is an ambiguous reference between 'Mapbox.VectorTile.Geometry.DescriptionAttribute' and 'System.ComponentModel.DescriptionAttribute'"

Any one has taken an effort to fix it or a WorkAround for now ?

@emartinDesignInteractive

UNITY 2019.4.31f with MAPBOX v2.1.1 SDK, still the same errors, cannot build for UWP with I2LCPP (mandated by UNITY):

"Assets\Mapbox\Core\mapbox-sdk-cs\MapMatching\MapMatchingParameters.cs(15,4): error CS0104: 'Description' is an ambiguous reference between 'Mapbox.VectorTile.Geometry.DescriptionAttribute' and 'System.ComponentModel.DescriptionAttribute'"

Any one has taken an effort to fix it or a WorkAround for now ?

Would recommend looking into Microsoft's Maps for Unity plugin, depending on your use case.

https://github.com/microsoft/MapsSDK-Unity

@tvasilopoulou
Copy link

Hello everyone,
I have been trying to load a simple map prefab using Mapbox with:

  • Unity Version: 2019.3.5f1
  • Mapbox version: 2.1.1
  • AR Foundation package 2.1.8

I have also deleted all AR related directories from the mapbox package and set all "Description" occurrences to refer to System.ComponentModel. In MapboxAccountsUnity.dll, I have checked the WSAPlayer checkbox in the inspector panel. Finally, after building for UWP as shown in the picture below, I have added the SQLite reference.
Screenshot_30

I have the same problem as @nosmirck described in #734 (comment), meaning I can successfully deploy to Hololens but on Debug mode I get similar logs as shown here:
20211117_122503_HoloLens

Most important error in the logs is: Rethrow as JsonSerializationException: Error setting value to 'AccessToken' on 'Mapbox.Unity.MapboxConfiguration'.
at Mapbox.Json.Serialization.ExpressionValueProvider.SetValue

but the token I provide in the editor is valid. In the Project settings my Scripting backend in IL2CPP which I cannot change but the API compatibility level is .NET 4.x.

Does anyone know how I can manage rendering the map on Hololens and resolving the NullReferenceException? Thank you!

@mertusta1996
Copy link

mertusta1996 commented Jul 13, 2022

For Hololens-2 and Mapbox in Unity UWP, try this repo ;
https://github.com/mertusta1996/Mapbox-Hololens-2-Unity-UWP-

@NHarishGit
Copy link

For Hololens-2 and Mapbox in Unity UWP, try this repo ; https://github.com/mertusta1996/Mapbox-Hololens-2-Unity-UWP-

The link is NOT working for me

@mertusta1996
Copy link

For Hololens-2 and Mapbox in Unity UWP, try this repo ; https://github.com/mertusta1996/Mapbox-Hololens-2-Unity-UWP-

The link is NOT working for me

I fixed the link sorry 👍
https://github.com/mertusta1996/Mapbox-Hololens-2-Unity-UWP-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests