Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » al_get_opengl_proc_address failed

This thread is locked; no one can reply to it. rss feed Print
al_get_opengl_proc_address failed
RmBeer2
Member #16,660
April 2017
avatar

I was thinking of posting the error on github, but unfortunately it is not possible, my current email was hijacked and when trying a new email, github blocks it. Anyway.

Have a error from al_get_opengl_proc_address(), give wrongs pointers and get a segfault in the L28.

TESTCASE:

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_image.h> 4 5int main(){ 6 int err,i,CICLO=1,redraw=0; 7 //Prepara ALLEGRO 8 ALLEGRO_DISPLAY*dsp; 9 ALLEGRO_EVENT event; 10 ALLEGRO_EVENT_QUEUE*queue; 11 12 //Inicializa Allegro 13 if(!al_init()){printf("Fallo AL_INIT\n");return -1;} 14 al_install_mouse(); 15 al_install_keyboard(); 16 //al_init_image_addon(); 17 //al_set_new_display_flags(ALLEGRO_OPENGL_ES_PROFILE); 18 dsp=al_create_display(640,480); 19 if(!dsp){printf("Fallo creando display\n");return -1;} 20 al_set_window_title(dsp,"HAPPY VIDEO"); 21 //timer=al_create_timer(1/60); 22 queue=al_create_event_queue(); 23 al_register_event_source(queue,al_get_keyboard_event_source()); 24 //al_register_event_source(queue,al_get_display_event_source(dsp)); 25 26 void*f=al_get_opengl_proc_address("glGetString"); 27 printf("PROC ADDRESS: %p\n",f); 28 const char *version_string = ((const char*(*)(int))f)(0x1F02); 29 printf("PROC ADDRESS: %s\n",version_string); 30 return 0; 31}

Line compiling: gcc pru.c -o pru -lallegro -g

RESULT:
PROC ADDRESS: 0xfffffffff4f535e0
(SIGSEGV in 0xfffffffff4f535e0)

I also trying with a TESTCASE for SDL:

#SelectExpand
1#include <stddef.h> 2#include <stdio.h> 3#include <stdlib.h> 4 5#include <SDL.h> 6 7int main(int argc, char *argv[]) 8{ 9 10 // Jesus Christ SDL, you suck! 11 SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "no"); 12 13 if (SDL_Init(SDL_INIT_VIDEO) < 0){ 14 printf("SDL init failed\n");return -1;} 15 16 SDL_Window *window = 17 SDL_CreateWindow("hi", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 18 1000, 500, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | 19 SDL_WINDOW_RESIZABLE); 20 if (!window){ 21 printf("failed to create SDL window\n");return -1;} 22 23 SDL_GLContext glcontext = SDL_GL_CreateContext(window); 24 if (!glcontext){ 25 printf("failed to create SDL GL context\n");return -1;} 26 27 void*f=SDL_GL_GetProcAddress("glGetString"); 28 printf("PROC ADDRESS: %p\n",f); 29 const char *version_string = ((const char*(*)(int))f)(0x1F02); 30 printf("PROC ADDRESS: %s\n",version_string); 31 32 printf("properly terminated\n"); 33 return 0; 34}

Line Compiling: gcc -o main main.c `pkg-config --libs --cflags mpv sdl2` -std=c99

RESULT:
PROC ADDRESS: 0x7fafcd76b5e0
PROC ADDRESS: 3.0 Mesa 19.3.4
properly terminated

-------------------------------------------------------------

This is my first serious fault discovered in Allegro 5...

🌈🌈🌈 🌟 Web of BlackRook 🌟 YouTube 🌟 🌈🌈🌈

Rm Beer for President 2020!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Bah humbug. This is not a bug in Allegro. You didn't request ALLEGRO_OPENGL, so you were using D3D. Which means al_get_opengl_proc_address will fail spectacularly.

Well, at least if you were on Windows that code would fail.

On Linux, it should work.

gusnan
Member #11,822
April 2010

Is this with Allegro from distribution package, or compiled from source?

RmBeer2
Member #16,660
April 2017
avatar

@Edgar

It fails the same anyway, I have already tried all the context variants for OpenGL.

@gusnan

For both. (From the system and from the source code)

🌈🌈🌈 🌟 Web of BlackRook 🌟 YouTube 🌟 🌈🌈🌈

Rm Beer for President 2020!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

glGetString is OpenGL 2.0. It will fail if your drivers aren't recent enough. But you say you're using Mesa?

What platform are you on that fails? What version of Allegro are you using? What version are your MesaGL drivers?

RmBeer2
Member #16,660
April 2017
avatar

this is the first like that i use: al_set_new_display_flags(ALLEGRO_OPENGL);
(in the comment line)

Yes, i use mesa.
Allegro from the system and from the source code in both sides, all updated in less of 1 day.
Also for the Archlinux system is updated in less of 3 days.

Archlinux Kernel: Linux 5.5.3-arch1-1 #1 SMP PREEMPT Tue, 11 Feb 2020 15:35:41 +0000 x86_64 GNU/Linux
mesa 19.3.4-2

EDIT:
mesa 19.3.4-2 is only get from testing... i unknown what patches're applied...
But it doesn't matter, since in the SDL testcase it works.

🌈🌈🌈 🌟 Web of BlackRook 🌟 YouTube 🌟 🌈🌈🌈

Rm Beer for President 2020!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Rmbeer2, post the solution. You were incorrectly casting as a different type of function signature, were you not?

Elias
Member #358
May 2000

Just add #include <allegro5/allegro_opengl.h> and it will work.

Also, never compile without warnings, that would have easily avoided that mistake.

--
"Either help out or stop whining" - Evert

RmBeer2
Member #16,660
April 2017
avatar

SOLUTION: Read the complete documentation and add this line:

#include <allegro5/allegro_opengl.h>

::)

🌈🌈🌈 🌟 Web of BlackRook 🌟 YouTube 🌟 🌈🌈🌈

Rm Beer for President 2020!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

RmBeer2
Member #16,660
April 2017
avatar

No, I don't think so, when I added that line of #include everything worked fine and without warnings.

🌈🌈🌈 🌟 Web of BlackRook 🌟 YouTube 🌟 🌈🌈🌈

Rm Beer for President 2020!

Elias
Member #358
May 2000

From what I read of your conversation on IRC, you incorrectly cast a function pointer as well.

Well, the effect of forgetting the #include means the compiler (after displaying a big warning) just assumes all undefined functions return int and so essentially the 64-bit function pointer got cast to a 32-bit int.

--
"Either help out or stop whining" - Evert

Go to: