Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacVim occasionally stops rendering text after sleep #1164

Closed
mattooca opened this issue Jan 11, 2021 · 64 comments · Fixed by #1179
Closed

MacVim occasionally stops rendering text after sleep #1164

mattooca opened this issue Jan 11, 2021 · 64 comments · Fixed by #1179
Labels
Renderer Text rendering issues, including CoreText renderer
Milestone

Comments

@mattooca
Copy link

I've been experiencing issue #1068 (where syntax highlighting turns off in existing MacVim windows when computer wakes from sleep). I also recently noticed a new issue where all text occasionally disappears in all open MacVim windows. I think the trigger is either waking the laptop from sleep or attaching / detaching external displays.

The problem occurs every two days or so, and impacts both windows that were already open and any new windows opened after. I can resolve the problem by quitting and restarting MacVim, but I often have many open windows so prefer to find a fix.

I'm currently using MacVim 8.2.2164 (169), running on OS X 10.15.7. I think this issue first appeared after the previous MacVim update (I tried updating when I first noticed the problem to see if it would resolve the issue, but no luck).

Attached image shows a new MacVim window opened up after the issue starts. The only visible text is up on the title bar, the VIM splash screen doesn't show up.

image

@ychin
Copy link
Member

ychin commented Jan 12, 2021

Can you try running with a clean vimrc (by doing mvim --clean), and show me the settings you have by doing defaults read org.vim.MacVim | grep MM?

Also, if you say resize the window, would it have fixed the problem?

@mattooca
Copy link
Author

mattooca commented Jan 12, 2021

Settings:

    MMAutosaveColumns = 230;
    MMAutosaveRows = 56;
    MMCurrentPreferencePane = General;
    MMTopLeftPoint = "{927, 1057}";

I'll try starting with mvim --clean next time the problem occurs.
Resizing windows did not make a difference, but I tried disconnecting and reconnecting the external display and found that the problem eventually went away (not right after reconnecting but a minute or so later).

@mattooca
Copy link
Author

Problem recurred just now, I tried opening a new window with 'mvim --clean' but see the same problem in that new window. The geometry is different (230x56 instead of my default 120x56) and the color scheme is a bit different, but it has the same problem as a window opened with just 'mvim'.

This time I waited for a while rather than restarting MacVim or detaching/reattaching the external display. The problem went away on its own after about 5 minutes, although at first it only rendered the top line of each file. Additional lines appeared as I moved the cursor up or down to each line...

@schveiguy
Copy link

Having the same problem. This is quite annoying, as I frequently have 4 or 5 windows open, with 2-5 buffers each. And trying to save things is hard because I can't see anything I'm typing. I've seen it go away once, but most of the time I end up restarting it.

Another tidbit, this doesn't happen to me only when waking from sleep (I think). When this happens while I'm editing, it does not remove the existing rendered text until I move my cursor around in the file, and then every line the cursor touches is blanked. If I hit ctrl-L, it blanks the whole window's text.

Attached is a pic of one vim window I hit ctrl-L on with multiple buffers, and another one behind it where I just started to move around (you can see the area around the cursor is blank).
Screen Shot 2021-02-03 at 5 33 11 PM

@ychin
Copy link
Member

ychin commented Feb 9, 2021

Huh that's annoying… @schveiguy can you also post your result of defaults read org.vim.MacVim | grep MM? Also, what kind of Mac are you using? And also, what font are you using?

Also, for both @schveiguy and @mattooca , do your monitors support retina display? Or do you switch between retina and non-retina? I'm mostly just grasping at straws here since I can't seem to repro the issue.

@ychin ychin added this to the snapshot-170 milestone Feb 9, 2021
@timothy-knox
Copy link

I'm seeing the same problem. I'm running MacVim 8.2.2164 (169) on macOS 10.15.7.

$ defaults read org.vim.MacVim | grep MM
    MMAppearanceModeSelection = 1;
    MMAutosaveColumns = 127;
    MMAutosaveRows = 43;
    MMCurrentPreferencePane = Appearance;
    MMNoTitleBarWindow = 0;
    MMTitlebarAppearsTransparent = 1;
    MMTopLeftPoint = "{0, 1027}";

It occurs without sleeping. It persists for several minutes, and running ':redraw!' does not fix it. But after five-ish minutes, the line under the cursor suddenly becomes visible again, and ':redraw!' then brings the whole screen back.

@schveiguy
Copy link

I'm mostly just grasping at straws here since I can't seem to repro the issue.

It might be a good grasp. Nearly all my time I spend on my 4k attached monitor instead of my retina screen. If I had to guess, I'd say it happens mostly on my 4k screen, and it might be 100% of the time, I'm not sure.

I just spent about 5 days where I didn't have my screen, just the retina display of my macbook, and I didn't have the problem happen, but that's not really a meaningful detail, as it doesn't happen with any specific regularity.

My font is Menlo 14 point.

Here is the result of that defaults command:

    MMAutosaveColumns = 170;
    MMAutosaveRows = 83;
    MMCurrentPreferencePane = General;
    MMLastWindowClosedBehavior = 2;
    MMTopLeftPoint = "{1817, 1522}";
    MMZoomBoth = 1;

@schveiguy
Copy link

schveiguy commented Feb 10, 2021

I did just notice that Macvim supports dark mode, I was on the "evening" setting for colors, because it wasn't available when I started using dark mode. I just switched back to the default scheme, and maybe this will make a difference?

Edit: eh, I went back. The blue that is used for the tildes at the bottom for the default scheme is hard on the eyes.

@ychin
Copy link
Member

ychin commented Feb 10, 2021

The default MacVim color scheme never got updated for dark mode and doesn't work well under it. I need to fix it… Anyway that's a different issue.

@mattooca
Copy link
Author

mattooca commented Feb 10, 2021

Regarding monitors, this is happening on a Macbook Pro with Retina display, but I usually have it attached to one or two lower-resolution external displays. The problem is happening right now, I tried dragging MacVim windows to different monitors but it makes no difference.
One other funny detail: it looks like the open / close parentheses syntax highlighting still works, see the little blue box in attached screenshot.

Screen Shot 2021-02-10 at 9 22 04 AM

@ychin
Copy link
Member

ychin commented Feb 11, 2021

I'm still struggling to repro this (even with an external 4K monitor), but if you see this again, try to change the font / font size. You could just do that by doing <cmd>- or <cmd>+ to quickly toggle font sizes. I think it would reset the font cache which would bring the text rendering back which should allow you to keep working.

Also, if changing font/font size does indeed solve the issue, let me know as that would confirm what I think is going wrong.

@ychin
Copy link
Member

ychin commented Feb 12, 2021

@mattooca can you clarify what you meant by this?

Attached image shows a new MacVim window opened up after the issue starts. The only visible text is up on the title bar, the VIM splash screen doesn't show up.

Are you saying that you saw that all of MacVim lost text rendering, then you opened a new window (either by Cmd-N or using the menu)? Or are you saying you already had a new window opened with text working, and then it lost its text rendering?

@mattooca
Copy link
Author

mattooca commented Feb 12, 2021 via email

@mattooca
Copy link
Author

The problem recurred this morning, and I tried a few things.
Changing font, changing font size, going into full screen mode, changing the color scheme, and opening up new windows: none of those fixed the issue.

However, disconnecting the external display did fix the problem. Text showed up again on all open windows almost immediately. The text stayed visible when I then reconnected to the external display, at least so far (I tried disconnecting about 10 minutes ago).

@ychin
Copy link
Member

ychin commented Feb 13, 2021

Oh… ok 😢. This is a little different from what I thought, but will help me prevent digging into a rabbit hole. Since I have trouble reproducing it, let me think about what to do over the weekend to see how this can be debugged and fixed.

@graywh
Copy link

graywh commented Feb 15, 2021

Also having this issue, but disconnecting my external monitor did not correct the problem. Waiting several minutes did.

MacVim 8.2.2164
2017 Macbook Pro w/ retina display
macOS 10.13.6
font DejaVu Sans Mono

% defaults read org.vim.MacVim | grep MM
2:    MMAutosaveColumns = 140;
3:    MMAutosaveRows = 60;
4:    MMCurrentPreferencePane = Advanced;
5:    MMTopLeftPoint = "{797, 1178}";`

@graywh
Copy link

graywh commented Feb 16, 2021

I will add that not all open windows are affected equally. I can have a window open that is displaying text and open a new window and have no text.

@schveiguy
Copy link

More info: It just happened again. I was on a second desktop in this case, and I swiped back to the first desktop to report. Instantly, when I went back to the other desktop, it was working again.

@schveiguy
Copy link

Happening again right now, this time swiping between desktops is not clearing the problem. Changing the font size does not clear the problem. When I moved the window from my 4k display to the retina display, it redrew the window completely and all text is now gone (except the highlights).

@schveiguy
Copy link

It's still in a bad state if you want me to try anything else.

@ychin ychin added the Renderer Text rendering issues, including CoreText renderer label Feb 18, 2021
@ychin
Copy link
Member

ychin commented Feb 18, 2021

@schveiguy Can you try to capture the system logs from MacVim? You could either use Console.app to get it, or just use the terminal and do log show --debug --info --predicate='process=="MacVim"' --last 1h > macvim_logs.txt which will grab the logs from last hour and put it to a file macvim_logs.txt that you could attach here.

The wiki for this (https://github.com/macvim-dev/macvim/wiki/Debugging) is a little outdated, but you may also want to do this step first by doing:

defaults write org.vim.MacVim MMLogLevel 7

After we are done debugging you probably want to set it back to default logging level:

defaults delete org.vim.MacVim MMLogLevel

Thanks a lot for the help in debugging.

@schveiguy
Copy link

OK, so my mac went to sleep. I came back to do these steps. I first logged in, and saw that it in fact was still in the bad state. So I ran the log command. Then I ran the defaults command, and switched back to my macvim window and it's now recovering (the text is coming back on lines that I put my cursor on). I took a second log dump. The newest logs after I did the defaults happened at 16:38:11. Attached is the log file.

Should I leave the MMLogLevel at 7 for when this happens again?

macvim_logs2.txt

@ychin
Copy link
Member

ychin commented Feb 18, 2021

Yeah maybe leave it at that level for now if you could. It's just going to generate a little more logging but the logs you captured didn't provide quite enough info, so it would be nice to see if we could get more info from this.

I'm trying different ways to see if I could replicate this.

@schveiguy
Copy link

Happened again just now. And here is the weird thing. I was not even using MacVim, I was running a build in another window. And my eyes happen to notice a change on the MacVim window, where the text just disappeared.

I have the logging level set to 7, let me know if you want me to try anything.

@schveiguy
Copy link

And, it's now working again. Here is the last 30m of logs that happened during that time:

macvim_logs.txt

@schveiguy
Copy link

Happened again, recovered again quickly. Logs:
macvim_logs2.txt

@schveiguy
Copy link

And again, it's happening a lot more today than usual. But it's also clearing up quickly too.

This time I moved it to my retina screen, it got blanked, then I moved it back to my 4k screen, and it started working again.

macvim_logs3.txt

@ychin
Copy link
Member

ychin commented Feb 22, 2021

Unfortunately those logs do not have debug info on them. I think you need to somehow trigger the debug logging to be on per the steps in https://developer.apple.com/documentation/os/logging/customizing_logging_behavior_while_debugging?language=objc or something, but from local testing, seems like just having Console.app running would turn on debug logging as well. I think next time if you could, maybe have Console.app running in the background?

But now I feel like we are just piling on more work for you to do. Currently the CoreText renderer doesn't have a lot of logging anyway, so I think I'll push an update out soon (last update was in 2020…) and call this out as a known issue, while adding more logging in suspicious points in the renderer so we will get better signal to noise ration in the logging and debugging effort.

Also pinging @s4y to see if he encountered anything like this when implementing the current renderer (tldr: under certain situations such as waking from sleep or unplugging monitors, all texts stop rendering but other parts still draw)

@stevematney
Copy link

stevematney commented Mar 9, 2021

I wanted to note: I've seen this issue when no changes in hardware occur at all. Occasionally all the text just disappears. Sometimes it seems to come back after a few minutes or after fiddling with some display settings inside MacVim, but sometimes it does not.

I may need to log a different issue, but I have consistently been able to get MacVim to crash. If I convert to HEX, and then convert back (from the Tools menu), and then switch to a different Dark Mode selection, MacVim crashes every time. I thought this was related to the disappearing text issue, but out of curiosity I just repeated the steps without that issue present, and it still crashed.

@eirnym
Copy link
Contributor

eirnym commented Mar 9, 2021

Ok, I finally got the issue once on MBA 2015, after copy-pasting via Cmd-A, Cmd-C, Cmd-V. No external monitors or sleeping. But… just once

@eirnym
Copy link
Contributor

eirnym commented Mar 9, 2021

Only quitting the app helped me. New window does not. Vim itself isn't broken, so I successfully saved my data.

@ychin
Copy link
Member

ychin commented Mar 9, 2021

Ok. So, I just pushed release 170 out. It contains some extra logging that should help identify the issue. It does require debugging logging on for maximum logging, so interested parties, if you could turn on debug logging and capture logs again I would appreciate it, thanks.

@fvicente
Copy link

I had this problem with build 170. Resizing doesn't fix the issue, but if I go to dark mode and go back to normal a resize makes the text to re-appear.

@tomp
Copy link

tomp commented Mar 10, 2021

I've had this happen to me a couple of times over the last week, with build 169. I'm on an 2017 15" MacBook Pro, with an external monitor, running a current version of Catalina. Resizing and changing the fonts hasn't helped me.

@ychin
Copy link
Member

ychin commented Mar 12, 2021

If any of you see this issue again, do you mind following the instructions at #1164 (comment) to capture logs and upload here? r170 contained more logging capability and it would be very useful, thanks.

@stevematney
Copy link

I ran into this this morning. Here are my logs from the last few hours: https://gist.github.com/stevematney/a694694e43f36c07b992c33929a697fc

@ychin
Copy link
Member

ychin commented Mar 12, 2021

@stevematney If you don't mind, do you mind enabling debug logging by doing the following? The drawback is just slightly more logging from MacVim, and debug logging are all logged to an OS memory buffer so it shouldn't use more disk space.

sudo log config --mode "level:debug" --subsystem org.vim.MacVim
defaults write org.vim.MacVim MMLogLevel 7

You can revert the debug logging by doing this:

sudo log config --mode "level:info" --subsystem org.vim.MacVim
defaults delete org.vim.MacVim MMLogLevel

I'm now wondering if I should have just made these logging non-debug-only…

@timothy-knox
Copy link

An update: First, I don't have logs to attach, sorry. :-(

I run on a MBP 13" 2019 model (8GB, quad core i5 1.4GHz), no external monitor. I just unlocked the screen saver, switched to MacVim, and watched the line under the cursor disappear, although the remainder of the text was visible. When I moved the cursor up a line, that line also disappeared. A ':redraw' made all the text disappear, though the 'misspelling carats' remained visible. After about five minutes (trying switching to full screen, decreasing and increasing the font size, and minimizing/restoring the window to no avail), the line under the cursor became visible.

An interesting point: Even though text wrapping was enabled, and I was on the second line of a two line paragraph, only the "screen row" of text disappeared, and when it came back, only the screen row came back (until I did a ':redraw'). So it appears to be related to rows of text, rather than paragraphs/logical lines of text.

@tomp
Copy link

tomp commented Mar 13, 2021

Just encountered this, again, in build 170. Symptoms were similar to what timothy-knox described...

watched the line under the cursor disappear, although the remainder of the text was visible. When I moved the cursor up a line, that line also disappeared. A ':redraw' made all the text disappear, though the 'misspelling carats' remained visible. After about five minutes (trying switching to full screen, decreasing and increasing the font size, and minimizing/restoring the window to no avail), the line under the cursor became visible.

macvim_logs.txt

@nsamarak
Copy link

I'm running build 170 on an M1 MacBook Air and this issue happens for me multiple times a day. MacVim seems to be fine when my computer wakes up from sleep but an hour or 2 later, text starts disappearing from the screen as I click on the text or as I use the up and down keys to scroll past the text. Logs attached.

defaults read org.vim.MacVim | grep MM
MMAutosaveColumns = 85;
MMAutosaveRows = 65;
MMTopLeftPoint = "{416, 1055}";

macvim_logs.txt

@s4y
Copy link
Contributor

s4y commented Mar 24, 2021

I can trigger this immediately by simulating memory pressure:

sudo memory_pressure -S -l critical -s 60

…so I suspect something is getting kicked out of a cache. Investigating but don't have any solid leads yet.

s4y added a commit to s4y/macvim that referenced this issue Mar 24, 2021
When there's memory pressure, the cache just drops the line immediately.
Fixes macvim-dev#1164.
@s4y
Copy link
Contributor

s4y commented Mar 24, 2021

I'm sorry for the delay in getting to this, all. The linked pull request should fix it.

@ychin
Copy link
Member

ychin commented Mar 24, 2021

memory_pressure

That's a nice trick! I'll keep that in mind next time. Also, thanks for looking into this.

@ychin
Copy link
Member

ychin commented Mar 24, 2021

Ok this should be fixed! Thanks for the PR. Played around with it with the memory_pressure tool and confirmed the behavior and also that it's fixed.

One of those things that if we switched to ARC instead of reference counting we may have avoided this bug :/ (but then this is a CoreFoundation object, so maybe there may still be chances to have screwed this up due to how you need to specify how the bridging works)

@s4y
Copy link
Contributor

s4y commented Mar 25, 2021

One of those things that if we switched to ARC instead of reference counting we may have avoided this bug :/ (but then this is a CoreFoundation object, so maybe there may still be chances to have screwed this up due to how you need to specify how the bridging works)

@ychin This was making me think about ARC, too. I have some interest in investigating it; is there any history around talking about/trying to switch to ARC?

@ychin
Copy link
Member

ychin commented Mar 25, 2021

@s4y I think there is a lack of history of trying to switch to ARC :). But no I don't know what the history is. I think we just never looked into it, and since MacVim tends to follow the Vim philosophy of backwards compatibility, it takes a while before we are ahead enough to be able to say "we can support ARC" without breaking backwards compatibility.

Also, it's just not the kind of thing that brings immediate improvements, even though it does help prevent random memory leaks and potential retain bugs like this one.

I'm not really opposed to switching over. I was hoping to take a look at some point in the future, but if you want to investigate it that's totally fine. FWIW the new tabs PR (#1120) is using ARC, and I explicitly OKed it. No point in making a new project that uses manual reference counting.

@ychin
Copy link
Member

ychin commented Mar 30, 2021

@s4y, if you want to look into ARC, please use #1182 instead of this issue.

@schveiguy
Copy link

FYI I recently updated to Big Sur and haven't seen this problem since (still on build 170). But it seems I probably won't see it again, thanks for all the support!

@ekortright
Copy link

I am still seeing this problem on MacOS Catalina (10.15.7) with retina display and an external monitor. My MacVim is Custom Version 8.2.2576 (170).

MacVim seems to render everything correctly when I start it up, but after it has been running for a while, any new windows (e.g., when trying to edit a file from the command line using mvim) pop up with no visible text anywhere.

The only way to fix the problem is to quit MacVim and start it again.

Please let me know if I can provide any other information.

@graywh
Copy link

graywh commented Mar 31, 2021

@ekortright Note that this was committed just a week ago and snapshot 170 is 3 weeks old.

@ychin
Copy link
Member

ychin commented Mar 31, 2021

Yeah I need to push an update with this fix. Will try to do tonight. Trying to go over other changes that went in and make sure they are ok.

ychin added a commit that referenced this issue Apr 1, 2021
Updated to Vim 8.2.2681.

This is a small update mostly containing a fix to rendering bug in Core
Text renderer.

Fixes
====================

- Fixed a rendering issue where MacVim would stop drawing text when the
  computer is running low on memory. Previously the user would have to
  restart MacVim in order to get the rendering back. #1164

Compatibility
====================

Requires macOS 10.9 or above.

Script interfaces have compatibility with these versions:

- Lua 5.4
- Perl 5.18
- Python2 2.7
- Python3 3.9
- Ruby 3.0
@ychin
Copy link
Member

ychin commented Apr 1, 2021

The update has been pushed so if you get the latest version it should be good now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Renderer Text rendering issues, including CoreText renderer
Projects
None yet
Development

Successfully merging a pull request may close this issue.