Skip to content

Commit

Permalink
Prevent errors in win editor when copying cam texture (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
holofermes authored Dec 24, 2024
1 parent 9f274e1 commit adee551
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Runtime/Scripts/WebCameraSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace LiveKit
public class WebCameraSource : RtcVideoSource
{
TextureFormat _textureFormat;
private RenderTexture _tempTexture;

public WebCamTexture Texture { get; }

Expand Down Expand Up @@ -56,6 +57,7 @@ protected override bool ReadBuffer()
_bufferType = GetVideoBufferType(_textureFormat);
_data = new NativeArray<byte>(GetWidth() * GetHeight() * GetStrideForBuffer(_bufferType), Allocator.Persistent);
_dest = new Texture2D(GetWidth(), GetHeight(), TextureFormat.BGRA32, false);
if (Texture.graphicsFormat != _dest.graphicsFormat) _tempTexture = new RenderTexture(GetWidth(), GetHeight(), 0, _dest.graphicsFormat);
textureChanged = true;
}

Expand All @@ -64,7 +66,16 @@ protected override bool ReadBuffer()
var bytes = MemoryMarshal.Cast<Color32, byte>(pixels);
_data.CopyFrom(bytes.ToArray());
_requestPending = true;
Graphics.CopyTexture(Texture, _dest);

if (Texture.graphicsFormat != _dest.graphicsFormat)
{
Graphics.Blit(Texture, _tempTexture);
Graphics.CopyTexture(_tempTexture, _dest);
}
else
{
Graphics.CopyTexture(Texture, _dest);
}

return textureChanged;
}
Expand Down

0 comments on commit adee551

Please sign in to comment.