I still have no solution other than to use software rendering. I'm fairly certain it's a graphics driver bug, specifically, a race condition.
Evidence:
- About one time in ten, it paints fine, so the problem is frequent but intermittent, suggestive of a timing issue.
- The problem happens only with the first paint after launching the application. (Yes, the size of the window is correct at that point.) Later repaints work fine. Fortunately, my application repaints the window every few minutes, so it remains black only for a few minutes after you launch it. This suggests a timing issue on application start.
- I haven't been able to reproduce with a tiny program, so the problem may be sensitive to the time necessary for the application to initialize. Perhaps the driver does some asynchronous initialization that doesn't always complete in time to handle the initial paint commands.
- It hasn't happened on other computers I've tried that use different graphics cards.
- When using software rendering, the painting works perfectly every time. This suggests that the bug isn't in my code.
Counter Evidence:
- Several rounds of driver updates over the past year have not made any difference in the behavior.
I'm posting this as an "answer" because a few others have seen similar symptoms and asked me if I ever found an answer. I'm still open to reading other ideas and will upvote good answers.