Error while loading an IGeometry in an Android MetaIO project

568 views Asked by At
    private IGeometry mItem;

    @Override
        protected void loadContents() {
            try {

                // TODO: Load desired tracking data for planar marker tracking
                boolean result = metaioSDK
                        .setTrackingConfiguration("ORIENTATION_FLOOR");
                MetaioDebug.log("Tracking data loaded: " + result);


                //
                //Load the item one
                mItem = loadItem("Project/Assets/chair.obj");
                mGestureHandler.addObject(mItem, 1);
                setVisibleItem(false);
             }catch (Exception e){}
        }

        public IGeometry loadItem(String objectPath){       
              IGeometry item = null;        
              try {             
                     // TODO: Load desired tracking data for planar marker tracking             
                     boolean result = metaioSDK     .setTrackingConfiguration("ORIENTATION_FLOOR");                        
                     MetaioDebug.log("Tracking data loaded: " + result);

                 // Load Object             
                     String filepath = AssetsManager.getAssetPath(
                        getApplicationContext(),
                        objectPath);            

                     item = metaioSDK.createGeometry(filepath);

                if (item != null) {
                    item.setScale(200f);
                    item.setTranslation(new Vector3d(0f, 0f, 0f));
                    item.setRotation(new Rotation((float) Math.PI / 2f, 0f,
                            0f));

                    //mGestureHandler.addObject(item, position);
                                } else
                    MetaioDebug.log(Log.ERROR, "Error loading geometry: "
                            + filepath);        }catch (Exception e){}
                    return item;    }



View.OnClickListener onClickColorTheme1(final Button but)  {
        return new View.OnClickListener() {
            public void onClick(View v) {

                        //mItem is a global variable
                mItem = loadItem("Project/Assets/newChair.obj");
            }
        };
    }

The IGeometry is loaded inside the overridden 'loadContent' method in an android metaIO project. I want to load another object to 'mItem' after an on click event. But it doesn't load the newChair. This is the error that comes when debugging:

Error: geometry can only be created in the render thread

Tried many methods to solve this, but couldn't solve it. One of it is where I tried the following but not really sure whether it is correct and don't really know where to put this

mSurfaceView.queueEvent(new Runnable(){
@Override
 public void run(){
         mItem = loadItem("Project/Assets/newChair.obj");
     }

} 
1

There are 1 answers

0
arsalank2 On

mSurfaceView.queueEvent is the correct way of handling it. You can add this to loadItem method:

public IGeometry loadItem(final String objectPath)
{   
  mSurfaceView.queueEvent(new Runnable()
  {
    @Override
    public void run()
    {
      // load the items here
    }
  }
}