Opened 11 years ago

Closed 8 years ago

#162 closed defect (fixed)

CGContextRestoreGState: invalid context

Reported by: szabgab Owned by:
Priority: major Milestone:
Component: editor Version: 0.39
Keywords: osx Cc:


In #159 Chris Dolan mentioned

Exactly once per second, I get a new warning message on the console that says "CGContextRestoreGState: invalid context".

On Mac, Wx Version: 0.88 wxWidgets 2.8.8 using r1449

It seems this is related to this:

Attachments (1)

diff.patch (1.1 KB) - added by tome 8 years ago.
Patch to defer on_stc_update_ui to the idle after the event

Download all attachments as: .zip

Change History (14)

comment:1 Changed 11 years ago by schwern

Me too. Except it doesn't seem to be once per second but once per keystroke.

Wx Version: 0.89 wxWidgets 2.8.9

This is perl, v5.10.0 built for darwin-thread-multi-2level

Padre 0.27

comment:2 Changed 10 years ago by azawawi

Is this bug still valid with Padre 0.46 ?
Can you test it?

comment:3 Changed 10 years ago by schwern

  • Version changed from 0.19 to 0.39

Still a problem in 0.39. Let's install 0.46 and see...

I'm having difficulty getting Wx 0.91 or 0.92 to fully compile.

comment:4 Changed 9 years ago by szabgab

We are at 0.84 and have not heard about this issue recently. Could please check if it's still there?

comment:5 follow-up: Changed 9 years ago by schwern

Sorry, I still can't compile Wx on OS X. See

comment:6 in reply to: ↑ 5 Changed 8 years ago by tome

I can confirm this issue is still there on osx perl 5.14.1, Padre 0.87 (trunk r14962 Wx : .9901, wxw: 2.8.8)

<Error>: CGContextRestoreGState: invalid context 0x0

comment:7 Changed 8 years ago by tome

  • Keywords osx added

comment:8 Changed 8 years ago by tome

I can confirm this is occurring because of updates to the status bar during the EVT_STC_UPDATEUI, as is indicated in the widgets ticket:

For example if I move the update code out of the UPDATEUI and into an idle timer, we don't get that error.

Wx::Event::EVT_STC_UPDATEUI( $self, -1, sub {

shift->{_do_update_ui} = 1;

} );

Wx::Event::EVT_IDLE($self, sub {

my $self = shift;
if($self->{_do_update_ui}) {

$self->{_do_update_ui} = undef;



This is all new code to me but at least it's a start.

comment:9 Changed 8 years ago by bowtie

tome diff for above

  • lib/Padre/Wx/

    288288    ); 
    290290    # Scintilla Event Hooks 
    291     Wx::Event::EVT_STC_UPDATEUI( $self, -1, \&on_stc_update_ui ); 
     291    Wx::Event::EVT_STC_UPDATEUI( 
     292        $self, -1, 
     293        sub { 
     294            shift->{_do_update_ui} = 1; 
     295        } 
     296    ); 
     298    Wx::Event::EVT_IDLE( 
     299        $self, 
     300        sub { 
     301            my $self = shift; 
     302            if ( $self->{_do_update_ui} ) { 
     304                $self->{_do_update_ui} = undef; 
     305                $self->on_stc_update_ui(); 
     306            } 
     307        } 
     308    ); 
     310    # Wx::Event::EVT_STC_UPDATEUI( $self, -1, \&on_stc_update_ui ); 
    292311    Wx::Event::EVT_STC_CHANGE( $self, -1, \&on_stc_change ); 
    293312    Wx::Event::EVT_STC_STYLENEEDED( $self, -1, \&on_stc_style_needed ); 
    294313    Wx::Event::EVT_STC_CHARADDED( $self, -1, \&on_stc_char_added ); 

Changed 8 years ago by tome

Patch to defer on_stc_update_ui to the idle after the event

comment:10 Changed 8 years ago by tome

I'm also now seeing these context warnings when doing fast swipe scrolling, so I'll need to figure out where that's coming from and if a more general solution should be implemented.

comment:11 Changed 8 years ago by tome

With r15298, there is now only one known case of this warning:
When using the default scintilla, we get this when scrolling to new lines.

After debugging and eliminating all the Padre calls, I believe this may be in the Wx's implementation. I'm hoping to find out more once I can, or when I get to chat with those folks again.

For now this bug is 1/2 fixed, but at least we don't see the warning on every single keystroke.

comment:12 Changed 8 years ago by azawawi

Close it? :)

comment:13 Changed 8 years ago by tome

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.