unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#56559: 29.0.50; Invalid CGContextSaveState on NS
@ 2022-07-14 15:08 Gerd Möllmann
  2022-07-15  2:43 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-07-15 13:05 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 2 replies; 12+ messages in thread
From: Gerd Möllmann @ 2022-07-14 15:08 UTC (permalink / raw)
  To: 56559


In GNU Emacs 29.0.50 (build 1, aarch64-apple-darwin21.5.0, NS appkit-2113.50 Version 12.4 (Build 21F79))
 of 2022-07-12 built on Mini.fritz.box
Repository revision: f209650e41d59356a90b5a602abc60c6783bc7b1
Repository branch: master
Windowing system distributor 'Apple', version 10.3.2113
System Description:  macOS 12.4

Configured using:
 'configure --with-native-compilation'

At various times, Emacs prints

2022-07-14 16:55:41.722952+0200 emacs[65244:294257] [emacs] CGContextSaveGState:
invalid context 0x0. If you want to see the backtrace, please set
CG_CONTEXT_SHOW_BACKTRACE environmental variable.

to the terminal from which it is started.  Setting the env variable,
gives the backtrace

2022-07-14 16:56:29.249179+0200 emacs[65299:295037] [emacs] CGContextSetLineJoin: invalid context 0x0. Backtrace:
  <+[NSBezierPath strokeRect:]+136>
   <ns_draw_window_cursor+5448>
    <display_and_set_cursor+4532>
     <update_window_cursor+1556>
      <update_cursor_in_window_tree+444>
       <gui_update_cursor+100>
        <ns_set_cursor_color+1140>
         <gui_set_frame_parameters+15768>
          <Fmodify_frame_parameters+856>
           <Finternal_set_lisp_face_attribute+54152>
  





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#56559: 29.0.50; Invalid CGContextSaveState on NS
  2022-07-14 15:08 bug#56559: 29.0.50; Invalid CGContextSaveState on NS Gerd Möllmann
@ 2022-07-15  2:43 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-07-15  9:50   ` Gerd Möllmann
  2022-07-15 13:05 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 1 reply; 12+ messages in thread
From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-07-15  2:43 UTC (permalink / raw)
  To: Gerd Möllmann; +Cc: 56559

Gerd Möllmann <gerd.moellmann@gmail.com> writes:

> 2022-07-14 16:55:41.722952+0200 emacs[65244:294257] [emacs] CGContextSaveGState:
> invalid context 0x0. If you want to see the backtrace, please set
> CG_CONTEXT_SHOW_BACKTRACE environmental variable.
>
> to the terminal from which it is started.  Setting the env variable,
> gives the backtrace
>
> 2022-07-14 16:56:29.249179+0200 emacs[65299:295037] [emacs] CGContextSetLineJoin: invalid context 0x0. Backtrace:
>   <+[NSBezierPath strokeRect:]+136>
>    <ns_draw_window_cursor+5448>
>     <display_and_set_cursor+4532>
>      <update_window_cursor+1556>
>       <update_cursor_in_window_tree+444>
>        <gui_update_cursor+100>
>         <ns_set_cursor_color+1140>
>          <gui_set_frame_parameters+15768>
>           <Fmodify_frame_parameters+856>
>            <Finternal_set_lisp_face_attribute+54152>
>   

Could you please try to find out if `ctx' is ever nil here (in
ns_draw_window_cursor):

  ns_focus (f, NULL, 0);

->NSGraphicsContext *ctx = [NSGraphicsContext currentContext];
  [ctx saveGraphicsState];

and if so, what the value of `ns_updating_frame' and `f' are at that
location.

Thanks.





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#56559: 29.0.50; Invalid CGContextSaveState on NS
  2022-07-15  2:43 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-07-15  9:50   ` Gerd Möllmann
  2022-07-15  9:54     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 12+ messages in thread
From: Gerd Möllmann @ 2022-07-15  9:50 UTC (permalink / raw)
  To: Po Lu; +Cc: 56559



> On 2022-07-15,, at 4:43 , Po Lu <luangruo@yahoo.com> wrote:
> 
> 
> Could you please try to find out if `ctx' is ever nil here (in
> ns_draw_window_cursor):
> 
>  ns_focus (f, NULL, 0);
> 
> ->NSGraphicsContext *ctx = [NSGraphicsContext currentContext];
>  [ctx saveGraphicsState];

Doesn't seem to happen.

> 
> and if so, what the value of `ns_updating_frame' and `f' are at that
> location.
> 
> Thanks.

Maybe this helps: I've got a backtrace with

  <+[NSBezierPath strokeRect:]+264>
   <ns_draw_window_cursor+1188>

and the disassembly of ns_draw_window_cursor in the vicinity of that offset shows

    0x10045a824 <+1088>: bl     0x10008a184               ; draw_phys_cursor_glyph at xdisp.c:32617
    0x10045a828 <+1092>: adrp   x8, 230
    0x10045a82c <+1096>: ldr    x8, [x8, #0x10]
    0x10045a830 <+1100>: str    x8, [sp]
    0x10045a834 <+1104>: ldur   d0, [x29, #-0x60]
    0x10045a838 <+1108>: ldur   d1, [x29, #-0x58]
    0x10045a83c <+1112>: ldur   d2, [x29, #-0x50]
    0x10045a840 <+1116>: ldur   d3, [x29, #-0x48]
    0x10045a844 <+1120>: fmov   d5, #0.50000000
    0x10045a848 <+1124>: mov.16b v4, v5
    0x10045a84c <+1128>: bl     0x1004bf6c4               ; symbol stub for: NSInsetRect
    0x10045a850 <+1132>: ldr    x0, [sp]
    0x10045a854 <+1136>: add    x8, sp, #0x20
    0x10045a858 <+1140>: str    d0, [sp, #0x20]
    0x10045a85c <+1144>: str    d1, [sp, #0x28]
    0x10045a860 <+1148>: add    x8, x8, #0x10
    0x10045a864 <+1152>: str    d2, [sp, #0x30]
    0x10045a868 <+1156>: str    d3, [x8, #0x8]
    0x10045a86c <+1160>: adrp   x8, 229
    0x10045a870 <+1164>: ldr    x1, [x8, #0x6e0]
    0x10045a874 <+1168>: ldr    d0, [sp, #0x20]
    0x10045a878 <+1172>: ldr    d1, [sp, #0x28]
    0x10045a87c <+1176>: ldr    d2, [sp, #0x30]
    0x10045a880 <+1180>: ldr    d3, [sp, #0x38]
    0x10045a884 <+1184>: bl     0x1004c0894               ; symbol stub for: objc_msgSend
    0x10045a888 <+1188>: b      0x10045a918               ; <+1332> at nsterm.m:3129:4
    0x10045a88c <+1192>: ldur   d0, [x29, #-0x60]
    0x10045a890 <+1196>: ldur   d1, [x29, #-0x58]
    0x10045a894 <+1200>: ldur   d2, [x29, #-0x50]
    0x10045a898 <+1204>: ldur   d3, [x29, #-0x48]
    0x10045a89c <+1208>: bl     0x1004bf724               ; symbol stub for: NSRectFill
    0x10045a8a0 <+1212>: b      0x10045a918               ; <+1332> at nsterm.m:3129:4
    0x10045a8a4 <+1216>: ldur   q0, [x29, #-0x60]
    0x10045a8a8 <+1220>: stur   q0, [x29, #-0x80]
    0x10045a8ac <+1224>: ldur   q0, [x29, #-0x50]
    0x10045a8b0 <+1228>: stur   q0, [x29, #-0x70]
    0x10045a8b4 <+1232>: ldur   x0, [x29, #-0x18]
    0x10045a8b8 <+1236>: bl     0x100100a90               ; get_phys_cursor_glyph at window.c:7420
    0x10045a8bc <+1240>: str    x0, [sp, #0x88]
    0x10045a8c0 <+1244>: ldr    x8, [sp, #0x88]
    0x10045a8c4 <+1248>: ldr    w8, [x8, #0x18]
    0x10045a8c8 <+1252>: tbz    w8, #0xa, 0x10045a900     ; <+1308> at nsterm.m:3125:7
    0x10045a8cc <+1256>: b      0x10045a8d0               ; <+1260> at nsterm.m:3123:23








^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#56559: 29.0.50; Invalid CGContextSaveState on NS
  2022-07-15  9:50   ` Gerd Möllmann
@ 2022-07-15  9:54     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-07-15 10:33       ` Gerd Möllmann
  0 siblings, 1 reply; 12+ messages in thread
From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-07-15  9:54 UTC (permalink / raw)
  To: Gerd Möllmann; +Cc: 56559

Gerd Möllmann <gerd.moellmann@gmail.com> writes:

>> On 2022-07-15,, at 4:43 , Po Lu <luangruo@yahoo.com> wrote:
>> 
>> 
>> Could you please try to find out if `ctx' is ever nil here (in
>> ns_draw_window_cursor):
>> 
>>  ns_focus (f, NULL, 0);
>> 
>> ->NSGraphicsContext *ctx = [NSGraphicsContext currentContext];
>>  [ctx saveGraphicsState];
>
> Doesn't seem to happen.

Odd, I thought that message was supposed to show up if you try to draw
something without an active graphics context.  I'm no Mac programmer, so
I guess someone else should take over at this point.

Thanks.





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#56559: 29.0.50; Invalid CGContextSaveState on NS
  2022-07-15  9:54     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-07-15 10:33       ` Gerd Möllmann
  2022-07-15 11:52         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 12+ messages in thread
From: Gerd Möllmann @ 2022-07-15 10:33 UTC (permalink / raw)
  To: Po Lu; +Cc: 56559



> On 2022-07-15,, at 11:54 , Po Lu <luangruo@yahoo.com> wrote:
> 
> Gerd Möllmann <gerd.moellmann@gmail.com> writes:
> 
>> Doesn't seem to happen.
> 
> Odd, I thought that message was supposed to show up if you try to draw
> something without an active graphics context.  I'm no Mac programmer, so
> I guess someone else should take over at this point.

Coming to think about it, maybe I'm doing something wrong?  How would I check for nil in this case?  I did "ctx == nil".  Should that perhaps be "*ctx == nil"?  (Sorry, I'm not an ObjC programmer at all.)




^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#56559: 29.0.50; Invalid CGContextSaveState on NS
  2022-07-15 10:33       ` Gerd Möllmann
@ 2022-07-15 11:52         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-07-15 13:25           ` Gerd Möllmann
  0 siblings, 1 reply; 12+ messages in thread
From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-07-15 11:52 UTC (permalink / raw)
  To: Gerd Möllmann; +Cc: 56559

Gerd Möllmann <gerd.moellmann@gmail.com> writes:

> Coming to think about it, maybe I'm doing something wrong?  How would
> I check for nil in this case?  I did "ctx == nil".  Should that
> perhaps be "*ctx == nil"?  (Sorry, I'm not an ObjC programmer at all.)

No, "ctx == nil" should be enough.

Thanks.





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#56559: 29.0.50; Invalid CGContextSaveState on NS
  2022-07-14 15:08 bug#56559: 29.0.50; Invalid CGContextSaveState on NS Gerd Möllmann
  2022-07-15  2:43 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-07-15 13:05 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-07-15 13:14   ` Gerd Möllmann
  1 sibling, 1 reply; 12+ messages in thread
From: Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-07-15 13:05 UTC (permalink / raw)
  To: Gerd Möllmann; +Cc: 56559

Gerd Möllmann <gerd.moellmann@gmail.com> writes:

> In GNU Emacs 29.0.50 (build 1, aarch64-apple-darwin21.5.0, NS appkit-2113.50 Version 12.4 (Build 21F79))
>  of 2022-07-12 built on Mini.fritz.box
> Repository revision: f209650e41d59356a90b5a602abc60c6783bc7b1
> Repository branch: master
> Windowing system distributor 'Apple', version 10.3.2113
> System Description:  macOS 12.4
>
> Configured using:
>  'configure --with-native-compilation'
>
> At various times, Emacs prints
>
> 2022-07-14 16:55:41.722952+0200 emacs[65244:294257] [emacs] CGContextSaveGState:
> invalid context 0x0. If you want to see the backtrace, please set
> CG_CONTEXT_SHOW_BACKTRACE environmental variable.
>
> to the terminal from which it is started.

I can't reproduce this issue.  Can you describe in more detail what you
do to reproduce the warning?  Can you reproduce this in emacs -Q?





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#56559: 29.0.50; Invalid CGContextSaveState on NS
  2022-07-15 13:05 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-07-15 13:14   ` Gerd Möllmann
  0 siblings, 0 replies; 12+ messages in thread
From: Gerd Möllmann @ 2022-07-15 13:14 UTC (permalink / raw)
  To: Daniel Martín; +Cc: 56559


> On 2022-07-15,, at 15:05 , Daniel Martín <mardani29@yahoo.es> wrote:
> 
> I can't reproduce this issue.  Can you describe in more detail what you
> do to reproduce the warning?  Can you reproduce this in emacs -Q?


I do nothing special, just start Emacs (with Spacemacs config).  It happens when drawing a hollow box cursor in my case, which is what I found out so far.  

I haven't tried with emacs -Q so far.







^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#56559: 29.0.50; Invalid CGContextSaveState on NS
  2022-07-15 11:52         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-07-15 13:25           ` Gerd Möllmann
  2022-07-15 14:01             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 12+ messages in thread
From: Gerd Möllmann @ 2022-07-15 13:25 UTC (permalink / raw)
  To: Po Lu; +Cc: 56559

Can I please ask another question?  You seem to be the only one here knowing the NS stuff.

I'm looking at the ns_focus/ns_unfocus stuff,.  From just eading the code, it appears to me that nested calls liek so:

  1 ns_focus          in ns_draw_window_cursor
  2   ns_focus        in draw_.*
  3   ns_unfocus      in draw_.*
  4   ...
  5 ns_unfocus        in ns_draw_window_cursor

are not supported, or is the intention that they are?

My hypthesis is the ns_unfocus in line 3 above undoes the ns_focus from line 1, or parts thereof, I haven't checked that thoroughly.

To make that a theory, I've added an ns_focus like so

      ns_focus(f, NULL, 0);
      [NSBezierPath strokeRect:NSInsetRect(r, 0.5, 0.5)];

and voilà the error is gone.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#56559: 29.0.50; Invalid CGContextSaveState on NS
  2022-07-15 13:25           ` Gerd Möllmann
@ 2022-07-15 14:01             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-07-15 14:12               ` Gerd Möllmann
  0 siblings, 1 reply; 12+ messages in thread
From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-07-15 14:01 UTC (permalink / raw)
  To: Gerd Möllmann; +Cc: 56559

Gerd Möllmann <gerd.moellmann@gmail.com> writes:

> Can I please ask another question?  You seem to be the only one here
> knowing the NS stuff.

There's also Alan Third (alan@idocy.org), and the developers listed in
etc/NEXTSTEP.  They know the code much better than I do.

> I'm looking at the ns_focus/ns_unfocus stuff,.  From just eading the
> code, it appears to me that nested calls liek so:
>
>   1 ns_focus          in ns_draw_window_cursor
>   2   ns_focus        in draw_.*
>   3   ns_unfocus      in draw_.*
>   4   ...
>   5 ns_unfocus        in ns_draw_window_cursor
>
> are not supported, or is the intention that they are?

They are not indeed.

> My hypthesis is the ns_unfocus in line 3 above undoes the ns_focus
> from line 1, or parts thereof, I haven't checked that thoroughly.
>
> To make that a theory, I've added an ns_focus like so
>
>       ns_focus(f, NULL, 0);
>       [NSBezierPath strokeRect:NSInsetRect(r, 0.5, 0.5)];
>
> and voilà the error is gone.

Thanks.  Does what I just installed on master work too?  (I can't test
on macOS ATM, but it works on GNUstep.)






^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#56559: 29.0.50; Invalid CGContextSaveState on NS
  2022-07-15 14:01             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-07-15 14:12               ` Gerd Möllmann
  2022-07-16  3:05                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 12+ messages in thread
From: Gerd Möllmann @ 2022-07-15 14:12 UTC (permalink / raw)
  To: Po Lu; +Cc: 56559



> On 2022-07-15,, at 16:01 , Po Lu <luangruo@yahoo.com> wrote:
> 
> Thanks.  Does what I just installed on master work too?  (I can't test
> on macOS ATM, but it works on GNUstep.)
> 

Works for me.  Thanks!

P.S.

For posterity, because I will forget: One can set a breakpoint at CGPostError in maxOS to stop when such an error occurs.






^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#56559: 29.0.50; Invalid CGContextSaveState on NS
  2022-07-15 14:12               ` Gerd Möllmann
@ 2022-07-16  3:05                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 12+ messages in thread
From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-07-16  3:05 UTC (permalink / raw)
  To: Gerd Möllmann; +Cc: 56559-done

Gerd Möllmann <gerd.moellmann@gmail.com> writes:

> Works for me.  Thanks!

Great, then I'm closing this bug.





^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-07-16  3:05 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-14 15:08 bug#56559: 29.0.50; Invalid CGContextSaveState on NS Gerd Möllmann
2022-07-15  2:43 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-15  9:50   ` Gerd Möllmann
2022-07-15  9:54     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-15 10:33       ` Gerd Möllmann
2022-07-15 11:52         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-15 13:25           ` Gerd Möllmann
2022-07-15 14:01             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-15 14:12               ` Gerd Möllmann
2022-07-16  3:05                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-15 13:05 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-15 13:14   ` Gerd Möllmann

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).