Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » "filled" primitives crashing

This thread is locked; no one can reply to it. rss feed Print
"filled" primitives crashing
roger levy
Member #2,513
July 2002

this is very mysterious...

al_draw_filled_ellipse and al_draw_filled_rectangle seem to crash the program,
al_draw_ellipse and al_draw_rectangle don't

i'm on 5.1.11

edit: actually they all seem to be crashing ... all i can do is al_draw_pixel

Mark Oates
Member #1,146
March 2001
avatar

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

roger levy
Member #2,513
July 2002

i think i'm doing that, but i'll investigate more tomorrow.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

roger levy
Member #2,513
July 2002

I'm drawing to a bitmap.

The most bizarre part about this is it seems to be sensitive to surrounding code. All I am able to get to run is al_draw_rectangle and only at the prompt (I'm using Forth) and if I use any flow control structures or call any other functions after calling al_draw_rectangle it does an access violation. This leads me to believe it could have something to do with the compiler.

Just tried downgrading to 5.1.9 but no difference. Using allegro_monolith-5.1.dll.

Edit: Could have something to do with how those functions use the stack. Going to try expanding the FFI's call stack size in the compiler.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

This will probably be vague and unhelpful, but it sounds like you're stomping on memory somewhere. Look for overruns and dangling pointers is all I can suggest.

Because the only way a primitive should crash is if the drawing target is NULL or the addon hasn't been initialized yet.

roger levy
Member #2,513
July 2002

It's definitely not a lack of init or drawing to null, just ensured that by inserting the appropriate stuff right before the draw call.

I was able to get things to work, although in a very wonky and unpredictable way, by modifying the stack pointer before and after calling al_draw_rectangle. The function seems to be sensitive to the exact value of the stack pointer before it is called, which leads me to think that these functions somehow depend on alignment rather than available stack space (which shouldn't be the problem since I confirmed that SwiftForth uses the system stack).

I am not sure about any memory clobbering ... I tried calling the primitive functions without any game code loaded and had the same issues.

EDIT: Just did a little experiment and confirmed that al_draw_rectangle requires 16-byte alignment of the stack pointer to run. For the curious, here's what the test code looks like:

variable (rp)
: al_draw_rectangle
  rp@ dup (rp) !  $10 - $fffffff0 and 4 + rp!   \ add 4 because the call itself subtracts 4.
  al_draw_rectangle
  (rp) @ rp! ;


%actor ~> %pea
  :: draw
    pos xy 6.0 -1.0 2+ at
    1.0 1.0 1.0 1.0 pcolor
    \ 3 circle
    \ al_init_primitives_addon
    \ buf0 al_set_target_bitmap
    \ cr rp@ h.
    \ 3 >r 3 >r 3 >r
    \ 3 >r 3 >r 3 >r
    \ rp@ h.
    xy> 3 3 2coords color> thickness> al_draw_rectangle
    \ 3 3 rectangle
    \ r> r> r> 3drop
    \ r> r> r> 3drop
    \ pixel
    \ 1 1 +at pixel
    \ -1 1 +at pixel
    \ -1 -1 +at pixel
    pos x 1i res x > if  me delete  then ;
endp

I attached a screenshot :) Note that the issue is technically not solved only worked around; this seems like non-standard behavior for a DLL.

Go to: