I put a bitmap pointer into this class
Then, in the constructor to initialize it
use it in following function
but,when i destory it in destructor function,
skyGUIEditBox::~skyGUIEditBox(){ if(m_bg){ al_destroy_bitmap(m_bg); } ClearCookie(); m_fnt=0; }
The following error occurred:
"Unhandled exception: 0xC0000005: read location 0x00000000 when an access violation occurs in the 0x645c4b16 at 地图编辑器.exe "

That's easy. The reason this is happening is because it's destroying the bitmap after allegro has killed itself. At least that's what I think is happening. Something is making those bitmap pointers invalid.
I had this happen when I was first starting out too. My solution evolved to "KillAllegro()" and to careful destruction of the bitmaps so they precede the end of main().
Basically, do not destroy bitmaps in the destructor of a class. Ideally, create all your images through the same routine and store a list of pointers to them. When the application terminates, destroy them one by one.
Something (hacked together some code for you):
If I read what you wrote wrong, I'm sorry. I have to go to bed now.
.
I find it's generally not a good idea to put stuff related to Allegro into pointer destructors, since if Allegro shuts down before such a struct/class is destroyed then any calls to most Allegro functions will cause crashes.
When it comes to bitmaps, what I like to do is load all of my bitmaps into global pointer arrays, then simply copy those pointers into my class/struct objects. When I shut down my program I simply destroy the bitmaps in their global arrays before closing out Allegro, thus meaning I can just completely ignore the outdated pointers in my class/struct objects.
If you absolutely must load your bitmaps directly into your objects, (which is still a bad idea for other reasons, such as being a waste of memory if multiple objects load up identical bitmaps, or being difficult to reload if display conditions change), then what you can do is make sure all such objects are declared explicitly:
skyGUIEditBox *SGUIEB = new skyGUIEditBox;
Then, BEFORE you shut down Allegro at the end of your program:
delete SGUIEB;
Ideally though, you should load your bitmaps separate from your objects into a global array and simply copy the existing bitmap pointers into your objects. It'll save you a lot of trouble in the long run.
Thank you fo your answer.
I had the same problem recently.
Instead of destroying the bitmaps in a destructor, I simply made a function which I called right before return 0; in main.
Something like fallelight12 wrote, but simpler:
Not a perfect example, but you get the idea
I think it would be best to wrap Allegro in a C++ class to make it work better with automatic destruction. You could use unique_ptr, but I think a real wrapper may work better.