PDA

View Full Version : SIGILL on glBegin



banana joe
09-16-2013, 09:45 AM
I have a programm wich crashes at glBegin in a simple drawing function.

At first here's my main function


int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(w1, h1);
glutCreateWindow("texture copy test");
glutDisplayFunc(display);

glewInit();
button = new GLButton(button_texture, 0, 75, 24);

glutMainLoop();
}


The GLButton constructor calls the function pointer button_texture wich generates a button texture.



void button_texture(GLuint &texture_pushed,
GLuint &texture_hovered,
GLuint &texture_released,
uint16_t &width, uint16_t &height,
bool &has_alpha, wchar_t *text)
{
if (width < 1 || height < 1)
{
fprintf(stderr, "[button_texture] width*height muss größer als 0 sein\n");
exit(1);
}

has_alpha = true;

//Erstelle Framebuffer
GLuint framebuffer = 0;
glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);

glGenTextures(1, &texture_pushed);

glBindTexture(GL_TEXTURE_2D, texture_pushed);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, 0);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_pushed, 0);
GLenum draw_buffers[1] = {GL_COLOR_ATTACHMENT0};
glDrawBuffers(1, draw_buffers);

if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
{
fprintf(stderr, "[button_texture] Fehler im Framebuffer\n");
exit(1);
}

glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glViewport(0, 0, width, height);

glColor4f(0.8f, 0.0f, 0.8f, 0.5f);

glBegin(GL_POLYGON);
glVertex2f(0.f,0.f);
glVertex2f(width, 0.0f);
glVertex2f(width, (GLfloat)height/2.f);
glVertex2f(width-(GLfloat)height/2.f, height);
glVertex2f(0, height);
glEnd();
}


And the display function for the main loop, where the error occurs.



void display(void)
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));

glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, glutGet(GLUT_WINDOW_WIDTH), 0.0, glutGet(GLUT_WINDOW_HEIGHT), -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();


glLoadIdentity();
glDisable(GL_LIGHTING);

glColor3f(1,1,1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, button->texture_pushed);


// Draw a textured quad
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
glTexCoord2f(0, 1); glVertex3f(0, button->width, 0);
glTexCoord2f(1, 1); glVertex3f(button->height, button->width, 0);
glTexCoord2f(1, 0); glVertex3f(button->height, 0, 0);
glEnd();


glDisable(GL_TEXTURE_2D);
glPopMatrix();


glMatrixMode(GL_PROJECTION);
glPopMatrix();

glMatrixMode(GL_MODELVIEW);


glutSwapBuffers();
}


I've linked the programm to electric fence, here's the debugger output



ElectricFence Aborting: free(76b110): address not from malloc().

Program received signal SIGILL, Illegal instruction.
0x00007ffff645c6c7 in kill () from /usr/lib/libc.so.6




(gdb) bt full
#0 0x00007ffff645c6c7 in kill () from /usr/lib/libc.so.6
No symbol table info available.
#1 0x00007ffff6ff14ad in ?? () from /usr/lib/libefence.so.0
No symbol table info available.
#2 0x00007ffff6ff18c7 in EF_Abortv () from /usr/lib/libefence.so.0
No symbol table info available.
#3 0x00007ffff6ff1968 in EF_Abort () from /usr/lib/libefence.so.0
No symbol table info available.
#4 0x00007ffff6ff0eda in free () from /usr/lib/libefence.so.0
No symbol table info available.
#5 0x00007ffff2a53e68 in _mesa_align_realloc () from /usr/lib/libdricore9.2.0.so.1
No symbol table info available.
#6 0x00007ffff2bced4c in _mesa_add_parameter () from /usr/lib/libdricore9.2.0.so.1
No symbol table info available.
#7 0x00007ffff2bceefa in _mesa_add_state_reference () from /usr/lib/libdricore9.2.0.so.1
No symbol table info available.
#8 0x00007ffff2fedb29 in ?? () from /usr/lib/xorg/modules/dri/i965_dri.so
No symbol table info available.
#9 0x00007ffff2bc4882 in _mesa_glsl_link_shader () from /usr/lib/libdricore9.2.0.so.1
No symbol table info available.
#10 0x00007ffff2a38c33 in _mesa_get_fixed_func_fragment_program () from /usr/lib/libdricore9.2.0.so.1
No symbol table info available.
#11 0x00007ffff2a86f68 in _mesa_update_state_locked () from /usr/lib/libdricore9.2.0.so.1
No symbol table info available.
#12 0x00007ffff2a87041 in _mesa_update_state () from /usr/lib/libdricore9.2.0.so.1
No symbol table info available.
#13 0x00007ffff2ac5a08 in ?? () from /usr/lib/libdricore9.2.0.so.1
No symbol table info available.
#14 0x0000000000401ebf in display () at main.cpp:39
No locals.
#15 0x00007ffff7720ac4 in ?? () from /usr/lib/libglut.so.3
No symbol table info available.
#16 0x00007ffff7724329 in fgEnumWindows () from /usr/lib/libglut.so.3
No symbol table info available.
#17 0x00007ffff772107d in glutMainLoopEvent () from /usr/lib/libglut.so.3
No symbol table info available.
#18 0x00007ffff772187d in glutMainLoop () from /usr/lib/libglut.so.3
No symbol table info available.
#19 0x0000000000402310 in main (argc=1, argv=0x7fffffffe6e8) at main.cpp:214
No locals.


main.cpp:39 is the glBegin(GL_QUADS); line in the void display(void) function.
main.cpp:214 is the glutMainLoop(); line in the main function

banana joe
09-19-2013, 12:29 AM
Now i have shortened the code:



#include "GL/glew.h"
#include "GL/glext.h"
#include "GL/glu.h"
#include "GL/glut.h"

#include <cstdio>

uint16_t tex_width = 75;
uint16_t tex_height = 24;

GLuint texture;

void render_texture()
{
GLuint framebuffer = 0;

glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);

glGenTextures(1, &texture);

glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_width, tex_height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, 0);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
GLenum draw_buffers[1] = {GL_COLOR_ATTACHMENT0};
glDrawBuffers(1, draw_buffers);

if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
{
fprintf(stderr, "[render_texture] Fehler im Framebuffer\n");
exit(1);
}

glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glViewport(0, 0, tex_width, tex_height);

glColor4f(0.8f, 0.0f, 0.8f, 0.5f);

glBegin(GL_POLYGON);
glVertex2f(0.f,0.f);
glVertex2f(tex_width, 0.0f);
glVertex2f(tex_width, (GLfloat)tex_height/2.f);
glVertex2f(tex_width-(GLfloat)tex_height/2.f, tex_height);
glVertex2f(0, tex_height);
glEnd();
}

void display(void)
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));

glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT/* | GL_DEPTH_BUFFER_BIT*/);

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, glutGet(GLUT_WINDOW_WIDTH), 0.0, glutGet(GLUT_WINDOW_HEIGHT), -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();

glLoadIdentity();

glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);


// Draw a textured quad
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
glTexCoord2f(0, 1); glVertex3f(0, tex_width, 0);
glTexCoord2f(1, 1); glVertex3f(tex_height, tex_width, 0);
glTexCoord2f(1, 0); glVertex3f(tex_height, 0, 0);
glEnd();


glDisable(GL_TEXTURE_2D);
glPopMatrix();


glMatrixMode(GL_PROJECTION);
glPopMatrix();

glMatrixMode(GL_MODELVIEW);


glutSwapBuffers();
}

int main(int argc, char **argv)
{

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE/* | GLUT_DEPTH*/);
glutInitWindowSize(1024, 1024);
glutCreateWindow("texture copy test");
glutDisplayFunc(display);

glewInit();

render_texture();

glutMainLoop();
}


The debugger output



(gdb) run
Starting program: /home/rejak/projects/glwidgets/src/./test
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

ElectricFence Aborting: free(769110): address not from malloc().

Program received signal SIGILL, Illegal instruction.
0x00007ffff645c6c7 in kill () from /usr/lib/libc.so.6
(gdb) bt full
#0 0x00007ffff645c6c7 in kill () from /usr/lib/libc.so.6
No symbol table info available.
#1 0x00007ffff6ff14ad in ?? () from /usr/lib/libefence.so.0
No symbol table info available.
#2 0x00007ffff6ff18c7 in EF_Abortv () from /usr/lib/libefence.so.0
No symbol table info available.
#3 0x00007ffff6ff1968 in EF_Abort () from /usr/lib/libefence.so.0
No symbol table info available.
#4 0x00007ffff6ff0eda in free () from /usr/lib/libefence.so.0
No symbol table info available.
#5 0x00007ffff2a53e68 in _mesa_align_realloc () from /usr/lib/libdricore9.2.0.so.1
No symbol table info available.
#6 0x00007ffff2bced4c in _mesa_add_parameter () from /usr/lib/libdricore9.2.0.so.1
No symbol table info available.
#7 0x00007ffff2bceefa in _mesa_add_state_reference () from /usr/lib/libdricore9.2.0.so.1
No symbol table info available.
#8 0x00007ffff2fedb29 in ?? () from /usr/lib/xorg/modules/dri/i965_dri.so
No symbol table info available.
#9 0x00007ffff2bc4882 in _mesa_glsl_link_shader () from /usr/lib/libdricore9.2.0.so.1
No symbol table info available.
#10 0x00007ffff2a38c33 in _mesa_get_fixed_func_fragment_program () from /usr/lib/libdricore9.2.0.so.1
No symbol table info available.
#11 0x00007ffff2a86f68 in _mesa_update_state_locked () from /usr/lib/libdricore9.2.0.so.1
No symbol table info available.
#12 0x00007ffff2a87041 in _mesa_update_state () from /usr/lib/libdricore9.2.0.so.1
No symbol table info available.
#13 0x00007ffff2ac5a08 in ?? () from /usr/lib/libdricore9.2.0.so.1
No symbol table info available.
#14 0x000000000040167a in display () at test.cpp:78
No locals.
#15 0x00007ffff7720ac4 in ?? () from /usr/lib/libglut.so.3
No symbol table info available.
#16 0x00007ffff7724329 in fgEnumWindows () from /usr/lib/libglut.so.3
No symbol table info available.
#17 0x00007ffff772107d in glutMainLoopEvent () from /usr/lib/libglut.so.3
No symbol table info available.
#18 0x00007ffff772187d in glutMainLoop () from /usr/lib/libglut.so.3
No symbol table info available.
#19 0x00000000004017b3 in main (argc=1, argv=0x7fffffffe6e8) at test.cpp:110
No locals.


So it crashs at
glBegin(GL_QUADS); in the
void display(void) function