microsoft / MapsSDK-Unity

This repository contains samples, documentation, and supporting scripts for Maps SDK, a Microsoft Garage project.
MIT License
649 stars 127 forks source link

Unity Exception" Destroy? #27

Closed TerraSame closed 4 years ago

TerraSame commented 4 years ago

"Hello" First off, Microsoft Maps is nothing less than spectacular! Thanks for your efforts. In working with "Maps" for the HoloLens I have run into a very persistent Exception. The project I am creating has numerous Scenes using Maps where The first Scene has an interactive button that launches a second Scene. Upon launching the second Maps Scene from the First Maps Scene, or for that matter, switching from any Maps Scene to another Scene, I get a nasty Development Console message saying:

Unity Exception" Destroy can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers instead move initialization code to the Awake or Start function. So that's it ! Is it me? Maybe Unity? Or could it be your system?

To Reproduce Steps to reproduce the behavior:

  1. I don't believe I have any answer to why I get this exception warning. I believe it pertains to something in the Maps code but I don't have a clue. I am using Unity Version 2019.1.14f1 so I imagine to recreate all that would need to be done is
    link two scenes together with a button and in HoloLens launch and see what happens...

Environment (please complete the following information):

Any advice as to a way to terminate this bug will be greatly appreciated... I look forward to being enlightened and if anything else is requested of me I will be most eager to respond. Thanks paul@terrasame.com 906-235-2187 www.terrasame.com

kircher1 commented 4 years ago

Hi @TerraSame!

Would it be possible to share the callstack that Unity displays with the log message related to main thread?

Also, can you double check which version of the Maps SDK NuGet package you are using? The latest available is 0.4.0.

Last of all, to better understand the repo, as you are loading new scenes, it sounds like it is possible for multiple MapRenderer GameObjects to be active in the scene. Is that accurate?

TerraSame commented 4 years ago

kircher1 notifications@github.com 5:13 PM (1 hour ago) " Hello" !

I love this stuff... My HoloLens is so damn cool... Thank you very much for responding!

Hi... Sorry for the late reply as I have been pounding the keys on this project... Lots of good news coming... I plan to update you very soon but I just noticed that I have racked up quite a bit of billable "Units" from developing... So, I am curious what is the cost for each "Unit" because I am at 1930 "Units" ? I sure hope that each unit isn't a dollar... :) Seems to me for developing and assisting you and your team with suggestions, ideas etc should be no cost if any... Anyways... I have found ways to accomplish resolving the issues I had which I will share soon but you will also need to know that I have had a devil of a time trying lower and high versions of Unity. So, I will go into detail about all this sometime this week... Thanks

Okay... So... Here are comments to your questions, best as I can do...

   Would it be possible to share the callstack that Unity displays

with the log message related to main thread?

Not sure as to finding a "Call Stack" in the HoloLens as the Exception I run into happens each time I switch to a different Scene while in the HoloLens and there are ne errors or warnings in Unity.

   Also, can you double check which version of the Maps SDK NuGet

package you are using? The latest available is 0.4.0.

I just obtained your version, "Microsoft.Maps.Unity.0.4.0" about a week ago... So I have the latest... My "NuGet for Unity" is 1.2.4

   Last of all, to better understand the repo, as you are loading new

scenes, it sounds like it is possible for multiple MapRenderer GameObjects to be active in the scene. Is that accurate?

You got me on this one but I would agree and I suppose so.... All I know is that if my first Scene is a "Maps" Scene and I do a switch, I then get the exception warning while in HoloLens... I would think that to test this situation on your side, either you connect two scenes and test or if needed I can create a simple two scene layout, compile, test and zip up the package for you to test... You guys are sharp so I would think the former idea would be easier than the latter idea... But if needed I will do the tough work...

On another note once this bug is stomped I hope to continue with ideas & suggestions... I really love your work... Thanks as this is going to be a major change for humanity... Thanks Paul More on all this soon :)

kircher1 commented 4 years ago

If the exception is only present on the HoloLens, you may be able to get the callstack from the Player.log. This is the app-specific log file that all log messages (info, warning, and error) are written to. On the HoloLens, you can use the file explorer from the Windows Device Portal to get the log file.

For the Bing Maps key, you can find more info about the different types and number of free transactions allowed here. How transactions are accounted for different Bing Maps APIs is explained here.

For the Maps SDK a "Unity-Control" transaction is currently counted any time a MapRenderer is created. If you find that you're destroying and initializing MapRenderers while transitioning through scenes, you could reduce transactions by having only one "global" MapRenderer that is maintained throughout the scenes and re-positioned as needed. This approach would also be helpful for performance as the MapRenderer would only have to request initial data once rather than having to do so for each creation.

Last thing to mention here is that you can disable transactions in the MapRenderer while in the Editor by deselecting "Show Map Data in Editor" as described here. Once you hit Play (or when running the built application) this setting is ignored. It only applies in the editor while not playing.

TerraSame commented 4 years ago

Brian, Thanks so much for replying towards my issues... I have my template and two projects looking and running very well... It is quite the system you and your team have devised... I personally have been working in the same realm with terrains since about 2000.... Primarily, my main thrust has been my Whistler project that can be seen on my web site...

On another note, this morning I had troubles with the projects not being responded through your system. So, I assume it is either your server or my account... I have made changes to my account so I hope that when I get home and test, the issue is resolved... Thanks Paul www.terrasame.com

On Mon, Nov 11, 2019, 9:45 AM kircher1 notifications@github.com wrote:

If the exception is only present on the HoloLens, you may be able to get the callstack from the Player.log https://docs.unity3d.com/Manual/LogFiles.html. This is the app-specific log file that all log messages (info, warning, and error) are written to. On the HoloLens, you can use the file explorer from the Windows Device Portal https://docs.microsoft.com/en-us/windows/mixed-reality/using-the-windows-device-portal to get the log file.

For the Bing Maps key, you can find more info about the different types and number of free transactions allowed here https://www.microsoft.com/en-us/maps/create-a-bing-maps-key. How transactions are accounted for different Bing Maps APIs is explained here https://docs.microsoft.com/en-us/bingmaps/getting-started/bing-maps-dev-center-help/understanding-bing-maps-transactions .

For the Maps SDK a "Unity-Control" transaction is currently counted any time a MapRenderer is created. If you find that you're destroying and initializing MapRenderers while transitioning through scenes, you could reduce transactions by having only one "global" MapRenderer that is maintained throughout the scenes and re-positioned as needed. This approach would also be helpful for performance as the MapRenderer would only have to request initial data once rather than having to do so for each creation.

Last thing to mention here is that you can disable transactions in the MapRenderer while in the Editor by deselecting "Show Map Data in Editor" as described here https://github.com/microsoft/MapsSDK-Unity/wiki/Configuring-the-MapRenderer#credentials. Once you hit Play (or when running the built application) this setting is ignored. It only applies in the editor while not playing.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/microsoft/MapsSDK-Unity/issues/27?email_source=notifications&email_token=AFMY7RBBZICWT5EIHUGRZL3QTGD2VA5CNFSM4JJOWBYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDXM3MQ#issuecomment-552521138, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFMY7RAJHTJ76A3D4TIGFMLQTGD2VANCNFSM4JJOWBYA .

TerraSame commented 4 years ago

Hello Mr. Kircher1 :) I have been conducting de-bugging because I still am experiencing crashes... I am still experiencing the "Exception Destroy" Issue.

Upon being in the first scene I switched scenes by clicking a button then I shut down the project from another button in the second scene and then looked at the Player Log. (I managed to find the Player Log file at: %USERPROFILE%AppData\Local\Packages) Please see attached. Where all looks good until at the bottom of the note pad file/player log, you will see the: UnityException: Destroy can only be called from the main thread.

I have also researched on the www and found others who have wrestled with this exception. For example: https://forum.unity.com/threads/load-can-only-be-called-from-the-main-thread-error-on-changing-scenes.382574/

I will continue my diagnostics but.... Any advice on this mater will be greatly appreciated. Thanks Paul

UnityPlayer.log

TerraSame commented 4 years ago

Further... This time I ran the project and switched scenes. On the forth scene switch the project crashed. Attached you find another Player Log file showing the 4 scene switches and the crash. Please advise... :) Thanks Paul

UnityPlayer.log

kircher1 commented 4 years ago

Glad you found a solution!

RenSiyao commented 3 years ago

I also encountered this problem when jumping the scene of Hololens. How did you solve it at last?

TerraSame commented 3 years ago

Hi... Sorry you have run into the same situation... It took me a lot of work fix that... What I did was start from scratch using one of the examples and simply switch out the old scenes with the new ones... The trick is to use the Scene Managment System that is on the experimental folder... It has been quite a while since I was in there so that is the best I can do from memory... If you still have problems with this, let me know and I will reply with better info...

On Thu, Nov 26, 2020, 10:38 PM RenSiyao notifications@github.com wrote:

I also encountered this problem when jumping the scene of Hololens. How did you solve it at last?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/microsoft/MapsSDK-Unity/issues/27#issuecomment-734628915, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFMY7RD2AMALWPK6BJS2B3TSR4NLRANCNFSM4JJOWBYA .

TerraSame commented 3 years ago

Hey... i replied but it went into the thread... Find that and read it... otherwise the trick is in using the Scene Managment System. You can find a great example in the Experimental folder...

On Thu, Nov 26, 2020, 10:38 PM RenSiyao notifications@github.com wrote:

I also encountered this problem when jumping the scene of Hololens. How did you solve it at last?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/microsoft/MapsSDK-Unity/issues/27#issuecomment-734628915, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFMY7RD2AMALWPK6BJS2B3TSR4NLRANCNFSM4JJOWBYA .