Question regarding multithreading
I have never worked with multi-threading before (started learning about it a few days ago). it looked interesting and like a powerful tool, so i started messing around with it. Making a few test programs here and there.
In my latest test I have hit a roadblock that I can't seem to get myself around.
I have located the problem, but i am unaware as to why it is giving me a run-time-error. here is the code for the thread that is running and causing the error (note: this function works if not using it in a thread):
The line that it gives the error on is:
I'm guessing it is because the call to al_get_bitmap(...) is not thread safe. But I'm still new to this multi-threading stuff. So if someone could confirm or deny, that be great. And any ideas on how to make this work using threads would also be appreciated.
Thanks in advanced,
The first thing you should do is check the return value of each function before passing it to the next.
Most likely, one of these functions is returning NULL and causing a crash when that value is passed to a function expecting a valid pointer.
Also, in your code you aren't storing the format anywhere. What exactly are you trying to do there?
@Todd Cope: Thanks for the tips I'll try that here in a couple moments and post back here (dinner time ). As you can see, I have a function commented out "LoadMap()" and deep in that function is the al_get_bitmap_format(...) code. i just moved it up front so that i wouldn't have to post a billion function calls, etc. Once a solution is found to prevent the error I will attempt to fix it where it is actually intended to be used.
EDIT: I just tested it real quick. And "format" ended up being equal to 23. So it looks to be running fine there as well.
The manual states that each thread has it's own "current display", and new threads have a default NULL current display, so you're passing NULL into those functions and that's probably why it's crashing.
If you had done what Todd said, you would have figured that out.
Thread #610871. Printed from Allegro.cc
@Trent Gamblin: your right. I must of missed that part in the manual or forgot about it. Thanks for clearing that up for me. And i was in a rush for my dinner so i didn't test the return value of my display in my "Load" thread. I just did it in my main. I was rushing and didn't read the post completely. Sorry, for that.
That pretty much solves my problem.