For my hack entry I decided to expand my wrapper library's asset manager with color management so that I could register a color by name and easily access it later on throughout the application (where it has access to assets).
Alas, I'm having a strange situation where the color being created does not appear to be initialized correctly. This has blocked me for a couple of days now. I'm not sure if the way I'm using Allegro is wrong, or if my type management is incorrect, or if this is somehow a bug in my build of Allegro.
Note: I'm casting between int and unsigned char, knowing the values should fit within an unsigned char, and assuming that the appropriate conversion will be applied by the C++ compiler. Even though I'm confident that this is fine, this feels like my most likely explanation for the flakiness if only because it's the only thing I can think of. 
Outputs things like this:
LIBAL5POLY DEBUG: {"r": 114, "g": 63, "b": 32, "a": 255} <=> {"r": 0, "g": 0, "b": 0, "a": 0}
Which makes it appear like the color object I just created is uninitialized/zeroed. And that appears to be correct too because when drawn the color is invisible regardless of background color (so the alpha=0 appears to be true at least). Any ideas what I'm doing wrong or ways to figure it out? Cookies for constructive posts that lead up to a solution. 
(I'm banned from the IRC channel ATM so I can't ask there...
)
I think you need to initialize Allegro and create a display before you call those functions, are you doing that?
Yes I am. This is only happening after Allegro has been initialized and a display created (and all errors should be handled).
Do you have a compileable and runnable testcase?
The only way al_map_rgb* fails is if al_init hasn't been run yet. Check again. Check for globals / singletons / etc....
EDIT
IF I have to give you the globals talk, I'm never gonna let you get over it.

EDIT2
static char buffers? Oh boy, you're gonna get it. NOT THREAD SAFE.
I'm pretty sure Edgar's got it:
The only way al_map_rgb* fails is if al_init hasn't been run yet.
This looks most likely to me; if I make a test prog with your code and run it without al_init, I get exactly the (0,0,0,0) result that you do. Try printing the result of al_is_system_installed in your LIBAL5POLY DEBUG: print-out.
I bet you're calling AssetManager::createColor from a global or static initializer.
IF I have to give you the globals talk, I'm never gonna let you get over it.
State that exists globally (i.e,. throughout the lifetime of the application) is OK. State that is globally readable and writeable is not though.
A closed static makes good sense here I think.
static char buffers? Oh boy, you're gonna get it. NOT THREAD SAFE.
Good feedback.
I appreciate that. What do I need to make that thread-safe? static thread_local char[50]?
What's the "correct" way? Perhaps I could try to implement a library buffer that can be used for various things.
I attempted once to implement a ring buffer[1] and apparently failed. I want to remedy that some day too.
So I guess I'd need at least two buffer implementations.
Do you have a compileable and runnable testcase?
https://github.com/bambams/al5poly-color-test
git clone --recursive git://github.com/bambams/al5poly-color-test.git && make -C al5poly-color-test run
Note: it references my library, which will contain the bulk of code, and obviously you wouldn't want to go through all of it... But I think it shouldn't be hard to track down where we call al_init(), and verify that it is all setup before we call al_map_rgba().
It's important to note that calling al_map_rgba() works fine. It's using my library's helper method that fails. There's no bug in Allegro. I just can't figure out the bug in my own code.
std::string AssetManager::printColor(ALLEGRO_COLOR color) { char buffer[50]; unsigned char red, green, blue, alpha; al_unmap_rgba(color, &red, &green, &blue, &alpha); snprintf(buffer, 50, "{\"r\": %d, \"g\": %d, \"b\": %d, \"a\": %d}", (int)red, (int)green, (int)blue, (int)alpha); return std::string(buffer); }
would be thread-safe, obviously you'd have to change the places where you'd used it and c_str() or whatever.
BTW I tried your example code from github and everything seemed to work OK. So that is weird.
...would be thread-safe, obviously you'd have to change the places where you'd used it and c_str() or whatever.
Yes, that's an easy way to make it thread-safe, but then it has the added cost of allocating the string and copying the buffer into it... Which I was trying to avoid just because it should be relatively simple... But I guess C++ over-complicates matters.
E.g., https://devblogs.microsoft.com/oldnewthing/20040308-00/?p=40363.
Apparently initialization of the static local is guaranteed thread-safe since C++0x, but that's all. It still sounds like adding thread_local to it will make it per-thread, which by definition should be thread safe, I guess? Which I guess is still a reasonable solution here instead of returning the copy, assuming it compiles OK.
BTW I tried your example code from github and everything seemed to work OK. So that is weird.
Good to know. So perhaps I'm using Allegro properly, and there's a bug with the binaries? Did you test on MinGW/Windows or some other platform?
Edgar, fixit fixit fixit?
Any ideas what I can do to narrow down the cause?
Edgar, fixit fixit fixit?
Any ideas what I can do to narrow down the cause?
If your color manager is a singleton, and it's constructed outside of main, that would explain it. You may not believe it but you're calling al_map_rgb before al_init otherwise it would work.
No, I have very minimal global state. The only reason the char buffer is global is because it's still local to that function, making its storage global, but it's access through the language is very narrow. 
And apparently the code worked fine with Peter's environment. Which suggests that maybe the bug isn't in my code after all.
bambams - your example code looks fine. It doesn't work for you? Which binaries are you using (I have several versions), the ones from Bitbucket (whose upload is broken btw) or Github (Allegro 5.2.6x from GIT)?
I can't remember where I downloaded them from. 
6ba400e3ecbf3bc7f468a2f65ffc0f9d540233c9 *Allegro525_GCC81_MinGW_W64_i686_posix_dwarf.7z
Append:
Maybe from BitBucket?
Yes, those are the ones from bitbucket. I have a newer version on github released with eagle.
Get it here :
https://github.com/EdgarReynaldo/EagleGUI/releases
0pt8pt1 is a monolith download.
0pt8pt0 has a separate download for Allegro 526x that and its deps.
EDIT
Try this code :
The updated library appears to work now.
I'm getting a correct brown circle. You might want to pull those 525 binaries down since there appears to be some kind of bug in them (and leave a notice redirecting to latest or something).
I tested the simple code I posted above with both 525 from bitbucket and 526x from github. Both work equally well. I don't think there is a bug in the binaries.
Your makefile is quite complicated, I wonder if maybe at some point it was rebuilding with a stale version of something or other? (vague, I know
)
Yeah, but it's pretty easy to see that I'm also initializing Allegro before I'm creating my color:
https://github.com/bambams/al5poly-color-test/blob/main/src/main.cpp#L26
(Note: these *_Ptr types are just boost::shared_ptr<T> typedefs)
I need to look more into this. It may well be that the build is fine, but I cannot yet see the bug in my code.
The color test program appears to still be failing with the 526 binaries though.
Bambams it could be ABI related if you have old 5.2 dlls laying around on the path somewhere. Did you compile statically or dynamically?