0

I try to send a value from my Activity through a GLSurfaceView to the Renderer, but there are some problems with the object in the SurfaceView class. I think I can't access directly to the Renderer from my Activity, I've tried. I get a null-Exception in my GLView class when I try to set the value.

public class Activity extends Activity implements SeekBar.OnSeekBarChangeListener{
GLSurfaceView mGLView;
...

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.layout_1d);
    mGLView = (GLView)findViewById(R.id.surfaceView1D);

    mGLView = new GLView(this,10);
//      mGLView.mRenderer.var_in_Renderer=10;   //Test, but not Working!

     }
...
     public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
         mGLView.var_in_Renderer=progress;   //Not working
         mGLView.setProgress(progress);
     }
...
}

class GLView extends GLSurfaceView {
   MyGLRenderer mRenderer;

   void setProgress(int progress){
       mRenderer.var_in_Renderer=progress;   //Error!!!!!!!!!!!!!!!!
   }

   //Empty Constructor don't go, so I filled
   public GLView(Context context,int progress){
      super(context);
   }

   public GLView(Context context, AttributeSet attrs) {
      super(context,attrs);

      // Set the Renderer for drawing on the GLSurfaceView
      mRenderer = new MyGLRenderer();
      setRenderer(mRenderer);
      mRenderer.var_in_Renderer=10; //That would work, but is not what I need
   }
}

How can I set a value for the variable in my Renderer?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Calling constructor _new GLView(this,10);_ does not instantiate _mRenderer_ variable. – harism Jun 09 '14 at 20:23
  • No that doesn't instantiate. The other Constructor initialize the object what I need, but I can't access to this, the second Constructor will called by the xml I think. Have a look to the last row, that would work, but the method setProgress doesn't !? What's the difference, is this not the same mRenderer object? –  Jun 09 '14 at 21:05
  • Why don't you simply delete/comment out the _mGLView = new GLView(this,10)_ line. It is overwriting the properly instantiated _mGLView variable with something half baked. – harism Jun 09 '14 at 21:08
  • :) Yes, you are right, now it works. In additional I had the wrong global classtype of mGLView, I used GLSurfaceView instead of GLView mGLView. –  Jun 09 '14 at 21:39

0 Answers0