// JP opened flex table

Click to See Complete Forum and Search --> : Release build crashes after OnPaint() or OnDraw()


Eric Roth
November 28th, 2000, 05:08 PM
I am trying to convert a MFC project that executes successfully in Debug compilation over to a final Release. Unfortunately, the release version crashes following the execution of any function triggered by a WM_PAINT message, like OnPaint(), OnDraw, or Invalidate(), which generates a WM_PAINT message. The triggered function completes execution, but then, just after, it crashes. This makes me believe it is an issue with the run-time stack being improperly managed upon return from the function.

This is the message I get when it crashes: <<The instruction at "0x5f401351" referenced memory at "0x00000037". The memory could not be "read".>>

I have read some articles about converting to a Release version. They suggested tips that I tried like using the /GZ switch at compilation, and removing important code from ASSERT() calls or replacing the ASSERTs with VERIFYs. Additionally, I have explored making sure all my varibles and objects are properly initialized. I have turned off all compiler optimizations. I believe the OnPaint() and OnDraw methods are properly registered into the message map, and have the proper arguments. I don't know what else I can try. If you have encountered a similar situation before, I'd appreciate any advise you could offer.

Thanks,
Eric Roth
rothe@lunainnovations.com

Alex Fedotov
November 28th, 2000, 07:50 PM
Could you show us call stack?

Eric Roth
November 29th, 2000, 11:09 AM
I found the problem. My OnPaint() method was registed in the message map using ON_MESSAGE(WM_PAINT, OnPaint). When I changed it to ON_WM_PAINT(), the crashes stopped. ...Interesting bug.

Eric Roth

Alturis2
December 7th, 2000, 09:10 PM
Not really. The ON_MESSAGE envokes the function with differnt parameters. The OnPaint is already customized to the paint message thus the parameters are different. ( i believe ) A Generic on message handler takes wparam and lparam. the OnPaint method takes... well i cant look it up now but im sure its not 2 32 bit integers

jomofo
January 22nd, 2001, 04:38 PM
Alturis is correct. Check out this MSDN article for more information:

"PRB: Incorrect Function Signatures May Cause Problems in Release"

When developing applications in Visual C++ with MFC, you may receive an invalid page fault in Mfc42.dll in release builds due to an incorrect function signature for any of the following MFC macros:

ON_MESSAGE()
ON_REGISTERED_MESSAGE()
ON_THREAD_MESSAGE()
ON_REGISTERED_THREAD_MESSAGE()

CAUSE
The message handlers for ON_MESSAGE(), ON_REGISTERED_MESSAGE(), ON_THREAD_MESSAGE(), and ON_REGISTERED_THREAD_MESSAGE() require the programmer to have the correct function signatures. By not having a correct function signature for the handler, an invalid page fault in Mfc42.dll results after the handler executes in release builds. A crash in debug builds does not occur because the stack frame is set up differently for debug builds than it is for release builds.

RESOLUTION
Make sure your message handlers for ON_MESSAGE(), ON_REGISTERED_MESSAGE(), ON_THREAD_MESSAGE(), and ON_REGISTERED_THREAD_MESSAGE() have the correct signatures.

psuhellcat
June 8th, 2001, 12:24 PM
I have the same problem..with OnDraw()..im not using OnPaint specifically at all...would the same solution work??

//JP added flex table