- Home /
Clearing RPC buffer on a NetworkView
I've been searching to see if anyone had the same issue when it comes to Network Memory leaks and I came across this post here. I am making a simple network project that grabs multiple images from the webcam using the WebCamTexture and streams them to another connected device and vice-versa. My main issue is after a set amount of time, sometimes 30 seconds sometimes 4 minutes, the sending rate becomes delayed and memory usage increases. Here's my code:
public Color32[] image = new Color32[webcamTexture.width * webcamTexture.height];
byte[] byteToFill = new byte[colorArray.Length * 4];
Texture2D[] texture = new Texture2D[2];
void FixedUpdate()
{
if (Network.connections.Length > 0)
{
webcamTexture.GetPixels32 (image);
Color32ArrayToByteArray (image, byteToFill);
networkView.RPC ("Send", RPCMode.Others, byteToFill);
}
}
[RPC]
public void Send(byte[] byteArray)
{
if (textureIndex == 0)
{
texture [0] = new Texture2D (320, 240);
ByteArrayToColor32 (byteArray, colorArray, color);
texture[0].SetPixels32 (colorArray);
texture[0].Apply ();
DestroyImmediate(renderer.material.mainTexture, true);
renderer.material.mainTexture = texture[0];
if (texture [1] != null)
Destroy (texture [1]);
textureIndex = 1;
}
else
{
texture [1] = new Texture2D (320, 240);
ByteArrayToColor32 (byteArray, colorArray, color);
texture[1].SetPixels32 (colorArray);
texture[1].Apply ();
DestroyImmediate(renderer.material.mainTexture, true);
renderer.material.mainTexture = texture[1];
if (texture [0] != null)
Destroy (texture [0]);
textureIndex = 0;
}
}
I had to make two textures because it wouldn't display the image properly if I used one.
How would one go about clearing the sending queue or emptying the Server's RPC buffer?
Your answer
Follow this Question
Related Questions
RPC not being called 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
RPC to server from client 1 Answer
Generic RPC Call 1 Answer