0

I'm trying to populate my scene from my page after it has been created but i'm getting the above error.

This is for android , it works on iOS (Some issue with thread security)

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

Any idea how to add items to my scene after it has been created ?

urhoApp?.addItem(urhoval);

In my urho App :

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"));
        } 
Jimmy
  • 895
  • 3
  • 12
  • 36

2 Answers2

2

You could try to invoke it on the main thread:

InvokeOnMain(() =>{
                   //Your code here 
                  }
Skylark
  • 149
  • 6
  • Excellent, I was using `Xamarin.Forms.Device.BeginInvokeOnMainThread()` to no avail. In hindsight it is obvious that the game main thread has to be different to the app's UI main thread and it is nice that Urho provides this mechanism of posting to it :) – CodingLumis Oct 02 '19 at 13:44
0

Every event of an android Activity is always called on a single thread - The "Main thread".

This thread is backed by a Queue into which all the activity events are getting posted. They are executed in the order of insertion.

If you are calling Finish(), the thread is freed from the current task.

Your Android thread that starts your Urho thread is still alive when Urho starts, and it is regarded as Main. Therefore it cannot handle your ResourceCache.

You should Finish() your Android thread that starts your Urho thread.

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

iOS is different. There is no main thread, and the Apple OS handles the events with inherent stability.

startButton.TouchUpInside += delegate
        {
            Urho.Application Urho3DApp = Urho.Application.CreateInstance(typeof(Urho3DApp), new ApplicationOptions("Data"));
            Urho3DApp.Run();
        };
Geert Jan
  • 408
  • 1
  • 6
  • 22