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