← Back to team overview

kicad-developers team mailing list archive

Re: Mac & "invalid context"


Marius Kintel wrote:
Hi again,

I've been digging deeper into this issue and think I found the cause of my problems with invalid graphic contexts: The Mac port of wxWidgets does not support having nested contexts (wxDC instances). In short, this means that the following is illegal and any draw command will fail:
wxClientDC dc(this);
wxClientDC dc2(this);
<- draw something here;

One example of where this is done in KiCad (this seems to be done all over the place):
wxClientDC dc( DrawPanel );

This function eventually calls WinEDA_BasePcbFrame::Compile_Ratsnest( wxDC* DC ...), which again calls WinEDA_MsgPanel::EraseMsgBox(), which creates a new context:
wxClientDC dc( this );

This one is easy to fix, but there are more, to an unknown extent.

In general (I'm not familiar with wxWidgets), it's considered nice to only draw stuff on the paint event itself. I guess this school of thought is not followed in KiCad, either accidentally or for some reason.

I'm wondering if anyone has any insights, ideas etc. about what to do about this?


~/= Marius

Kicad was written over a 15 year period, and going back to the start computers were slower then. One of the considerations then might have been to "show progress" when loading a board, or doing any type of long processing, things which now happen in a blink of the eye. One way that progress is shown, is to draw things on the screen while they are happening. A good example is loading a board file.

Today, this may not be appropriate. Each situation is different, so don't over extrapolate what I am saying. But in certain situations the drawing simply does not need to happen until the operation is complete, because the screen can be redrawn so quickly now.

Obviously this does not extend to situations where drawing does need to take place interactively, such as dragging operations.

So experiment. And also, you may want to take a look at the wxWidgets source and also post questions on that list. Perhaps there is an easy way to increase its functionality to make it compatible with Kicad source as is.