2017-01-05 42 views
0

我试图在创建后从我的页面填充我的场景,但出现上述错误。Urho Android - 仅在主线程中支持发送事件

这是Android的,它适用于iOS(与线程安全一些问题)

01-05 18:45:19.139 E/Urho3D (32719): Sending events is only supported from the main thread 
01-05 18:45:19.139 E/Urho3D (32719): Sending events is only supported from the main thread 
01-05 18:45:19.139 E/Urho3D (32719): Sending events is only supported from the main thread 
01-05 18:45:19.139 E/Urho3D (32719): Attempted to get resource Models/Box.mdl from outside the main thread 
01-05 18:45:19.149 E/Urho3D (32719): Attempted to get resource Materials/Stone.xml from outside the main thread 

任何想法,它是如何被创建之后将项目添加到我的场景?

urhoApp?.addItem(urhoval);

在我乌尔禾应用:

public void addItem(string p) 
     { 

      modelNode2 = scene.CreateChild(p); 
      modelNode2.Position = new Vector3(5.0f, 1.0f, 5.0f); 

      modelNode2.SetScale(10.0f); 

      var obj2 = modelNode2.CreateComponent<StaticModel>(); 
      obj2.Model = ResourceCache.GetModel("Models/Box.mdl"); 
      obj2.SetMaterial(urhoAssets.GetMaterial("Materials/Stone.xml")); 
     } 

回答

1

你可以尝试调用它在主线程:

InvokeOnMain(() =>{ 
        //Your code here 
        } 
0

一个机器人活动的每一个事件总是叫上单线程 - “主线程”。

此线程由所有活动事件发布到的队列支持。它们按照插入的顺序执行。

如果您正在调用Finish(),则线程将从当前任务中释放。

当Urho启动时,启动你的Urho线程的Android线程仍然活着,它被认为是主要的。因此它无法处理您的ResourceCache。

你应该完成()你的Android线程启动你的Urho线程。

startBtn.Click += (sender, e) => 
     { 
      Intent intent = new Intent(this, typeof(Urho3DActivity)); 
      intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop); 
      StartActivity(intent); 
      Finish(); 
     }; 

iOS是不同的。没有主线程,Apple OS以固有的稳定性处理事件。

startButton.TouchUpInside += delegate 
     { 
      Urho.Application Urho3DApp = Urho.Application.CreateInstance(typeof(Urho3DApp), new ApplicationOptions("Data")); 
      Urho3DApp.Run(); 
     };