While maintaining an old product, I came across an error that results in the screen being filled up with hundreds of message boxes saying 'C++ Exception' and nothing else. I traced the problem to the following line:
Application->ProcessMessages();
I understand the purpose of this line, to process all the messages in the message queue, but I'm not sure what's causing the error.
I'm not looking for a specific solution, but I'm wondering if anyone else has had this problem or might know what sort of situations may cause this to happen.
Closing all the message boxes causes the application to return to normal, expected behavior.
Update - After some more searching, I found that the errors are not necessarily the fault of ProcessMessages. The errors occur because the program is doing some intensive calculations and actually runs out of memory. It seems like commenting out ProcessMessages reduces the memory consumption just enough to get through the calculations without errors. Hence, ProcessMessages looks like the culprit, but in fact, is not.
It looks like I have some refactoring to do.
Update 2 - Three days later, I have come to the conclusion that error only happens when ProcessMessages is called. If I comment all the calls to ProcessMessages (and to my dismay, there are many), then the application runs fine with a constant memory consumption, implying that the intensive calculations are not sucking up the memory. Uncommenting a call causes the memory to skyrocket to the point of error again. So the original question stands: why does ProcessMessages cause this error?
It would appear that some calls are made from a timer event and others are made from the main application execution. Might this be a problem?