Skip to content

Commit adee551

Browse files
authored
Prevent errors in win editor when copying cam texture (#66)
1 parent 9f274e1 commit adee551

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Runtime/Scripts/WebCameraSource.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace LiveKit
1212
public class WebCameraSource : RtcVideoSource
1313
{
1414
TextureFormat _textureFormat;
15+
private RenderTexture _tempTexture;
1516

1617
public WebCamTexture Texture { get; }
1718

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

@@ -64,7 +66,16 @@ protected override bool ReadBuffer()
6466
var bytes = MemoryMarshal.Cast<Color32, byte>(pixels);
6567
_data.CopyFrom(bytes.ToArray());
6668
_requestPending = true;
67-
Graphics.CopyTexture(Texture, _dest);
69+
70+
if (Texture.graphicsFormat != _dest.graphicsFormat)
71+
{
72+
Graphics.Blit(Texture, _tempTexture);
73+
Graphics.CopyTexture(_tempTexture, _dest);
74+
}
75+
else
76+
{
77+
Graphics.CopyTexture(Texture, _dest);
78+
}
6879

6980
return textureChanged;
7081
}

0 commit comments

Comments
 (0)