Original Post
hey everyone,
i am building a gui in directx- and i wish an element of the system (e.g. a dialog box with buttons ok and cancel) to be able to free itself. I have written a MemManager class like so:
class MemManager {
int noElems; // no elems to be destroyed
unsigned long elems[NO_ELEMS]; // array of pointers
bool add(void *); // adds a pointer to the array
bool destroy(); // free mem pointed to by elems array
};
the dialog box has a pointer to a memManager object. My event handler for the gui uses the windows event thread and modifies the messages for my purposes.
at the end of each game loop i call the memManagers destroy function.
i want the dialog box to have an event handler method something like so:
handleEvent(Message msg) {
if (msg == "cancel") { // cancel is clicked
m_parent->removeWindow(this);
memManager->add(this); *** DODGY LINE!! *******
}
}
however, this does not work. I am almost certain it is because of thread synchronization between the event handler thread and the main thread. how could i fix this, or better yet, avoid it altogether??
thanks for reading this,
hope i gave enough information,
cheers