Jump to content
  • Advertisement
Sign in to follow this  
JoshKlint_34394

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

This topic is 1787 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement

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

It's rather pointless to debug this code if I (and apparently no one else) don't even know the correct place to call the function in question.

Edited by Josh Klint

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!