UnityRenderStreaming icon indicating copy to clipboard operation
UnityRenderStreaming copied to clipboard

[BUG]: Screen is flipped vertically and Datachannel dead when close up one of multi-tabs

Open lyclyc171 opened this issue 1 year ago • 8 comments

Package version

3.1.0-exp.6

Environment

* OS: Debian 11
* Unity version:2022.2.2f1c1
* Graphics API: OpenGL
* Browser: FireFox

Steps To Reproduce

  1. Running broadcast sample on debian 11
  2. Open multiple tabs(>1) on browser
  3. Close one of tabs

Current Behavior

  1. Observing screen is flipped vertically
  2. Do not receive any mouse and keyboard event

Expected Behavior

screen and user interface all going well

Anything else?

Actually I have find the reason by debugging. BroadCast.Disconnect() will be called when close a tab, then following functions RemoveSender and RemoveChannel are called subsequently.

private void Disconnect(string connectionId)
{
    if (!connectionIds.Contains(connectionId))
        return;
    connectionIds.Remove(connectionId);

    foreach (var sender in streams.OfType<IStreamSender>())
    {
        RemoveSender(connectionId, sender);  // Cause problem 1
    }
    foreach (var receiver in streams.OfType<IStreamReceiver>())
    {
        RemoveReceiver(connectionId, receiver);
    }
    foreach (var channel in streams.OfType<IDataChannel>())
    {
        RemoveChannel(connectionId, channel);   // Cause problem 2
    }
}
  1. RemoveSender lead to call Dispose() in VideoStreamSourceScreen, then m_screenCopyTexture will be destroyed image which is the reference to sourceTexture_ in VideoTrackSource image so the sourceTexture_ is null and Graphics.Blit will copy a correct screen texture to upside down.

  2. As for RemoveChannel, I think there is already a commit to fix it: https://github.com/Unity-Technologies/UnityRenderStreaming/pull/925

lyclyc171 avatar Jul 28 '23 02:07 lyclyc171

@lyclyc171 yeah i had this problem long time ago, and i think it was because of this RemoveSender method in SignalingHandlerBase which was probably removing the track for that one user, then recreating a new track which wrongfully flips the texture again for the other users. So I commented it out: image and i also updated the SetTransceiver method in StreamSenderBase too image Now, this might get things working for you, but I'm not fully sure if I'm fully cleaning up everything memory-wise, so insights here would be appreciated.

JohnnyNgo avatar Jul 31 '23 19:07 JohnnyNgo

@lyclyc171 How about the google chrome?

karasusan avatar Aug 01 '23 05:08 karasusan

@JohnnyNgo Is this issue already fixed by #925 ?

karasusan avatar Aug 01 '23 05:08 karasusan

@karasusan I'm using Render Streaming 3.1.0-exp.6 for reference, so I don't think I have tried that solution. I never had the issue of inputs or resolution changes as mentioned in #925, probably because I don't use Broadcast.cs (I made my own custom script to handle removing/adding senders/channels to each users)

So I'd say my solution here is more specific to the Vertical Flipping part and is not already fixed.

JohnnyNgo avatar Aug 01 '23 19:08 JohnnyNgo

@lyclyc171 How about the google chrome?

No, it doesn't work

lyclyc171 avatar Aug 02 '23 07:08 lyclyc171

@lyclyc171 yeah i had this problem long time ago, and i think it was because of this RemoveSender method in SignalingHandlerBase which was probably removing the track for that one user, then recreating a new track which wrongfully flips the texture again for the other users. So I commented it out: image and i also updated the SetTransceiver method in StreamSenderBase too image Now, this might get things working for you, but I'm not fully sure if I'm fully cleaning up everything memory-wise, so insights here would be appreciated.

@JohnnyNgo Does the screen image turn to normal after you comment out "RemoveTrack"? Actually my debugging result tell me "OnStroppedStream" ( in your second pic ) is the reason who calls Dispose().

Anyway, thanks for your clue, I will try to comment RemoveTrack out to check result.

lyclyc171 avatar Aug 02 '23 07:08 lyclyc171

memo: URS-624

karasusan avatar Aug 08 '23 05:08 karasusan

Hey I have a similar issue in 3.1.0-exp.7. When I have multiple tabs open and close one the image for the others is distorted.
Just changing the SetTransceiver method to how @JohnnyNgo commented seems to fix it for me. (Or just never calling RemoveSender to begin with) Are there already plans to implement this or sth similar @karasusan and if yes do you know when this might happen?

RaoulBickmann avatar Oct 09 '23 09:10 RaoulBickmann