Sign in to follow this  
JoshKlint_34394

Android - Where to call surfaceView.getHolder().setFixedSize()?

Recommended Posts

I am trying to use surfaceView.getHolder().setFixedSize() to render to a half-resolution buffer on high-density Android displays.  Everywhere I try calling this command it either crashes or does nothing.  Where is this actually supposed to get called?

Share this post


Link to post
Share on other sites

It shouldn't crash --- assuming your call to getHolder() doesn't return null.  You need to always test for null objects, so make sure of that.

 

Its purpose is to configure a view surface prior to it being used.  Once it is created or locked you shouldn't be modifying it. 

 

Do you have some actual code snippits that we could look at, if you need?

Share this post


Link to post
Share on other sites
I tried in my class that extends glSurfaceView.Renderer, results in a crash:
    public void onSurfaceChanged(GL10 gl, int width, int height) {
    	if(!initRun) {
    		mView.getHolder().setFixedSize(width/2,height/2);
    		init(width/2, height/2);
    		initRun = true;
    	}
    	else
    	{
    		mView.getHolder().setFixedSize(width/2,height/2);
        	recreateSurface(width,height);
    	}
    }

I tried in AndroidActivity.onCreate() just after creating an AndroidSurfaceView (extends the GLSurfaceView class) and it has no effect:
		mView = new AndroidSurfaceView(this);
		mView.getHolder().setFixedSize(1920/2,1200/2);
Edited by Josh Klint

Share this post


Link to post
Share on other sites

in each case I would add the lines:

 

if(mView == null)

{

assert mView != null : "mView was null. Aborting";

return;

}

android.view.SurfaceHolder holder = mView.getHolder();

if(holder == null)

{

assert holder != null : "surface holder was null. Aborting.";

return;

}

holder.setFixedSize(1920/2,1200/2);

 

Assuming you have turned on assertions (which you really ought to do when developing) it should help isolate the crash. If you don't have asserts turned on, do something else in your app so you can trap it when shouldn't happen.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this