Improved error handling
This commit is contained in:
parent
2d0acd2a82
commit
6f6bae267a
@ -132,8 +132,10 @@ namespace RoboidControl.Unity {
|
||||
string extension = core.modelUrl[core.modelUrl.LastIndexOf(".")..];
|
||||
if (extension == ".jpg" || extension == ".png")
|
||||
StartCoroutine(LoadJPG());
|
||||
#if GLTF
|
||||
else if (extension == ".gltf" || extension == ".glb")
|
||||
ProcessGltfModel(core);
|
||||
#endif
|
||||
break;
|
||||
case PoseMsg.Id:
|
||||
Debug.Log($"{this.core.id} Handle Pose");
|
||||
@ -177,9 +179,9 @@ namespace RoboidControl.Unity {
|
||||
}
|
||||
}
|
||||
|
||||
#if GLTF
|
||||
bool loadingModel = false;
|
||||
private async void ProcessGltfModel(RoboidControl.Thing coreThing) {
|
||||
#if GLTF
|
||||
if (!loadingModel) {
|
||||
loadingModel = true;
|
||||
|
||||
@ -200,21 +202,6 @@ namespace RoboidControl.Unity {
|
||||
await gltfImport.InstantiateMainSceneAsync(parentTransform);
|
||||
SkinnedMeshRenderer[] meshRenderers = parentTransform.GetComponentsInChildren<SkinnedMeshRenderer>();
|
||||
|
||||
#if pHUMANOID4
|
||||
// if (parentThing.objectType == 7) {
|
||||
// HumanoidControl hc = parentThing.gameObject.GetComponent<HumanoidControl>();
|
||||
// if (hc == null)
|
||||
// hc = parentThing.gameObject.AddComponent<HumanoidControl>();
|
||||
|
||||
// foreach (SkinnedMeshRenderer meshRenderer in meshRenderers) {
|
||||
// if (meshRenderer.rootBone != null) {
|
||||
// Debug.Log("Found a skinned mesh with bones");
|
||||
// hc.RetrieveBonesFrom(meshRenderer.rootBone);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
#endif
|
||||
parentTransform.localScale = Vector3.one;
|
||||
if (meshRenderers.Length > 0) {
|
||||
foreach (SkinnedMeshRenderer meshRenderer in meshRenderers) {
|
||||
@ -234,8 +221,8 @@ namespace RoboidControl.Unity {
|
||||
}
|
||||
}
|
||||
loadingModel = true;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
private void ScanForThings(Transform rootTransform) {
|
||||
RoboidControl.Thing[] thingArray = this.core.owner.things.ToArray();
|
||||
|
@ -160,7 +160,6 @@ namespace RoboidControl {
|
||||
if (this.remoteSite == null)
|
||||
this.Publish(msg);
|
||||
else
|
||||
//this.Send(this.remoteSite, msg);
|
||||
this.remoteSite.Send(msg);
|
||||
|
||||
this.nextPublishMe = currentTimeMS + this.publishIntervalMS;
|
||||
@ -242,12 +241,6 @@ namespace RoboidControl {
|
||||
#region Send
|
||||
|
||||
public void SendThingInfo(Participant owner, Thing thing) {
|
||||
// Console.WriteLine("Send thing info");
|
||||
// this.Send(owner, new ThingMsg(this.networkId, thing));
|
||||
// this.Send(owner, new NameMsg(this.networkId, thing));
|
||||
// this.Send(owner, new ModelUrlMsg(this.networkId, thing));
|
||||
// this.Send(owner, new PoseMsg(this.networkId, thing));
|
||||
// this.Send(owner, new BinaryMsg(this.networkId, thing));
|
||||
owner.Send(new ThingMsg(this.networkId, thing));
|
||||
owner.Send(new NameMsg(this.networkId, thing));
|
||||
owner.Send(new ModelUrlMsg(this.networkId, thing));
|
||||
@ -264,23 +257,12 @@ namespace RoboidControl {
|
||||
this.Publish(new BinaryMsg(this.networkId, thing));
|
||||
}
|
||||
|
||||
// public bool Send(Participant owner, IMessage msg) {
|
||||
// int bufferSize = msg.Serialize(ref this.buffer);
|
||||
// if (bufferSize <= 0)
|
||||
// return true;
|
||||
|
||||
// IPEndPoint participantEndpoint = new IPEndPoint(IPAddress.Parse(owner.ipAddress), owner.port);
|
||||
// // Console.WriteLine($"msg to {participantEndpoint.Address.ToString()} {participantEndpoint.Port}");
|
||||
// this.udpClient?.Send(this.buffer, bufferSize, participantEndpoint);
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public bool Publish(IMessage msg) {
|
||||
int bufferSize = msg.Serialize(ref this.buffer);
|
||||
if (bufferSize <= 0)
|
||||
return true;
|
||||
|
||||
// Console.WriteLine($"publish to {broadcastIpAddress.ToString()} {this.port}");
|
||||
Console.WriteLine($"publish to {broadcastIpAddress.ToString()} {this.port}");
|
||||
this.udpClient?.Send(this.buffer, bufferSize, this.broadcastIpAddress, this.port);
|
||||
return true;
|
||||
}
|
||||
@ -291,15 +273,26 @@ namespace RoboidControl {
|
||||
|
||||
protected void ReceiveUDP(IAsyncResult result) {
|
||||
try {
|
||||
// UnityEngine.Debug.Log("received");
|
||||
if (this.udpClient == null) // || this.endPoint == null)
|
||||
if (this.udpClient == null)
|
||||
return;
|
||||
|
||||
byte[] data = this.udpClient.EndReceive(result, ref endPoint);
|
||||
byte[] data = { };
|
||||
try {
|
||||
data = this.udpClient.EndReceive(result, ref endPoint);
|
||||
}
|
||||
catch (SocketException e) {
|
||||
if (e.ErrorCode != 10054)
|
||||
throw;
|
||||
#if DEBUG
|
||||
else
|
||||
Console.WriteLine($"No receiver found for the previously sent UDP packet");
|
||||
#endif
|
||||
}
|
||||
// This does not yet take multi-packet messages into account!
|
||||
if (endPoint == null)
|
||||
return;
|
||||
|
||||
if (data.Length > 0) {
|
||||
// We can receive our own publish (broadcast) packages. How do we recognize them????
|
||||
// It is hard to determine our source port
|
||||
string ipAddress = endPoint.Address.ToString();
|
||||
@ -309,6 +302,7 @@ namespace RoboidControl {
|
||||
|
||||
ReceiveData(data, remoteParticipant);
|
||||
}
|
||||
}
|
||||
|
||||
udpClient.BeginReceive(new AsyncCallback(callbackResult => ReceiveUDP(callbackResult)), null);
|
||||
}
|
||||
@ -437,7 +431,7 @@ namespace RoboidControl {
|
||||
|
||||
protected virtual void Process(Participant sender, BinaryMsg msg) {
|
||||
#if DEBUG
|
||||
// Console.WriteLine($"{this.name}: Process BinaryMsg [{msg.networkId}/{msg.thingId}] {msg.dataLength}");
|
||||
// Console.WriteLine($"{this.name}: Process BinaryMsg [{msg.networkId}/{msg.thingId}] {msg.dataLength}");
|
||||
#endif
|
||||
Thing thing = sender.Get(msg.thingId);
|
||||
thing?.ProcessBinary(msg.data);
|
||||
|
Loading…
x
Reference in New Issue
Block a user