1

I have a small 2D rendering library in C++ that runs on Win32 apps, and uses Direct2D to do it's drawing. I have called BeginDraw(), done a load of drawing and then called DrawText(). This is of course before EndDraw().

Instead of returning so I can carry on making calls to rendering functions, it stalls because it has sent a WM_PAINT (presumably without waiting).(and will continue to send the message until maybe the window is validated? I don't know)

I have tried to catch the call and test if I'm drawing at the time, in which case pretend I have processed the message correctly (but without actually validating any client region manually), but it just keeps sending it, and DrawText() doesn't return.

Is this normal behaviour and what to do about it?

(I'm using visual studio community 2013 as well.)

Andy Good
  • 37
  • 3
  • 1
    `WM_PAINT` will keep coming until you paint or validate your window. If you don't care (because you're not using GDI) then just call `BeginPaint` followed by `EndPaint`. – Raymond Chen Jan 21 '17 at 19:08
  • Thanks Raymond. I don't understand why it is sending one within DrawText of an ID2D1::RenderTarget anyway, when it doesn't do so when using functions like DrawLine or DrawRect. Any ideas? – Andy Good Jan 22 '17 at 13:15
  • What you're describing sounds strange to me. I have a test application myself, where I do DrawTextLayout() in WM_PAINT handler, after EndDraw() I simply validate with ValidateRect(hwnd, NULL) and it works normally. Could you show some of your code maybe? It's presumably HwndRenderTarget, is it? What Windows version? – bunglehead Jan 22 '17 at 16:25
  • @AndyGood It can send it at any time, so just handle it as you're meant to. – Jonathan Potter Jan 23 '17 at 01:54
  • I was handling it. It was in an infinite loop :) – Andy Good Mar 07 '17 at 22:20

1 Answers1

1

I found the error eventually.

One of the parameters I passed to a DIrect2D function was an invalid object pointer, as I didn't know that I had released the memory already, then was trying to use the object to draw stuff. If I knew the default memory pattern for released Direct2D pointers was 0xcdcdcdcd (or something like that), I would've seen it sooner.

For some reason unbeknownst to man, this triggered a WM_PAINT... horrible bug.

Thanks all!

Andy Good
  • 37
  • 3