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

In the ChatRoomService example, BroadcastAllAsync (x => x.OnJoin) x always NullReferenceException #41

Closed
yoohoxiao opened this issue Sep 13, 2017 · 15 comments

Comments

@yoohoxiao
Copy link

How to solve this problem?

@neuecc
Copy link
Member

neuecc commented Sep 13, 2017

it is caused from does not call RegisterStreamingMethod before call at once.
requires OnJoin before Broadcast...
However, null is not desirable, so I'd like to fix it.
thanks.

@yoohoxiao
Copy link
Author

So how do I fix this problem now?

@neuecc
Copy link
Member

neuecc commented Sep 13, 2017

Who calls BroadcastAll?
In the chat scenario, although I think that someone will surely start after Join.

@yoohoxiao
Copy link
Author

public async Task<ServerStreamingResult<ChatRoomMember>> OnJoin()
{
  return await GetStreamingContextRepository().RegisterStreamingMethod(this, OnJoin);
}

@yoohoxiao
Copy link
Author

Now this problem can not be resolved, there are other ways, I do not know where to modify.

@neuecc
Copy link
Member

neuecc commented Sep 14, 2017

please show reproduce client code.
below code is works fine.

static async Task RunChat(ChannelContext ctx)
{
    // create room
    var client = ctx.CreateClient<IChatRoomService>();

    var room = await await client.CreateNewRoom("test", "A"); // TODO:IChatRoomCommand sample is old so require await await...

    var result = await await client.SendMessage(room.Id, "foo bar baz");
    Console.WriteLine("Send success:" + result);
}

@yoohoxiao
Copy link
Author

public IEnumerator Join(string roomId, string nickName)
{
       var r = client.Join(roomId, nickName).ResponseAsync.ToYieldInstruction();
       yield return r;
}

@yoohoxiao
Copy link
Author

Do you need to do two "ToYieldInstruction" here?

@neuecc
Copy link
Member

neuecc commented Sep 14, 2017

ah, sorry, require subscribe OnJoin before do anything.

neuecc added a commit that referenced this issue Sep 14, 2017
neuecc added a commit that referenced this issue Sep 14, 2017
@neuecc
Copy link
Member

neuecc commented Sep 14, 2017

I've fixed sample code and upload v0.5.1.1 includes this fix.
4d1c8af

main fix is add new api, when creating StreamingContextRepository

new StreamingContextRepository<IChatRoomStreaming>(connection, this);

@yoohoxiao
Copy link
Author

Sorry, did not see the version update!

@yoohoxiao
Copy link
Author

public async UnaryResult<RoomResponse> CreateNewRoom(string roomName, string nickName)
Are you sure you can write this way?
Why the editor that need to add Task , or can not use async.

@neuecc
Copy link
Member

neuecc commented Sep 14, 2017

this is for C# 7.0 only, if you have to use old c#, change signature to Task<UnaryResult<T>>.
(but for Unity, generates IObservable<T> code).

@yoohoxiao
Copy link
Author

public interface IChatRoomCommand
{
           IObservable<UnaryResult<global::ShareType.RoomResponse>> CreateNewRoom(string roomName, string nickName);
}

Does Unity3d need this?

@neuecc
Copy link
Member

neuecc commented Sep 14, 2017

@neuecc neuecc closed this as completed Jan 7, 2019
AntonC9018 pushed a commit to AntonC9018/MagicOnion that referenced this issue Sep 13, 2022
AntonC9018 pushed a commit to AntonC9018/MagicOnion that referenced this issue Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants