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
Sharing fixes #306
Sharing fixes #306
Conversation
of a race condition that led to the user never getting into a room.
…t an event from NetworkConnection instead of calling Invoke with a timer.
Hi @Holo-Krzysztof, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! TTYL, MSBOT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please sign the CLA :)
|
||
// We will register for session joined to indicate when the sharing service | ||
// is ready for us to make room related requests. | ||
SharingSessionTracker.Instance.SessionJoined += Instance_SessionJoined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be removing the event handler in OnDestroy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GitHub view is misleading. This removed line was in the SharingManagerConnected method and moved to Awake in this pull request.
Edit: Unless you're asking if this event handler should be -= in OnDestroy, then I agree haha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol, yeah this actually is in the SharingManagerConneced method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am asking for it to be -= in the OnDestroy :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that it gets removed after we raise the Instance_SessionJoined
event.
We also never unsubscribe to SharingManagerConnected
on line 128 either.
We should probably be unsubscribing to any/all of these events whenever we call OnDestroy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a statement to unregister that handler in OnDestroy.
using UnityEngine; | ||
|
||
namespace HoloToolkit.Sharing | ||
{ | ||
public class SharingStage : MonoBehaviour | ||
public class SharingStage : Singleton<SharingStage> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice :)
//delay sending notification so everything is initialized properly | ||
Invoke("SendConnectedNotification", 1); | ||
//Invoke("SendConnectedNotification", 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these lines then?
@@ -116,18 +116,19 @@ public bool AnchorEstablished | |||
/// </summary> | |||
RoomManagerAdapter roomManagerCallbacks; | |||
|
|||
void Start() | |||
void Awake() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing this to Awake can cause issues accessing a Singleton Instance. There's no guarantee that the Singleton object will be initialized until every object's Awake is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't scene objects loaded before the first Awake call is made?
If yes, Singleton already accounts for that by calling FindObjectOfType if the instance doesn't exist.
Otherwise I could change it to Start, but I'd need to verify that everything still works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep in mind that the Singleton pattern is being updated due to the new input module #277
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, we found that FindObjectOfType will fail if Awake() hasn't been called yet. Since the execution order can vary, this was occasionally seen in BasicCursor.cs and raised in #246.
In addition, @HodgsonSDAS brings up a good point. The new pattern has Instance set in Awake(), so there's no guarantee it will be set in any other Awake().
@Holo-Krzysztof, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one little nit. But while we're editing the ImportExportAnchorManager class anyway, could we make all the methods properties and fields explicitly private?
{ | ||
Connect(); | ||
} | ||
} | ||
|
||
protected void OnDestroy() | ||
{ | ||
Instance = null; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Extra line
@@ -116,18 +116,19 @@ public bool AnchorEstablished | |||
/// </summary> | |||
RoomManagerAdapter roomManagerCallbacks; | |||
|
|||
void Start() | |||
void Awake() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep in mind that the Singleton pattern is being updated due to the new input module #277
I've moved the singleton access calls into start, WorldAnchorStore is fine in Awake, I guess. |
@@ -500,7 +505,7 @@ void Export() | |||
/// Called by the WorldAnchorTransferBatch as anchor data is available. | |||
/// </summary> | |||
/// <param name="data"></param> | |||
public void WriteBuffer(byte[] data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should probably stay public, if they were already public.
Sorry, I just meant the things that weren't explicit.
@@ -509,7 +514,7 @@ public void WriteBuffer(byte[] data) | |||
/// Called by the WorldAnchorTransferBatch when anchor exporting is complete. | |||
/// </summary> | |||
/// <param name="status"></param> | |||
public void ExportComplete(SerializationCompletionReason status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should stay public
{ | ||
get | ||
{ | ||
return currentState.ToString(); | ||
} | ||
} | ||
|
||
public bool AnchorEstablished | ||
private bool AnchorEstablished |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should stay public
@@ -41,15 +41,15 @@ enum ImportExportState | |||
|
|||
ImportExportState currentState = ImportExportState.Start; | |||
|
|||
public string StateName | |||
private string StateName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should stay public
Also, Unless someone whats to know the |
This references issue #292
The major fixes here are subscribing to
NetworkConnection
events so that we know when we're connected to the server instead of usingInvoke
with a certain time (which failed when init took more than one second) and usingSingleton<T>
forSharingStage
, as the previous implementation was broken and an unnecessary duplication of efforts.My previous testing showed the Sharing sample scene to work now, which wasn't the case before; I would appreciate if some other people tested and verified this to be true.