Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Josh Klint   GDNet+   -  Reputation: 1354

Like
0Likes
Like

Posted 27 August 2013 - 10:01 AM

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?


Build mobile games with native code

http://www.leadwerks.com


Sponsor:

#2 frob   Moderators   -  Reputation: 22731

Like
1Likes
Like

Posted 27 August 2013 - 11:44 AM

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?


Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I write about assorted stuff.


#3 Josh Klint   GDNet+   -  Reputation: 1354

Like
0Likes
Like

Posted 27 August 2013 - 02:45 PM

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, 27 August 2013 - 02:46 PM.

Build mobile games with native code

http://www.leadwerks.com


#4 frob   Moderators   -  Reputation: 22731

Like
0Likes
Like

Posted 27 August 2013 - 03:33 PM

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.


Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I write about assorted stuff.


#5 Josh Klint   GDNet+   -  Reputation: 1354

Like
0Likes
Like

Posted 28 August 2013 - 01:20 AM

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, 28 August 2013 - 01:21 AM.

Build mobile games with native code

http://www.leadwerks.com





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS