Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » What does al_get_target_bitmap() return?

Credits go to ph03nix and Schyfis for helping out!
This thread is locked; no one can reply to it. rss feed Print
What does al_get_target_bitmap() return?
AmnesiA
Member #15,195
June 2013
avatar

I'm trying to debug an object that for some reason will not draw a background to my display like it's supposed to. To debug I'm running through the program "wathcing" al_get_target_bitmap() to make sure that the correct bitmap is being drawn to. The only issue is that I expected it to store a memory address that I could cross reference with the addresses that each bitmap was stored to (since they are both functions of the ALLEGRO_BITMAP* type) but instead it returns an integer.

For example, when the targeted bitmap is al_get_backbuffer(display) the integer shows up as (for this run-through) 8666204 and when the targeted bitmap is canvas (declared as ALLEGRO_BITMAP* in one of my objects) the integer shows up as 62219096. There doesn't seem to me to be a way to see how this translates to addresses or the bitmap itself. I tried to dereference the number with a * beforehand but then the watch just shows a different integer and if I do an address-of (&) it says "Attempt to take address of value not located in memory"

tl;dr how do I make al_get_target_bitmap() show which bitmap is being targeted the same way that ALLEGRO_BITMAP* canvas shows its value as 0x3b56470

EDIT: I forgot to mention, I also tried dereferencing the ALLEGRO_BITMAP* variables but that just gives me <incomplete type>

=======================
Website
My first game!

Schyfis
Member #9,752
May 2008
avatar

Took me forever to find it, but it's defined as follows:

ALLEGRO_BITMAP *al_get_target_bitmap(void)
{
   thread_local_state *tls;

   if ((tls = tls_get()) == NULL)
      return 0;
   return tls->target_bitmap;
}

And boiled down, all al_set_target_bitmap is doing is setting tls->target_bitmap.

tls->target_bitmap = bitmap;

As far as I can tell, al_get_target_bitmap just returns an ALLEGRO_BITMAP*, doesn't look like any magic is happening here... at least not to me. Maybe someone else knows a bit more about watching ALLEGRO_BITMAP*s?

________________________________________________________________________________________________________
[freedwill.us]
[unTied Games]

ph03nix
Member #15,028
April 2013
avatar

That integer you're printing is the memory address, just in decimal instead of hex.

for example:
6221909610 = 3B5635816

Just set the watch's output to decimal, or print the memory address in hex (use google for this)

AmnesiA
Member #15,195
June 2013
avatar

Ohhh wow, that's so simple, I'm such a pleb. Thank you so much!

=======================
Website
My first game!

Go to: