glDrawArrays make program breakdown, could you kindly help me to make a root cause analysis?

in my embed program, this is a fix_paint_png function which used to render the icon of pictures, and the program frequently breaks down when it calls glDrawArrays(...).

could you kindly help me to analysis the root cause of break down ? thanks in advance .

below is the source code of this function.

void ShowUiMain::fixed_paint_tex(TEX tex,float px,float py,float lx,float ly,float xx,float yy,float winWidth,float winHeight,float width,float height,bool stretch,float angle,float opacity)
{
#ifdef ShowUiMain_DBG
    static bool is_func_running = false;
    if(is_func_running)
    {
        return;
    }else
    {
        is_func_running = true;
    }
#endif
#ifdef ShowUiMain_DBG
    printf("**************************************ShowUiMain::fixed_paint_tex start ******************************\r\n");
    printf("enter file : %s, func:%s,line:%d .\r\n", __FILE__,__FUNCTION__,__LINE__);
#endif
    GLboolean  cull_enable=glIsEnabled(GL_CULL_FACE );
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
#ifdef ShowUiMain_DBG
    printf("in file : %s, func:%s,line:%d .\r\n", __FILE__,__FUNCTION__,__LINE__);
#endif
    float x0,y0,x1,y1;
    if(stretch){
        x0=(xx-winWidth/2)/(winWidth/2);
        y0=(winHeight/2-yy)/(winHeight/2);
        x1=(xx+width-winWidth/2)/(winWidth/2);
        y1=(winHeight/2-(yy+height))/(winHeight/2);
    }else{
        x0=(xx-winWidth/2)/(winWidth/2);
        y0=(winHeight/2-yy)/(winHeight/2);
        x1=(xx+lx-winWidth/2)/(winWidth/2);
        y1=(winHeight/2-(yy+ly))/(winHeight/2);
    }
#ifdef ShowUiMain_DBG
    printf("in file : %s, func:%s,line:%d .\r\n", __FILE__,__FUNCTION__,__LINE__);
#endif
    //////////////////////////////////////////////////////////////////
    float vertices[30+1]={
        x0, y0, -0.1,  px/(float)tex.tex_width, py/(float)tex.tex_height,      //   0        2/3
        x0, y1, -0.1,  px/(float)tex.tex_width, (py+ly)/(float)tex.tex_height, //
        x1, y0, -0.1, (px+lx)/(float)tex.tex_width, py/(float)tex.tex_height,      //
        x1, y0, -0.1, (px+lx)/(float)tex.tex_width, py/(float)tex.tex_height,      //
        x0, y1, -0.1,  px/(float)tex.tex_width, (py+ly)/(float)tex.tex_height, //
        x1, y1, -0.1, (px+lx)/(float)tex.tex_width, (py+ly)/(float)tex.tex_height,  //   1/4       5
        0
    };
#ifdef ShowUiMain_DBG
    printf("in file : %s, func:%s,line:%d .\r\n", __FILE__,__FUNCTION__,__LINE__);
#endif
    float arc_angle=angle*M_PI/180.0f;

    float  mid_x=(x0+x1)/2.0;
    float  mid_y=(y0+y1)/2.0;

    if(angle > 0.000001 ||  angle < -0.000001)   /* omit calculation when angle == 0; */
    {
        for(int i=0;i<30;i+=5)
        {
            xx=(vertices[i]-mid_x)*cos(arc_angle)-(vertices[i+1]-mid_y)*sin(arc_angle)+mid_x;
            yy=(vertices[i]-mid_x)*sin(arc_angle)+(vertices[i+1]-mid_y)*cos(arc_angle)+mid_y;
            vertices[i]=xx;
            vertices[i+1]=yy;
        }
    }

#ifdef ShowUiMain_DBG
    printf("in file : %s, func:%s,line:%d .\r\n", __FILE__,__FUNCTION__,__LINE__);
#endif
    GLuint program = shaderObj->get_program();
    glUseProgram(program);
    glUniform1i(glGetUniformLocation(program, "sTexture"), 0);
    glUniform1f(glGetUniformLocation(program, "opacity"), opacity);

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, tex.texid);

    glDisable(GL_DEPTH_TEST);
#ifdef ShowUiMain_DBG
    printf("in file : %s, func:%s,line:%d .\r\n", __FILE__,__FUNCTION__,__LINE__);
#endif
    if(b_blend)
    {
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }
    else
        glDisable(GL_BLEND);
#ifdef ShowUiMain_DBG
    printf("in file : %s, func:%s,line:%d .\r\n", __FILE__,__FUNCTION__,__LINE__);
#endif
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);
#ifdef ShowUiMain_DBG
    printf("in file : %s, func:%s,line:%d .\r\n", __FILE__,__FUNCTION__,__LINE__);
#endif
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 20, vertices);
    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 20, vertices+3);
#ifdef ShowUiMain_DBG
    printf("in file : %s, func:%s,line:%d .\r\n", __FILE__,__FUNCTION__,__LINE__);
#endif
    glDrawArrays(GL_TRIANGLES, 0, 6);

#ifdef ShowUiMain_DBG
    printf("in file : %s, func:%s,line:%d .\r\n", __FILE__,__FUNCTION__,__LINE__);
#endif
    glDisableVertexAttribArray(0);
    glDisableVertexAttribArray(1);
#ifdef ShowUiMain_DBG
    printf("in file : %s, func:%s,line:%d .\r\n", __FILE__,__FUNCTION__,__LINE__);
#endif
    if(cull_enable)
        glEnable(GL_CULL_FACE);
    else
        glDisable(GL_CULL_FACE);
#ifdef ShowUiMain_DBG
    is_func_running = false;
#endif
#ifdef ShowUiMain_DBG
    printf("quit file : %s, func:%s,line:%d .\r\n", __FILE__,__FUNCTION__,__LINE__);
    printf("**************************************ShowUiMain::fixed_paint_tex end ******************************\r\n");

#endif
}

since when program breaks down, the log printed on the screen stops before calling glDrawArrays(...), and the error info is :

appname  invoked oom-killer: gfp_mask=0x26000c0, order=1, oom_score_adj=0

Not going to lie, I am in the learning stage of OpenGL too, so I could be way off the mark. You are binding an EBO, so you should be using indices and drawing using glDrawElements?

Questions:

  • What HW platform? CPU? GPU?
  • How much physical CPU RAM is installed?
  • 32-bit or 64-bit OS?
  • Are you running in a VM?

The OS appears to be Linux.

The Linux kernel has determined that memory available has gotten too low, and has gone to killing processes to try and free some up. You need to locate which app(s) are consuming too much physical memory and put a stop to that. So this really isn’t an OpenGL question.

Toward tracking down the culprits however, try this. I don’t agree with all the sentiments expressed exactly, because many apps are written to be CPU memory hogs (many written to assume lazy physical RAM page allocation, which is the default). But these may put you on a course to track down which app(s) are using up all of your RAM:

Hello, Dark_Photon,
Thanks for your kindly advice. below is some information:
1, HW platform : A15 of TDA2SX ;
2, CPU ram is about 2GB and when process breaks down , the free mem is about 1.2GB;
3, an embed linux system;

actually, the app was killed by oom_killer since app apply for 2 pages of memory( 8KB) and system has enough free mem, it seems that there are other reasons why the oom_killer kills app.but i don’t know what they are.
thanks again.

Ok, so ARM Cortex A-15 CPU, ImgTech PowerVR SGX544 GPU, and not much memory if you’re running any fat apps and services (or very many of them at once).

Just take it step-by-step and I’m sure you’ll figure it out. As alluded to above, the first step is to switch your Linux config to fail RAM alloc requests by the RAM hog app requesting them, not approve some requests that are unsupportable given your amount of RAM.

Hey, Dark_Photon,

thanks for your kindly advices. let me explain the background info of this issue.

1, the app which calls openGL to render ui running on tda2Sx platform, named " apps.out " ;
2, when glDrawArrays func is called, the apps.out breakdown and error printed:
apps.out invoked oom-killer: gfp_mask=0x26000c0, order=1, oom_score_adj=0
which means apps.out was killed by oom_killer when it applys 2 mem pages( 8KBytes);
3, when apps.out runs, the system free mem is about 1.2GBytes and keeps about 1.2GBytes when apps.out breaks down;
4, glDrawArrays func is called by render func which is called by sgxFrmCpy link which runs on A15 core. yes, as your mentioned, sgx is TDA2sx’s gpu, so this link call render func which maybe run on GPU core.
5, in ideal situation, sgxFrmCpy calls the render func per 33ms about. but currently render func spends 40~200ms to render the ui.

and on the board, there is no fat app and not many small apps run at the same time.
so ,it puzzles me why apps.out breaks down when it only apply for 8KBytes mem, and i conclude that the 8KBytes mem is for icon of pictures which need to render by glDrawArrays func.

for your reference and have a nice thanksgiving day.
BR.

hello, bobjones,

nice to hear from you and thanks for you advice, i am green hand too.
since the app break down when it load the image at first time. so it’s difficult to run smoothly by calling glDrawElements.

and today I read that the glBindBuffer(GL_ARRAY_BUFFER, 0) means that cancelling the binding relation between array_buffer and previous buffer since 0 is not a valid buffer id number.

thanks again and have a nice day.
BR.
ohenry