Android OpenGL: GLSurfaceView.Renderer.onDrawFrame() called twice at startup









up vote
0
down vote

favorite












I have a simple Android application which uses OpenGL (via GLSurfaceView).
Code is below:



public class MainActivity extends Activity 
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(new MyGLSurfaceView(this));


class MyGLSurfaceView extends GLSurfaceView implements GLSurfaceView.Renderer
MyGLSurfaceView(Context context)
super(context);
setEGLContextClientVersion(2); // OpenGL ES 2.0
setRenderer(this); // callbacks go to this class
setRenderMode(RENDERMODE_WHEN_DIRTY); // draw on request


public void onSurfaceChanged(GL10 gl, int width, int height)

public void onSurfaceCreated(GL10 gl, EGLConfig config)

public void onDrawFrame(GL10 gl)
/* if (startup) do_only_once(); */
try Thread.sleep(250); catch (Exception ignored)





At the application startup onDrawFrame() (of GLSurfaceView.Renderer) called twice most of times.
As far as I know, onSurfaceChanged() (of GLSurfaceView.Renderer) should call onDrawFrame(), but I don't understand why it happens several times.



I would like to compute and draw some "background" objects, that should be done only once. I use setRenderMode(RENDERMODE_WHEN_DIRTY). But onDrawFrame() is still called several times. How can I make it to be called only once? What is the reason of such repetitive calling?



Adding Logging for these functions (and also some default Activity callbacks) in the start and the end of each will result in output below. Activity lifecycle seems to work fine:



// Example of function with Logging:
protected void onCreate(Bundle savedInstanceState)
Log.d("__DEBUG__", "onCreate() ");
super.onCreate(savedInstanceState);
setContentView(new MyGLSurfaceView(this));
Log.d("__DEBUG__", "onCreate() ");


22:12:46.361 __DEBUG__: onCreate()
22:12:46.376 __DEBUG__: MyGLSurfaceView()
22:12:46.376 __DEBUG__: MyGLSurfaceView()
22:12:46.430 __DEBUG__: onCreate()
22:12:46.431 __DEBUG__: onStart()
22:12:46.431 __DEBUG__: onStart()
22:12:46.432 __DEBUG__: onResume()
22:12:46.433 __DEBUG__: onResume()
22:12:46.498 __DEBUG__: onSurfaceCreated()
22:12:46.498 __DEBUG__: onSurfaceCreated()
22:12:46.498 __DEBUG__: onSurfaceChanged()
22:12:46.498 __DEBUG__: onSurfaceChanged()
22:12:46.498 __DEBUG__: onDrawFrame()
22:12:46.748 __DEBUG__: onDrawFrame()
22:12:46.754 __DEBUG__: onDrawFrame()
22:12:47.004 __DEBUG__: onDrawFrame()









share|improve this question























  • Possible duplicate of Is it normal for the "activity.onCreate()" method to be called multiple times
    – muradm
    Nov 11 at 20:03










  • @muradm, my Activity.onCreate() works fine (called only once, according to Log), the question is about GLSurfaceView lifecycle.
    – DualGlad
    Nov 11 at 20:09










  • According to log everything is called twice. And your GLSurfaceView is initialized within onCreate() method. So if it is called twice, then onCreate() is called twice. Otherwise you are initializing GLSurfaceView also somewhere else, which is not illustrated in code snippets.
    – muradm
    Nov 11 at 20:15










  • @muradm, for logging I used "func_name() " at the beginning ot func_name() and "func_name() " at the end of it. It shows that new onDrawFrame() is called only after the end of previous one.
    – DualGlad
    Nov 11 at 20:27










  • @muradm, added an example of Logging. Each function should be printed 2 times
    – DualGlad
    Nov 11 at 20:33














up vote
0
down vote

favorite












I have a simple Android application which uses OpenGL (via GLSurfaceView).
Code is below:



public class MainActivity extends Activity 
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(new MyGLSurfaceView(this));


class MyGLSurfaceView extends GLSurfaceView implements GLSurfaceView.Renderer
MyGLSurfaceView(Context context)
super(context);
setEGLContextClientVersion(2); // OpenGL ES 2.0
setRenderer(this); // callbacks go to this class
setRenderMode(RENDERMODE_WHEN_DIRTY); // draw on request


public void onSurfaceChanged(GL10 gl, int width, int height)

public void onSurfaceCreated(GL10 gl, EGLConfig config)

public void onDrawFrame(GL10 gl)
/* if (startup) do_only_once(); */
try Thread.sleep(250); catch (Exception ignored)





At the application startup onDrawFrame() (of GLSurfaceView.Renderer) called twice most of times.
As far as I know, onSurfaceChanged() (of GLSurfaceView.Renderer) should call onDrawFrame(), but I don't understand why it happens several times.



I would like to compute and draw some "background" objects, that should be done only once. I use setRenderMode(RENDERMODE_WHEN_DIRTY). But onDrawFrame() is still called several times. How can I make it to be called only once? What is the reason of such repetitive calling?



Adding Logging for these functions (and also some default Activity callbacks) in the start and the end of each will result in output below. Activity lifecycle seems to work fine:



// Example of function with Logging:
protected void onCreate(Bundle savedInstanceState)
Log.d("__DEBUG__", "onCreate() ");
super.onCreate(savedInstanceState);
setContentView(new MyGLSurfaceView(this));
Log.d("__DEBUG__", "onCreate() ");


22:12:46.361 __DEBUG__: onCreate()
22:12:46.376 __DEBUG__: MyGLSurfaceView()
22:12:46.376 __DEBUG__: MyGLSurfaceView()
22:12:46.430 __DEBUG__: onCreate()
22:12:46.431 __DEBUG__: onStart()
22:12:46.431 __DEBUG__: onStart()
22:12:46.432 __DEBUG__: onResume()
22:12:46.433 __DEBUG__: onResume()
22:12:46.498 __DEBUG__: onSurfaceCreated()
22:12:46.498 __DEBUG__: onSurfaceCreated()
22:12:46.498 __DEBUG__: onSurfaceChanged()
22:12:46.498 __DEBUG__: onSurfaceChanged()
22:12:46.498 __DEBUG__: onDrawFrame()
22:12:46.748 __DEBUG__: onDrawFrame()
22:12:46.754 __DEBUG__: onDrawFrame()
22:12:47.004 __DEBUG__: onDrawFrame()









share|improve this question























  • Possible duplicate of Is it normal for the "activity.onCreate()" method to be called multiple times
    – muradm
    Nov 11 at 20:03










  • @muradm, my Activity.onCreate() works fine (called only once, according to Log), the question is about GLSurfaceView lifecycle.
    – DualGlad
    Nov 11 at 20:09










  • According to log everything is called twice. And your GLSurfaceView is initialized within onCreate() method. So if it is called twice, then onCreate() is called twice. Otherwise you are initializing GLSurfaceView also somewhere else, which is not illustrated in code snippets.
    – muradm
    Nov 11 at 20:15










  • @muradm, for logging I used "func_name() " at the beginning ot func_name() and "func_name() " at the end of it. It shows that new onDrawFrame() is called only after the end of previous one.
    – DualGlad
    Nov 11 at 20:27










  • @muradm, added an example of Logging. Each function should be printed 2 times
    – DualGlad
    Nov 11 at 20:33












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a simple Android application which uses OpenGL (via GLSurfaceView).
Code is below:



public class MainActivity extends Activity 
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(new MyGLSurfaceView(this));


class MyGLSurfaceView extends GLSurfaceView implements GLSurfaceView.Renderer
MyGLSurfaceView(Context context)
super(context);
setEGLContextClientVersion(2); // OpenGL ES 2.0
setRenderer(this); // callbacks go to this class
setRenderMode(RENDERMODE_WHEN_DIRTY); // draw on request


public void onSurfaceChanged(GL10 gl, int width, int height)

public void onSurfaceCreated(GL10 gl, EGLConfig config)

public void onDrawFrame(GL10 gl)
/* if (startup) do_only_once(); */
try Thread.sleep(250); catch (Exception ignored)





At the application startup onDrawFrame() (of GLSurfaceView.Renderer) called twice most of times.
As far as I know, onSurfaceChanged() (of GLSurfaceView.Renderer) should call onDrawFrame(), but I don't understand why it happens several times.



I would like to compute and draw some "background" objects, that should be done only once. I use setRenderMode(RENDERMODE_WHEN_DIRTY). But onDrawFrame() is still called several times. How can I make it to be called only once? What is the reason of such repetitive calling?



Adding Logging for these functions (and also some default Activity callbacks) in the start and the end of each will result in output below. Activity lifecycle seems to work fine:



// Example of function with Logging:
protected void onCreate(Bundle savedInstanceState)
Log.d("__DEBUG__", "onCreate() ");
super.onCreate(savedInstanceState);
setContentView(new MyGLSurfaceView(this));
Log.d("__DEBUG__", "onCreate() ");


22:12:46.361 __DEBUG__: onCreate()
22:12:46.376 __DEBUG__: MyGLSurfaceView()
22:12:46.376 __DEBUG__: MyGLSurfaceView()
22:12:46.430 __DEBUG__: onCreate()
22:12:46.431 __DEBUG__: onStart()
22:12:46.431 __DEBUG__: onStart()
22:12:46.432 __DEBUG__: onResume()
22:12:46.433 __DEBUG__: onResume()
22:12:46.498 __DEBUG__: onSurfaceCreated()
22:12:46.498 __DEBUG__: onSurfaceCreated()
22:12:46.498 __DEBUG__: onSurfaceChanged()
22:12:46.498 __DEBUG__: onSurfaceChanged()
22:12:46.498 __DEBUG__: onDrawFrame()
22:12:46.748 __DEBUG__: onDrawFrame()
22:12:46.754 __DEBUG__: onDrawFrame()
22:12:47.004 __DEBUG__: onDrawFrame()









share|improve this question















I have a simple Android application which uses OpenGL (via GLSurfaceView).
Code is below:



public class MainActivity extends Activity 
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(new MyGLSurfaceView(this));


class MyGLSurfaceView extends GLSurfaceView implements GLSurfaceView.Renderer
MyGLSurfaceView(Context context)
super(context);
setEGLContextClientVersion(2); // OpenGL ES 2.0
setRenderer(this); // callbacks go to this class
setRenderMode(RENDERMODE_WHEN_DIRTY); // draw on request


public void onSurfaceChanged(GL10 gl, int width, int height)

public void onSurfaceCreated(GL10 gl, EGLConfig config)

public void onDrawFrame(GL10 gl)
/* if (startup) do_only_once(); */
try Thread.sleep(250); catch (Exception ignored)





At the application startup onDrawFrame() (of GLSurfaceView.Renderer) called twice most of times.
As far as I know, onSurfaceChanged() (of GLSurfaceView.Renderer) should call onDrawFrame(), but I don't understand why it happens several times.



I would like to compute and draw some "background" objects, that should be done only once. I use setRenderMode(RENDERMODE_WHEN_DIRTY). But onDrawFrame() is still called several times. How can I make it to be called only once? What is the reason of such repetitive calling?



Adding Logging for these functions (and also some default Activity callbacks) in the start and the end of each will result in output below. Activity lifecycle seems to work fine:



// Example of function with Logging:
protected void onCreate(Bundle savedInstanceState)
Log.d("__DEBUG__", "onCreate() ");
super.onCreate(savedInstanceState);
setContentView(new MyGLSurfaceView(this));
Log.d("__DEBUG__", "onCreate() ");


22:12:46.361 __DEBUG__: onCreate()
22:12:46.376 __DEBUG__: MyGLSurfaceView()
22:12:46.376 __DEBUG__: MyGLSurfaceView()
22:12:46.430 __DEBUG__: onCreate()
22:12:46.431 __DEBUG__: onStart()
22:12:46.431 __DEBUG__: onStart()
22:12:46.432 __DEBUG__: onResume()
22:12:46.433 __DEBUG__: onResume()
22:12:46.498 __DEBUG__: onSurfaceCreated()
22:12:46.498 __DEBUG__: onSurfaceCreated()
22:12:46.498 __DEBUG__: onSurfaceChanged()
22:12:46.498 __DEBUG__: onSurfaceChanged()
22:12:46.498 __DEBUG__: onDrawFrame()
22:12:46.748 __DEBUG__: onDrawFrame()
22:12:46.754 __DEBUG__: onDrawFrame()
22:12:47.004 __DEBUG__: onDrawFrame()






android opengl-es glsurfaceview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 21:13









Nicol Bolas

280k33461633




280k33461633










asked Nov 11 at 19:53









DualGlad

12




12











  • Possible duplicate of Is it normal for the "activity.onCreate()" method to be called multiple times
    – muradm
    Nov 11 at 20:03










  • @muradm, my Activity.onCreate() works fine (called only once, according to Log), the question is about GLSurfaceView lifecycle.
    – DualGlad
    Nov 11 at 20:09










  • According to log everything is called twice. And your GLSurfaceView is initialized within onCreate() method. So if it is called twice, then onCreate() is called twice. Otherwise you are initializing GLSurfaceView also somewhere else, which is not illustrated in code snippets.
    – muradm
    Nov 11 at 20:15










  • @muradm, for logging I used "func_name() " at the beginning ot func_name() and "func_name() " at the end of it. It shows that new onDrawFrame() is called only after the end of previous one.
    – DualGlad
    Nov 11 at 20:27










  • @muradm, added an example of Logging. Each function should be printed 2 times
    – DualGlad
    Nov 11 at 20:33
















  • Possible duplicate of Is it normal for the "activity.onCreate()" method to be called multiple times
    – muradm
    Nov 11 at 20:03










  • @muradm, my Activity.onCreate() works fine (called only once, according to Log), the question is about GLSurfaceView lifecycle.
    – DualGlad
    Nov 11 at 20:09










  • According to log everything is called twice. And your GLSurfaceView is initialized within onCreate() method. So if it is called twice, then onCreate() is called twice. Otherwise you are initializing GLSurfaceView also somewhere else, which is not illustrated in code snippets.
    – muradm
    Nov 11 at 20:15










  • @muradm, for logging I used "func_name() " at the beginning ot func_name() and "func_name() " at the end of it. It shows that new onDrawFrame() is called only after the end of previous one.
    – DualGlad
    Nov 11 at 20:27










  • @muradm, added an example of Logging. Each function should be printed 2 times
    – DualGlad
    Nov 11 at 20:33















Possible duplicate of Is it normal for the "activity.onCreate()" method to be called multiple times
– muradm
Nov 11 at 20:03




Possible duplicate of Is it normal for the "activity.onCreate()" method to be called multiple times
– muradm
Nov 11 at 20:03












@muradm, my Activity.onCreate() works fine (called only once, according to Log), the question is about GLSurfaceView lifecycle.
– DualGlad
Nov 11 at 20:09




@muradm, my Activity.onCreate() works fine (called only once, according to Log), the question is about GLSurfaceView lifecycle.
– DualGlad
Nov 11 at 20:09












According to log everything is called twice. And your GLSurfaceView is initialized within onCreate() method. So if it is called twice, then onCreate() is called twice. Otherwise you are initializing GLSurfaceView also somewhere else, which is not illustrated in code snippets.
– muradm
Nov 11 at 20:15




According to log everything is called twice. And your GLSurfaceView is initialized within onCreate() method. So if it is called twice, then onCreate() is called twice. Otherwise you are initializing GLSurfaceView also somewhere else, which is not illustrated in code snippets.
– muradm
Nov 11 at 20:15












@muradm, for logging I used "func_name() " at the beginning ot func_name() and "func_name() " at the end of it. It shows that new onDrawFrame() is called only after the end of previous one.
– DualGlad
Nov 11 at 20:27




@muradm, for logging I used "func_name() " at the beginning ot func_name() and "func_name() " at the end of it. It shows that new onDrawFrame() is called only after the end of previous one.
– DualGlad
Nov 11 at 20:27












@muradm, added an example of Logging. Each function should be printed 2 times
– DualGlad
Nov 11 at 20:33




@muradm, added an example of Logging. Each function should be printed 2 times
– DualGlad
Nov 11 at 20:33

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252604%2fandroid-opengl-glsurfaceview-renderer-ondrawframe-called-twice-at-startup%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252604%2fandroid-opengl-glsurfaceview-renderer-ondrawframe-called-twice-at-startup%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線