Closed Holo-Krzysztof closed 7 years ago
I can believe this. Were you in Debug mode? This was a relatively recent change by @alexdrenea inside SharingStage. Seems reasonable to move SharingSessionTracker.Instance.SessionJoined += Instance_SessionJoined; to Start().
@alexdrenea any thoughts on this?
I checked the code as well and I agree that the event should be hooked up in Start
, there's no good reason for it to be in the SharingManagerConnected()
method.
I can't validate it on a real device at the moment though (due to lack of availability 😞).
@Holo-Krzysztof would you like to make the change?
I'm not entirely sure yet, because after that change I've got a NullReferenceException in InitRoomApi() once, but that could be due to other changes in the project. I'll investigate that and if there are no issues, I'll make a pull request.
On Di. Okt. 18 19:54:43 2016 GMT+0200, Neeraj Wadhwa wrote:
@Holo-Krzysztof would you like to make the change?
You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/Microsoft/HoloToolkit-Unity/issues/292#issuecomment-25458708
Btw, it was in release mode, @NeerajW.
Alright, I discovered another bug related to my change: Sometimes SharingManagerConnected
never gets called and thus roomManager
is null, leading to exceptions in InitRoomApi()
.
Let's look at a sample execution:
SharingStage
calls Awake()
, which in turn calls Connect()
(in my case, because auto discovery is off)Connect()
does some config steps and creates a SharingManager
from native and then says "Wait a second and check if we're connected" with the Invoke()
call below (which seems like asking for trouble, not to mention that it's hard to find in the editor -> no references in Shift+F12 because it's not a direct call, but uses reflection)Awake()
methods of other scripts are running too, and after that each script's Start()
method is called, such as that of ImportExportAnchorManager
, which sets up the event handler SharingManagerConnected
.SendConnectedNotification()
), the event handler in ImportExportAnchorManager
is never called, which leaves us with NullReferenceExceptions
all over the place instead of a valid RoomManager
.I'm currently thinking of a good way to solve this and will edit this comment accordingly. Any thoughts on this, @NeerajW @alexdrenea?
EDIT: I think I've solved it, but don't have time right now to submit my changes. You'll get a pull request next week.
Yeah I'm no fan of Invoke()
.
private void Instance_SessionJoined(object sender, SharingSessionTracker.SessionJoinedEventArgs e)
{
// We don't need to get this event anymore.
SharingSessionTracker.Instance.SessionJoined -= Instance_SessionJoined;
// We still wait to wait a few seconds for everything to settle.
Invoke("MarkSharingServiceReady", 5);
}
Another issue is that testing in the Editor is difficult because ImportExportAnchorManager
only puts you in a room if WorldAnchorStore.GetAsync(AnchorStoreReady);
completes successfully (Which it never does because we're not actually on device).
I've noticed a strange bug which seems like a race condition: sometimes, when looking at the debug output of the Sharing sample you get a "User joining session" debug print but after that it seems to be stuck forever in the AnchorStore_Initialized state because the sharing service never gets marked as ready. This happens because
SharingSessionTracker.SendJoinEvent()
is called beforeImportExportAnchorManager
gets to subscribe to this event.The problem went away after moving
SharingSessionTracker.Instance.SessionJoined += Instance_SessionJoined;
fromSharingManagerConnected()
toStart()
, so I'd propose that as a solution. Can anyone else reproduce this issue and give me some more insight?