Fix crash in painting.