Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » crash in ex_prim

Credits go to Arthur Kalliokoski, Elias, and SiegeLord for helping out!
This thread is locked; no one can reply to it. rss feed Print
crash in ex_prim
Edgar Reynaldo
Member #8,592
May 2007
avatar

ex_prim crashes on my laptop with DirectX due to al_create_vertex_buffer failing due to _al_create_vertex_buffer_directx failing due to is_legacy_card() returning true.

It would be nice to at least get a warning, like "Your laptop's shitty integrated graphics card sucks. Fail, hoser."

I thought ex_prim was working for me before, so I hacked it to use OpenGL quick and it works again.

I'm running Windows Vista with an ATI Radeon X1270 integrated graphics card.

#SelectExpand
1 2c:\mingw\LIBS\A5GIT\allegro\build\examples>gdb ex_prim 3GNU gdb (GDB) 7.3 4Copyright (C) 2011 Free Software Foundation, Inc. 5License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 6This is free software: you are free to change and redistribute it. 7There is NO WARRANTY, to the extent permitted by law. Type "show copying" 8and "show warranty" for details. 9This GDB was configured as "mingw32". 10For bug reporting instructions, please see: 11<http://www.gnu.org/software/gdb/bugs/>... 12Reading symbols from c:\mingw\libs\a5git\allegro\build\examples\ex_prim.exe...done. 13(gdb) run 14Starting program: c:\mingw\libs\a5git\allegro\build\examples\ex_prim.exe 15[New Thread 4416.0x1158] 16BFD: C:\Windows\system32\atiumdva.dll: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .text 17BFD: C:\Windows\system32\atiumdva.dll: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .rdata 18BFD: C:\Windows\system32\atiumdva.dll: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .data 19[New Thread 4416.0xf2c] 20[New Thread 4416.0x12e0] 21[New Thread 4416.0x9f0] 22[New Thread 4416.0x1664] 23[New Thread 4416.0xd10] 24[New Thread 4416.0x16b8] 25[New Thread 4416.0x128c] 26[New Thread 4416.0x15e8] 27 28Program received signal SIGSEGV, Segmentation fault. 290x004f09e6 in al_lock_vertex_buffer (buffer=0x0, offset=0, length=13, flags=2) at C:\mingw\LIBS\A5GIT\allegro\addons\primitives\primitives.c:363 30363 if (offset + length > buffer->common.size) 31(gdb) bt 32#0 0x004f09e6 in al_lock_vertex_buffer (buffer=0x0, offset=0, length=13, flags=2) at C:\mingw\LIBS\A5GIT\allegro\addons\primitives\primitives.c:363 33#1 0x004045e0 in IndexedBuffers (mode=0) at C:\mingw\LIBS\A5GIT\allegro\examples\ex_prim.c:581 34#2 0x00404e86 in main (argc=1, argv=0x2719b8) at C:\mingw\LIBS\A5GIT\allegro\examples\ex_prim.c:762 35(gdb) p al_create_vertex_buffer(NULL , NULL , 13 , ALLEGRO_PRIM_BUFFER_STATIC) 36No symbol "NULL" in current context. 37(gdb) p al_create_vertex_buffer(0,0,13,ALLEGRO_PRIM_BUFFER_STATIC) 38$1 = (ALLEGRO_VERTEX_BUFFER *) 0x0 39(gdb) break primitives.c:230 40Breakpoint 1 at 0x4f0467: file C:\mingw\LIBS\A5GIT\allegro\addons\primitives\primitives.c, line 230. 41(gdb) run 42The program being debugged has been started already. 43Start it from the beginning? (y or n) y 44Starting program: c:\mingw\libs\a5git\allegro\build\examples\ex_prim.exe 45[New Thread 4812.0x1750] 46BFD: C:\Windows\system32\atiumdva.dll: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .text 47BFD: C:\Windows\system32\atiumdva.dll: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .rdata 48BFD: C:\Windows\system32\atiumdva.dll: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .data 49[New Thread 4812.0x10c0] 50[New Thread 4812.0xb18] 51[New Thread 4812.0x1724] 52[New Thread 4812.0x15ac] 53[New Thread 4812.0x15c0] 54[New Thread 4812.0x14c8] 55[New Thread 4812.0x13a8] 56 57Breakpoint 1, al_create_vertex_buffer (decl=0x0, initial_data=0x544040, num_vertices=13, flags=8) at C:\mingw\LIBS\A5GIT\allegro\addons\primitives\primitives.c:230 58230 ret = al_calloc(1, sizeof(ALLEGRO_VERTEX_BUFFER)); 59(gdb) next 60231 ret->common.size = num_vertices; 61(gdb) p ret 62$2 = (ALLEGRO_VERTEX_BUFFER *) 0x50a28b8 63(gdb) next 64232 ret->common.write_only = !(flags & ALLEGRO_PRIM_BUFFER_READWRITE); 65(gdb) 66233 ret->decl = decl; 67(gdb) 68240 if (display_flags & ALLEGRO_OPENGL) { 69(gdb) p display_flags & ALLEGRO_OPENGL 70$3 = 0 71(gdb) next 72244 else if (display_flags & ALLEGRO_DIRECT3D) { 73(gdb) p display_flags & ALLEGRO_DIRECT3D 74No symbol "ALLEGRO_DIRECT3D" in current context. 75(gdb) next 76245 if (_al_create_vertex_buffer_directx(ret, initial_data, num_vertices, flags)) 77(gdb) next 78252 al_free(ret); 79(gdb) p _al_create_vertex_buffer_directx(ret , initial_data , num_vertices , flags) 80$4 = false 81(gdb) break prim_directx.cpp:981 82Breakpoint 2 at 0x4f8e83: file C:\mingw\LIBS\A5GIT\allegro\addons\primitives\prim_directx.cpp, line 981. 83(gdb) run 84The program being debugged has been started already. 85Start it from the beginning? (y or n) y 86Starting program: c:\mingw\libs\a5git\allegro\build\examples\ex_prim.exe 87[New Thread 2376.0x16b0] 88BFD: C:\Windows\system32\atiumdva.dll: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .text 89BFD: C:\Windows\system32\atiumdva.dll: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .rdata 90BFD: C:\Windows\system32\atiumdva.dll: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .data 91[New Thread 2376.0xb0c] 92[New Thread 2376.0x1134] 93[New Thread 2376.0x1718] 94[New Thread 2376.0x132c] 95[New Thread 2376.0x138c] 96[New Thread 2376.0x11a8] 97[New Thread 2376.0xbf0] 98 99Breakpoint 1, al_create_vertex_buffer (decl=0x0, initial_data=0x544040, num_vertices=13, flags=8) at C:\mingw\LIBS\A5GIT\allegro\addons\primitives\primitives.c:230 100230 ret = al_calloc(1, sizeof(ALLEGRO_VERTEX_BUFFER)); 101(gdb) continue 102Continuing. 103 104Breakpoint 2, _al_create_vertex_buffer_directx (buf=0x5102818, initial_data=0x544040, num_vertices=13, flags=8) at C:\mingw\LIBS\A5GIT\allegro\addons\primitives\prim_directx.cpp:981 105981 if (is_legacy_card()) 106(gdb) p is_legacy_card() 107$5 = true 108(gdb)

Arthur Kalliokoski
Second in Command
February 2005
avatar

It would be nice to at least get a warning, like "Your laptop's shitty integrated graphics card sucks. Fail, hoser."

You realize that these sample programs were hacked together as examples of how to use the features, not to be shining examples of be-all-and-end-all with every loose end tied up user programs, right? If you don't like it, rewrite it and submit a patch.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Edgar Reynaldo
Member #8,592
May 2007
avatar

Well of course I don't expect every single line of code to be perfect. I'm just saying, I shouldn't have to debug ex_prim just to find out that some obscure function named is_legacy_card() is returning true on my laptop. If my laptop isn't good enough or doesn't support something there should be some way to tell, right?

Arthur Kalliokoski
Second in Command
February 2005
avatar

So fix it and send in a patch or the entire new ex_prim.c. Get your name in lights! I bet you could fix the lack of messages for minimizing and maximizing windows too. Just think how impressive it will be when people google your name and find out you've contributed to open source software! OTOH, you'd have to use your real name for that to work well.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Edgar Reynaldo
Member #8,592
May 2007
avatar

But my dear friend Arthur, "There's just no point".

Quote:

#SelectExpand
1 2bool _al_create_vertex_buffer_directx(ALLEGRO_VERTEX_BUFFER* buf, const void* initial_data, size_t num_vertices, int flags) 3{ 4#ifdef ALLEGRO_CFG_D3D 5 LPDIRECT3DDEVICE9 device; 6 IDirect3DVertexBuffer9* d3d_vbuff; 7 DWORD fvf = A5V_FVF; 8 int stride = buf->decl ? buf->decl->stride : (int)sizeof(ALLEGRO_VERTEX); 9 HRESULT res; 10 void* locked_memory; 11 12 /* There's just no point */
13 if (is_legacy_card())
14 return false;
15 16 device = al_get_d3d_device(al_get_current_display());

Edit :
Also, my point is not that ex_prim crashes, it is that al_create_vertex_buffer will never return true on my laptop and if I hadn't debugged it I would never know why. :P

Arthur Kalliokoski
Second in Command
February 2005
avatar

"There's just no point".

What? ex_dualies (?) returns an error if you don't have two monitors hooked up.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Edgar Reynaldo
Member #8,592
May 2007
avatar

I was quoting the comment from the _al_create_vertex_buffer_directx function where it says there is just no point to try with a 'legacy' card. Apparently my Pixel Shader version is too low or something from looking at is_legacy_card(). OpenGL can do it though?

Apparently this answers it :

prim_directx.cpp said:

/*
* In the context of this file, legacy cards pretty much refer to older Intel cards.
* They are distinguished by three misfeatures:
* 1. They don't support shaders
* 2. They don't support custom vertices
* 3. DrawIndexedPrimitiveUP is broken
*
* Since shaders are used 100% of the time, this means that for these cards
* the incoming vertices are first converted into the vertex type that these cards
* can handle.
*/

Arthur Kalliokoski
Second in Command
February 2005
avatar

I meant hack the main program to put up a error dialog box with the message "Your laptop's shitty integrated graphics card sucks. Fail, hoser." As for why OGL can do it, maybe the root cause of the problem is DX capability bits, sometimes two mutually exclusive abilities of a card can conflict with those bits.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Elias
Member #358
May 2000

So according to that comment, those legacy cards should still work in ex_prim, just have their vertex types converted?

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

SiegeLord
Member #7,827
October 2006
avatar

Elias said:

So according to that comment, those legacy cards should still work in ex_prim, just have their vertex types converted?

Yes. But conversion means that you have to download the vertex buffer data back to the host system, convert the vertices and send the new vertices to the GPU. Legacy cards don't support shaders, which means that in the second step you can't use vertex buffers... which means there just was no point in making a vertex buffer: they are meant to be an optimization and these workarounds make them worse than just using al_draw_prim directly.

ex_prim shouldn't crash though, that's an oversight.

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

Edgar Reynaldo
Member #8,592
May 2007
avatar

SiegeLord
Member #7,827
October 2006
avatar

Does that mean I can't run any shader code on my laptop? Or just directx shaders, since opengl seemed to implement it?

Primitives addon does not require OpenGL to implement shaders, as it is more flexible than D3D, so at least you'll be able to use the addon.

Now... in terms of shaders... I'm not sure. Seems unlikely for D3D, but maybe it's possible for OpenGL? Since you appear to have A5.1 installed, I'd just try and see if some of the shader examples (ex_shader, ex_prim_shader, ex_shader_multitex) run under OpenGL.

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

Edgar Reynaldo
Member #8,592
May 2007
avatar

(using 5.1.8) ex_prim_shader fails with this message :
{"name":"608234","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/d\/dd8149736548c0dc849d07c30f0c0eca.png","w":493,"h":253,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/d\/dd8149736548c0dc849d07c30f0c0eca"}608234
and then crashes.

ex_shader shows a dark red screen.

ex_shader_multitex flashes a window then I have to restore its real window and it shows a black screen.

ex_shader_target shows a black screen.

What are these supposed to do?

SiegeLord
Member #7,827
October 2006
avatar

What are these supposed to do?

Well, not that XD.

I meant to run them OpenGL (need to plop an allegro5.cfg file with [graphics] driver = opengl in the compiled examples directory).

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

Edgar Reynaldo
Member #8,592
May 2007
avatar

Ah, okay.

Using OpenGL :

ex_prim_shader ran properly and showed the light source following the mouse

ex_shader, ex_shader_multitex, and ex_shader_target all crash.

ex_shader backtrace :

#SelectExpand
1 2Program received signal SIGSEGV, Segmentation fault. 30x00000000 in ?? () 4(gdb) bt 5#0 0x00000000 in ?? () 6#1 0x677e032f in ogl_flush_vertex_cache (disp=0x286990) at C:\downloads\Programming\ProgrammingLibraries\Allegro\5pt1pt8\allegro\src\opengl\ogl_draw.c:366 7#2 0x677dd70a in draw_quad (bitmap=0x289d48, tint=..., sx=0, sy=0, sw=320, sh=200, flags=0) at C:\downloads\Programming\ProgrammingLibraries\Allegro\5pt1pt8\allegro\src\opengl\ogl_bitmap.c:277 8#3 0x677ddad4 in ogl_draw_bitmap_region (bitmap=0x289d48, tint=..., sx=0, sy=0, sw=320, sh=200, flags=0) at C:\downloads\Programming\ProgrammingLibraries\Allegro\5pt1pt8\allegro\src\opengl\ogl_bitmap.c:362 9#4 0x67702662 in _bitmap_drawer (bitmap=0x289d48, tint=..., sx=0, sy=0, sw=320, sh=200, flags=0) at C:\downloads\Programming\ProgrammingLibraries\Allegro\5pt1pt8\allegro\src\bitmap_draw.c:54 10#5 0x677029c2 in _draw_tinted_rotated_scaled_bitmap_region (bitmap=0x289d48, tint=..., cx=0, cy=0, angle=0, xscale=1, yscale=1, sx=0, sy=0, sw=320, sh=200, dx=0, dy=0, flags=0) at C:\downloads\Programming\ProgrammingLibraries\Allegro\5pt1pt8\allegro\src\bitmap_draw.c:116 11#6 0x67702a5e in al_draw_tinted_bitmap_region (bitmap=0x289d48, tint=..., sx=0, sy=0, sw=320, sh=200, dx=0, dy=0, flags=0) at C:\downloads\Programming\ProgrammingLibraries\Allegro\5pt1pt8\allegro\src\bitmap_draw.c:128 12#7 0x67702b30 in al_draw_tinted_bitmap (bitmap=0x289d48, tint=..., dx=0, dy=0, flags=0) at C:\downloads\Programming\ProgrammingLibraries\Allegro\5pt1pt8\allegro\src\bitmap_draw.c:139 13#8 0x67702b77 in al_draw_bitmap (bitmap=0x289d48, dx=0, dy=0, flags=0) at C:\downloads\Programming\ProgrammingLibraries\Allegro\5pt1pt8\allegro\src\bitmap_draw.c:148 14#9 0x00401936 in main (argc=1, argv=0x283790) at C:\downloads\Programming\ProgrammingLibraries\Allegro\5pt1pt8\allegro\examples\ex_shader.cpp:128 15(gdb)

ogl_draw.c:366 is :

         glGenVertexArrays(1, &o->vao);

ex_shader_multitex crashes in the same spot.

ex_shader_target crashes in the same spot, ogl_flush_vertex_cache.

Go to: