question

hira-7329 avatar image
0 Votes"
hira-7329 asked KyleWang-MSFT commented

It becomes null on UrhoSurface

I'm showing UrhoSurface in ContentView and trying to get it working.
However, the cube of EnterButton becomes null.
Why?


 public partial class Test3D : ContentView
     {
         Cube cube;
    
         public Test3D()
         {
             InitializeComponent();
    
             test();
         }
    
         public async void test()
         {
             cube = await urhoSurface.Show<Cube>(new ApplicationOptions("Data"));
         }
    
         public async void EnterButton(object sender, EventArgs args)
         {
             cube.Rotate();
         }
     }


Postscript

  public class Cube : Urho.Application
     {
         Node CubeNode;
         StaticModel model;
        
         Node cameraNode;
        
         public Cube(ApplicationOptions options) : base(options) { }
        
         protected override async void Start()
         {
             base.Start();
             await Create3DObject();
         }
        
         protected override void OnUpdate(float timeStep)
         {
             base.OnUpdate(timeStep);
         }
        
         protected override void OnDeleted()
         {
             base.OnDeleted();
         }
        
         public void Rotate()
         {
             CubeNode.Rotation *= new Quaternion(0.0f, 1.0f, 0.0f);
         }
        
         private async Task Create3DObject()
         {
             Scene scene = new Scene();
             scene.CreateComponent<Octree>();
        
             CubeNode = scene.CreateChild();
             CubeNode.Position = new Vector3(0, 0, 0);
             CubeNode.Rotation = new Quaternion(0, 0, 0);
             CubeNode.SetScale(15.0f);
        
             model = CubeNode.CreateComponent<StaticModel>();
        
             model.Model = ResourceCache.GetModel("Models/cube.mdl");
             Node lightNode = scene.CreateChild(name: "light");
             lightNode.SetDirection(new Vector3(0, 0, 0));
             lightNode.Rotate(new Quaternion(20.0f, 0.0f, 0.0f));
             Light light = lightNode.CreateComponent<Light>();
             light.Color = new Urho.Color(0.525f, 0.525f, 0.525f);
             light.LightType = LightType.Directional;
             light.Brightness = 0.8f;
        
             Node zoneNode = scene.CreateChild(name: "Zone");
             Zone zone = zoneNode.CreateComponent<Zone>();
             zone.SetBoundingBox(new BoundingBox(-10000.0f, 10000.0f));
             zone.AmbientColor = new Urho.Color(0.6f, 0.6f, 0.6f);
        
             cameraNode = scene.CreateChild(name: "camera");
             cameraNode.Position = new Vector3(0, 0, -5.0f);
             cameraNode.SetDirection(new Vector3(0, 0, 0) - cameraNode.Position);
             Camera camera = cameraNode.CreateComponent<Camera>();
        
             var viewport = new Viewport(Context, scene, camera, null);
             viewport.SetClearColor(Urho.Color.White);
             Renderer.SetViewport(0, viewport);
         }
     }
dotnet-xamarin
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@hira-7329 Base on the description you provided, can't reproduce the issue. Where did you define "urhoSurface"? Where did you call "EnterButton". So could you add more details? For example, a mininal, reproducible example.

0 Votes 0 ·

I'm sorry.
The urhoSurface and EnterButton are on xmal.

 <?xml version="1.0" encoding="UTF-8"?>
 <ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
              xmlns:urho="clr-namespace:Urho.Forms;assembly=UrhoSharp.Forms"
              x:Class="AirPri.Test3D">
     <AbsoluteLayout AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All">
    
         <Grid AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All">
             <urho:UrhoSurface x:Name="urhoSurface" InputTransparent="True" />
         </Grid>
            
         <Button Text="Enter" Clicked="EnterButton" AbsoluteLayout.LayoutBounds="0.5,1,100,100" AbsoluteLayout.LayoutFlags="PositionProportional"/>
    
     </AbsoluteLayout>
 </ContentView>
0 Votes 0 ·

@hira-7329 What is the code of class "Cube"? I defined a class Inherits "Application" but did not get any "null exception". So could you add more info which can reproduce the issue? Just edit your question description, rather than posting new comment.

0 Votes 0 ·

Added "Cube" class.

0 Votes 0 ·
Show more comments

0 Answers