Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » SIGSEGV when attaching shaders

This thread is locked; no one can reply to it. rss feed Print
SIGSEGV when attaching shaders
brisingr123
Member #15,673
July 2014

Hello everyone. I've recently started using Allegro, and was initially started out with Allegro 5.0.10. However, I needed shaders for my game, so I decided to port over to 5.1.8. I downloaded the windows binaries that someone in this forum had made for the same, and somewhat clumsily replaced the old header and lib files, although I'm not entirely sure I did it the right way. One way or the other I got the library working and functions like al_get_shader_source that were earlier not working now worked. However, now I've run into a strange problem.

    ALLEGRO_SHADER* shader = al_create_shader(ALLEGRO_SHADER_GLSL);
    if(shader == NULL)
    {
        MessageBox(NULL, "Could not create shader!", "Error!", MB_OK | MB_ICONERROR);
        return 0;
    }
    if (!al_attach_shader_source(shader, ALLEGRO_VERTEX_SHADER, "Assets\\shaders\\tempVert.vert"))
        std::cout << al_get_shader_log(shader);

When I try attaching a shader, the program gives me a SIGSEGV (segmentation fault). Not sure where I'm wrong, so any help would be appreciated.

Slartibartfast
Member #8,789
June 2007
avatar

al_attach_shader_source expects the source code for the shader, not a path to the shader.
The function you were thinking of is al_attach_shader_source_file.

brisingr123
Member #15,673
July 2014

Oh sorry, I got my source messed up.

Actually, I've tried al_attach_shader_source_file, as well as later changed it to al_attach_shader_source while providing the shader code in the program itself, but it crashed either way. So I undo-ed the change, but I guess I didn't undo it completely. So I'm pretty sure the problem is not with not being able to find the file or incorrect shader code - one way or the other, that would generate an error log, not crash my program with segsev.

EDIT : Could not linking to the correct libs (or linking only to some, and not all libs) result in this kind of a thing? I ask coz when I ported from 5.0.10 to 5.1.8, I didn't exactly link to all the lib files - I only linked to those that were present in 5.0.10. Is it possible that the 2 or 3 files that I failed to link to are causing this problem?

Slartibartfast
Member #8,789
June 2007
avatar

Are you sure the crash is in al_attach_shader_source and not later on as a result of it failing when something expected it to have succeeded is called?
Either way it is a good idea to use a debugger to catch the exception, preferably when linking against a version of allegro with debug symbols so you can see exactly what goes wrong.

Is it possible that the 2 or 3 files that I failed to link to are causing this problem?

Not linking to something that is required will cause a linking error, not a runtime error, however if you linked against one library but another got loaded in its place (because they share the same name and one being in a place that puts it in a higher precedence than the other) it could cause all sorts of havoc. Also, if you linked against libraries of both 5.0.10 and 5.1.8 at the same time I don't know what would happen. Are you linking statically or dynamically?

brisingr123
Member #15,673
July 2014

Yup, pretty sure the crash is in attach_shader, since I set a breakpoint at that particular line, the program ran fine till then, but if I pressed "next line" it never went ahead, just gave a sigsev and crashed.

And well, I didn't make the libs myself (as I said, downloaded them from this forum) so not sure if they are debug, but they work well enough. I replaced all the old 5.0.10 libs with the new 5.1.8 ones, so I'm only linking to one of them (new one).

And lastly, static linking it is.

EDIT : https://www.allegro.cc/forums/thread/613773/995477#target
This was from where I downloaded the binaries. I replaced the old includes, and replaced the old allegro libs with the ones given here (for instance, replaced liballegro_acodec-5.0.10-static-mt.a with liballegro_acodec-static.a . However, liballegro_main-static.a, liballegro_video-static.a and libtheora.a have not been linked, since they were not present in 5.0.10, and I wasn't sure of the order of linking these libs.

EDIT 2 : Okay, so I cleaned the entire allegro installation and placed the files again, linked to ALL the files, but still the same problem. The program directly crashed with a sigsev - I can't even use al_get_shader_log() to get the error. Maybe I'm doing something wrong in my code... care to take a look?

#SelectExpand
1if(!al_init()) 2 { 3 MessageBox(NULL, "Could not initialize Allegro!", "Error!", MB_OK | MB_ICONERROR); 4 return false; 5 } 6 7 al_set_new_display_flags((IS_FULLSCREEN? ALLEGRO_FULLSCREEN: ALLEGRO_WINDOWED) | ALLEGRO_OPENGL_3_0); 8 al_set_new_window_position(683 - SCREEN_WIDTH/2, 384 - SCREEN_HEIGHT/2); 9 10 GAME_DISPLAY = al_create_display(SCREEN_WIDTH, SCREEN_HEIGHT); 11 if(GAME_DISPLAY == NULL) 12 { 13 MessageBox(NULL, "Could not create screen for display!", "Error!", MB_OK | MB_ICONERROR); 14 return 0; 15 } 16 17 al_init_image_addon(); 18 al_init_font_addon(); 19 al_init_ttf_addon(); 20 al_install_keyboard(); 21 al_install_mouse(); 22 23 ALLEGRO_BITMAP* icon = NAMESPACE::LoadImageFromFile("Assets\\icon.png"); 24 al_set_display_icon(GAME_DISPLAY, icon); 25 al_destroy_bitmap(icon); 26 27 NAMESPACE::ShowLoadingScreen(); 28 29 LoadAssets(); 30 31 srand(time(NULL)); 32 33 ALLEGRO_SHADER* shader = al_create_shader(ALLEGRO_SHADER_GLSL); 34 if(shader == NULL) 35 { 36 MessageBox(NULL, "Could not create shaders!", "Error!", MB_OK | MB_ICONERROR); 37 return 0; 38 } 39 if (!al_attach_shader_source_file(shader, ALLEGRO_VERTEX_SHADER, "Assets\\shaders\\tempVert.vert")) 40 std::cout << al_get_shader_log(shader); 41 if (!al_attach_shader_source_file(shader, ALLEGRO_PIXEL_SHADER, "Assets\\shaders\\tempFrag.frag")) 42 std::cout << al_get_shader_log(shader); 43 al_build_shader(shader); 44 al_use_shader(shader);

Slartibartfast
Member #8,789
June 2007
avatar

I'm not sure if that's the issue, but the al_set_new_display_flags[1] documentation states you need to set ALLEGRO_PROGRAMMABLE_PIPELINE if you want to use ALLEGRO_SHADER objects, so that may be it.

References

  1. note that clicking that link will bring you to 5.0 documentation and not 5.1, you should look at [2] for that.
brisingr123
Member #15,673
July 2014

Well, I did try the ALLEGRO_PROGRAMMABLE_PIPELINE flag initially, but the "al_set_display_icon(GAME_DISPLAY, icon);" line throws a SIGSEV in that case, and I don't even reach the shader part.

EDIT : Okay, to test the theory I moved the shader code between the icon part and the create display part. Still the error.

EDIT 2 : Okay, so I tried an allegro example (ex_shader.cpp), and was surprised to find that al_create_shader(ALLEGRO_SHADER_AUTO) gives me a ALLEGRO_SHADER_HLSL shader instead of ALLEGRO_SHADER_GLSL, and replacing ALLEGRO_SHADER_AUTO with ALLEGRO_SHADER_GLSL actually causes the program to crash. Why this surprises me is because I have set the ALLEGRO_OPENGL_3_0 flag. So, is there any way to force the creation of OpenGL display (I really don't want to be creating 2 shaders - one glsl, and one hlsl), and also, what's the method to check if my display is opengl or directX based?

EDIT 3 : Holy shit, I just figured out the problem - ALLEGRO_OPENGL_3_0 flag is shit! ALLEGRO_OPENGL works like a charm, and I get no more errors.

Not sure why that is, but either way, I'm good to go for now :D

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Go to: