Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allegro 5 - Cannot Destroy Shader

This thread is locked; no one can reply to it. rss feed Print
Allegro 5 - Cannot Destroy Shader
DragonDePlatino
Member #16,608
December 2016

I don't understand...

#SelectExpand
1#include <allegro5/allegro5.h> 2#include <stdio.h> 3 4int main(void) { 5 al_init(); 6 al_create_display(1280, 720); 7 8 ALLEGRO_SHADER* shader = al_create_shader(ALLEGRO_SHADER_AUTO); 9 10 if (NULL == shader) { 11 printf("Failed to initialize shader."); 12 } 13 14 al_destroy_shader(shader); 15}

Call Stack:

#SelectExpand
1#0 0x4be280 hlsl_destroy_shader(shader=0xdf6890) (C:/dev/allegro_winpkg/universal/allegro/src/win/d3d_shader.cpp:319) 2#1 0x43962b al_destroy_shader(shader=0xdf6890) (C:/dev/allegro_winpkg/universal/allegro/src/shader.c:232) 3#2 0x405b6a main() (C:\Users\Platino\Documents\C\Crucis\src\main.c:32)

Why does this crash when I attempt to destroy the shader? I haven't even attempted to attach a source yet. I've read through the documentation here, looked at the examples here and checked my allegro.log for anything odd. This is frustrating beyond belief. >:(

Edgar Reynaldo
Member #8,592
May 2007
avatar

DragonDePlatino
Member #16,608
December 2016

Wow. Never used GDB before. Nor did I know that existed before you mentioned it.

#SelectExpand
1(gdb) bt full 2#0 0x00000000004be2d0 in hlsl_destroy_shader (shader=0x3f6850) 3 at C:/dev/allegro_winpkg/universal/allegro/src/win/d3d_shader.cpp:319 4 hlsl_shader = 0x3f6850 5 __func__ = "hlsl_destroy_shader" 6#1 0x000000000043967b in al_destroy_shader (shader=0x3f6850) 7 at C:/dev/allegro_winpkg/universal/allegro/src/shader.c:232 8 bmp = 0x26337b8 9 i = 0 10 __func__ = "al_destroy_shader" 11#2 0x0000000000405b6a in main () 12 at C:\Users\Platino\Documents\C\Crucis\src\main.c:35 13 shader = 0x3f6850

Is that what you're looking for? I'm using a static x64 version of Allegro 5.2.2.

SiegeLord
Member #7,827
October 2006
avatar

It looks like a bug in Allegro, the only way to avoid it (aside from not destroying the shader) is to actually add sources and build it.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

DragonDePlatino
Member #16,608
December 2016

#SelectExpand
1#include <allegro5/allegro5.h> 2#include <stdio.h> 3 4int main(void) { 5 al_init(); 6 al_create_display(1280, 720); 7 8 ALLEGRO_SHADER* shader = al_create_shader(ALLEGRO_SHADER_AUTO); 9 ALLEGRO_SHADER_PLATFORM platform = al_get_shader_platform(shader); 10 11 if (NULL == shader) { 12 puts("Failed to initialize shader.\n"); 13 } 14 15 FILE* test_file = fopen("share/test.glsl", "r"); 16 17 if (NULL == test_file) { 18 puts("Failed to find GLSL shader."); 19 exit(1); 20 } 21 22 fclose(test_file); 23 test_file = fopen("share/test.hlsl", "r"); 24 25 if (NULL == test_file) { 26 puts("Failed to find HLSL shader."); 27 exit(1); 28 } 29 30 fclose(test_file); 31 32 bool success = false; 33 if (platform == ALLEGRO_SHADER_GLSL) { 34 success = al_attach_shader_source_file(shader, ALLEGRO_PIXEL_SHADER, "share/test.glsl"); 35 } else if (platform == ALLEGRO_SHADER_HLSL) { 36 success = al_attach_shader_source_file(shader, ALLEGRO_PIXEL_SHADER, "share/test.hlsl"); 37 } else { 38 puts("Failed to identify shader platform.\n"); 39 exit(1); 40 } 41 42 if (!success) { 43 puts("Failed to attach shader source.\n"); 44 exit(1); 45 } 46 47 al_build_shader(shader); 48 al_destroy_shader(shader); 49 al_uninstall_system(); 50}

When I run this, it creates the shader and correctly finds both of the shader files with fopen(). The platform is identified as ALLEGRO_SHADER_HLSL and line 36 is run. My console then prints "Failed to attach shader source." I don't know how to write HLSL shaders yet so I used ex_prim_shader_pixel.glsl and ex_prim_shader_pixel.hlsl from here. This is the GDB output:

#SelectExpand
1(gdb) run 2Starting program: C:\Users\Platino\Documents\C\Crucis\bin-debug\crucis.exe 3[New Thread 3644.0x1884] 4[New Thread 3644.0xfc4] 5[New Thread 3644.0x1b20] 6[New Thread 3644.0x18cc] 7[New Thread 3644.0xf1c] 8[New Thread 3644.0x1638] 9Failed to attach shader source. 10 11 12Program received signal SIGSEGV, Segmentation fault. 130x00000000004be240 in hlsl_destroy_shader (shader=0x1236850) 14 at C:/dev/allegro_winpkg/universal/allegro/src/win/d3d_shader.cpp:319 15319 C:/dev/allegro_winpkg/universal/allegro/src/win/d3d_shader.cpp: No such 16file or directory. 17(gdb) bt full 18#0 0x00000000004be240 in hlsl_destroy_shader (shader=0x1236850) 19 at C:/dev/allegro_winpkg/universal/allegro/src/win/d3d_shader.cpp:319 20 hlsl_shader = 0x1236850 21 __func__ = "hlsl_destroy_shader" 22#1 0x00000000004395eb in al_destroy_shader (shader=0x1236850) 23 at C:/dev/allegro_winpkg/universal/allegro/src/shader.c:232 24 bmp = 0x3137b8 25 i = 0 26 __func__ = "al_destroy_shader" 27#2 0x00000000004314c2 in _al_run_destructors (dtors=0x1234520) 28 at C:/dev/allegro_winpkg/universal/allegro/src/dtor.c:120 29 dtor = 0x31db60 30 object = 0x1236850 31 func = 0x4393fd <al_destroy_shader> 32 iter = 0x31dbb0 33 __func__ = "_al_run_destructors" 34#3 0x000000000043a464 in al_uninstall_system () 35 at C:/dev/allegro_winpkg/universal/allegro/src/system.c:311 36 __func__ = "al_uninstall_system" 37#4 0x00007ffe46fe6e1f in msvcrt!_flushall () 38 from C:\Windows\system32\msvcrt.dll 39No symbol table info available. 40#5 0x0000000000405c6e in main () 41 at C:\Users\Platino\Documents\C\Crucis\src\main.c:44

SiegeLord
Member #7,827
October 2006
avatar

The destructor crash is fixed on the master branch, but that's unrelated to your issues with attaching the source. Could you try seeing if al_get_shader_log returns anything?

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

DragonDePlatino
Member #16,608
December 2016

If I use the example shader I found here then print al_get_shader_log after attaching the source, I get the following error:

#SelectExpand
1C:\Users\Platino\Documents\C\Crucis\memory(11,16): error X3000: unrecognized ide 2ntifier 'VS_OUTPUT' 3Failed to attach shader source.

If I use the following pixel shader I found here...

#SelectExpand
1float4 PixelShaderFunction() : COLOR0 2{ 3 return float4(1, 0, 0, 1); 4}

...then it successfully attaches, builds, then destroys. Finally! I haven't learned HLSL so I don't understand what VS_OUTPUT is. In the past, I used SFML which defaulted to GLSL. Is there any reason why allegro is forcing me to use HLSL? Would I get a performance penalty if I switched to GLSL? Is that even possible on Windows 8.1? Would it be portable?

On another note, could there please be an allegro error to reflect this quirk with shaders? It would be nice if you got a printout like "Cannot destroy a shader without attaching source." when you attempt doing so. It would've saved me several days and a lot of frustration getting this to work. The shader was going to be for something very minor, anyways. :(

SiegeLord
Member #7,827
October 2006
avatar

Oh, VS_OUTPUT is defined in the vertex shader, I guess you had to attach both for it to work.

You can use GLSL too if you want, there is a tiny performance penalty but nothing that should prevent you from using it. Do this by adding al_set_new_display_flags(ALLEGRO_OPENGL) before creating the display.

As for destroying the shaders, your original code will work in the next release without the crash.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Elias
Member #358
May 2000

Also, if you want your game to ever work anywhere besides Windows, you will want GLSL anyway :)

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

DragonDePlatino
Member #16,608
December 2016

Ah, I see. In that case, I'll switch to OpenGL and use that for all platforms. Thanks for helping me!

Go to: