UnityOSC
UnityOSC copied to clipboard
Received OSC message that triggers a Unity error causes loop
In Unity v2017.2.0f3, when an OSC message is received succesfully but results in an error in Unity, a loop occurs somewhere where the OSC message is sent again or reprocessed which results in an error....
Below is some simple code which reproduces the issue
// OSCMessageReceiver
// Unity code where an incoming OSC message comes in
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OSCMessageReceiver: MonoBehaviour {
public OSC osc;
public int[] numbers = new int[0];
// Use this for initialization
void Start () {
osc.SetAddressHandler("/filter", OnReceiveFilter);
}
// Update is called once per frame
void Update () {
}
void OnReceiveFilter(OscMessage message)
{
int x = message.GetInt(0);
Debug.Log(x);
Debug.LogError(numbers[x]);
}
}
# Python code that sends an OSC message
import argparse
import random
import time
from pythonosc import udp_client
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--ip", default="127.0.0.1",
help="The ip of the OSC server")
parser.add_argument("--port", type=int, default=6969,
help="The port the OSC server is listening on")
args = parser.parse_args()
client = udp_client.SimpleUDPClient(args.ip, args.port)
msg = 5
client.send_message("/filter", msg)
In the above example, the Python script sends a message to OSCMessageReceiver to display the 6th item in the array numbers
which is out of range and triggers an error inside Unity. As a result the aforementioned loop occurs. This issue is not fatal and does not crash Unity nor hinder gameplay as far as I can tell, but it does flood the console with error messages.
Hi, I am sorry, but I do not update or support UnityOSC anymore. Please use the following libraries instead :