jalvesaq / Nvim-R

Vim plugin to work with R
GNU General Public License v2.0
968 stars 126 forks source link

`Error: C stack usage `\d+` is too close to the limit` #738

Closed iago-pssjd closed 1 year ago

iago-pssjd commented 1 year ago

Sometimes (at least, possibly only, on Windows) I get errors of this kind, for example:

> Error: C stack usage  1686122784 is too close to the limit
nvimcom error executing command: slotNames(fit)

when I change ViM mode to insert mode, where fit is a fitted model in my code and I did not use slotNames.

Another example is after trying to use \rh on a function in my R code,

> Error: C stack usage  1686120464 is too close to the limit

Why may it happen?

jalvesaq commented 1 year ago

This happens when PROTECT() and UNPROTECT() are unbalanced in C code. They may become unbalanced because there is an uneven number of them in the code (which should not be the case) or when some code is executed while a PROTECT/UNPROTECT block is being executed. To prevent this, on Unix (Linux, Mac OS, BSD, etc.) there is a function suggested by Simon Urbanek (please, seek his name in src/nvimcom.c) that postpones the execution of the code until R is ready. This solution is not available for R on Windows.

In my experience, R crashes not long after C stack error message.

iago-pssjd commented 1 year ago

Thanks! @jalvesaq

This solution is not available for R on Windows.

Ok, therefore I will close the issue.

In my experience, R crashes not long after C stack error message.

Indeed, this is being my experience too.

jalvesaq commented 1 year ago

The more frequent the communication between (Neo)Vim and R, the higher the chance of Nvim-R asking R to execute a command while it is still busy doing something else. The suspects are:

  1. Auto completion with cmp-nvim-r (main suspect).
  2. Object Browser
  3. Automatic updating of syntax highlighting when a new package is loaded.

nvimcom seemed to be stable when I tried Nvim-R on a Windows virtual machine for the last time (some months ago), but I have never tried nvim-cmp on Windows. If you could identify what feature (or plugin, in the case of cmp-nvim-r) is causing the C stack error, I would disable that feature/plugin for Windows.

iago-pssjd commented 1 year ago

I will check if I have cmp-nvim-r installed and if I don't get this issue after cleaning it (and I'll let you know). I didn't have activated the Object Browser. What I do sometimes is resizing (g)ViM windows. May have it some relation?

jalvesaq commented 1 year ago

Yes, when the terminal is resized, Nvim-R sends a message to nvimcom to check the new width in the environment variable COLUMNS. Then, nvimcom will run the command options(width=X), where X is the value of COLUMNS.

Actually, the documentation says that on Windows the command is sent to R Console, and not to nvimcom.

iago-pssjd commented 1 year ago

I confirm you I did not have installed cmp-nvim-r. I will try not resizing windows while R code is being executed and let's see if I don't get this issue.

jalvesaq commented 1 year ago

There are many places in the Vim code that I check if (Neo)Vim was compiled on Windows --- has("win32") --- when in fact I should check if R was compiled on Windows. I don't know if someone can run Nvim-R within a Unix version of Gvim (from a Linux subsystem) and a native Windows version of R. If yes, then Nvim-R will wrongly assume that R was also compiled on Unix.