sudden-onset R-related 3dMVM crash

Gentlefolk:

I'm generating a null-hypothesis distribution using random permutations of group labels for a project I'm working on with Gang. The approach invokes 3dMVM. Disturbingly, several iterations of permutation go nicely and then all heck breaks loose rendering the following message:

*** caught segfault ***
address 0x0, cause 'invalid permissions'

Traceback:
1: dyn.load(file, DLLpath = DLLpath, ...)
2: library.dynam(lib, package, package.lib)
3: loadNamespace(package, lib.loc)
4: doTryCatch(return(expr), name, parentenv, handler)
5: tryCatchOne(expr, names, parentenv, handlers[[1L]])
6: tryCatchList(expr, classes, parentenv, handlers)
7: tryCatch({ ns <- loadNamespace(package, lib.loc) env <- attachNamespace(ns, pos = pos, deps, exclude, include.only)}, error = function(e) { P <- if (!is.null(cc <- conditionCall(e))) paste(" in", deparse(cc)[1L]) else "" msg <- gettextf("package or namespace load failed for %s%s:\n %s", sQuote(package), P, conditionMessage(e)) if (logical.return && !quietly) message(paste("Error:", msg), domain = NA) else stop(msg, call. = FALSE, domain = NA)})
8: library(data.table)
9: withCallingHandlers(expr, packageStartupMessage = function(c) tryInvokeRestart("muffleMessage"))
10: suppressPackageStartupMessages(library(data.table))
11: eval(ei, envir)
12: eval(ei, envir)
13: withVisible(eval(ei, envir))
14: source(find.in.path("lib_dataTable.R"))
15: eval(ei, envir)
16: eval(ei, envir)
17: withVisible(eval(ei, envir))
18: source(first.in.path("AFNIio.R"))
An irrecoverable exception occurred. R is aborting now ...
Segmentation fault

This has happened twice now. I did a full AFNI and R re-installation the first time and it worked for three permutation iterations. Suspiciously, each crash happened around 11:30 p.m. central european time. I suspect some tricksy remote management issues from my university.

Appending output (see below) from running afni_system_check.py -check_all.

Any advice appreciated!!

Paul

-------------------------------- general ---------------------------------
architecture:         64bit Mach-O
cpu type:             arm64
system:               Darwin
release:              25.5.0
version:              Darwin Kernel Version 25.5.0: Tue Jun  9 22:18:58 PDT 2026; root:xnu-12377.121.10~1/RELEASE_ARM64_T6000
distribution:         26.5.2
number of CPUs:       10
user:                 paulhamilton
apparent login shell: zsh
shell RC file:        .zshrc (exists)

--------------------- AFNI and related program tests ---------------------
which afni           : /Users/paulhamilton/abin/afni
afni version         : Precompiled binary macos_13_ARM: Jul  7 2026 
                     : AFNI_26.2.01 'Gordian III'
AFNI_version.txt     : AFNI_26.2.01, macos_13_ARM, Jul 07 2026, build
afnipy version       : AFNI_26.2.01
which python         : /opt/homebrew/opt/python/libexec/bin/python
python version       : 3.14.6
which R              : /usr/local/bin/R
R version            : R version 4.6.1 (aarch64-apple-darwin23)

instances of various programs found in PATH:
    afni    : 1   (/Users/paulhamilton/abin/afni)
    R       : 1   (/Library/Frameworks/R.framework/Versions/4.6/Resources/bin/R)
    python  : 1   (/opt/homebrew/Cellar/python@3.14/3.14.6/Frameworks/Python.framework/Versions/3.14/bin/python3.14)
    python2 : 0 
    python3 : 2 
      /opt/homebrew/Cellar/python@3.14/3.14.6/Frameworks/Python.framework/Versions/3.14/bin/python3.14
      /usr/bin/python3

testing ability to start various programs...
    afni                 : success
    suma                 : success
    3dSkullStrip         : success
    3dAllineate          : success
    3dRSFC               : success
    SurfMesh             : success
    3dClustSim           : success
    build_afni.py        : success
    uber_subject.py      : success
    3dMVM                : FAILURE
        
         *** caught segfault ***
        address 0x0, cause 'invalid permissions'
        
        Traceback:
         1: dyn.load(file, DLLpath = DLLpath, ...)
         2: library.dynam(lib, package, package.lib)
         3: loadNamespace(package, lib.loc)
         4: doTryCatch(return(expr), name, parentenv, handler)
         5: tryCatchOne(expr, names, parentenv, handlers[[1L]])
         6: tryCatchList(expr, classes, parentenv, handlers)
         7: tryCatch({    ns <- loadNamespace(package, lib.loc)    env <- attachNamespace(ns, pos = pos, deps, exclude, include.only)}, error = function(e) {    P <- if (!is.null(cc <- conditionCall(e)))         paste(" in", deparse(cc)[1L])    else ""    msg <- gettextf("package or namespace load failed for %s%s:\n %s",         sQuote(package), P, conditionMessage(e))    if (logical.return && !quietly)         message(paste("Error:", msg), domain = NA)    else stop(msg, call. = FALSE, domain = NA)})
         8: library(data.table)
         9: withCallingHandlers(expr, packageStartupMessage = function(c) tryInvokeRestart("muffleMessage"))
        10: suppressPackageStartupMessages(library(data.table))
        11: eval(ei, envir)
        12: eval(ei, envir)
        13: withVisible(eval(ei, envir))
        14: source(find.in.path("lib_dataTable.R"))
        15: eval(ei, envir)
        16: eval(ei, envir)
        17: withVisible(eval(ei, envir))
        18: source(first.in.path("AFNIio.R"))
        An irrecoverable exception occurred. R is aborting now ...
        Segmentation fault
    rPkgsInstall         : FAILURE
        
         *** caught segfault ***
        address 0x0, cause 'invalid permissions'
        
        Traceback:
         1: .Call("R_SUMA_HistString", ExecName, args, ohist)
         2: AFNI.command.history(ExecName, args, NULL)
         3: read.rPkgsInstall.opts.batch(args, verb = 0)
        An irrecoverable exception occurred. R is aborting now ...
        Segmentation fault

------------------------ dependent program tests -------------------------
checking for dependent programs...

which tcsh           : /bin/tcsh
tcsh version         : 6.21.00
which Xvfb           : /opt/X11/bin/Xvfb

checking for R packages...
    rPkgsInstall -pkgs ALL -check : FAILURE
        
         *** caught segfault ***
        address 0x0, cause 'invalid permissions'
        
        Traceback:
         1: .Call("R_SUMA_HistString", ExecName, args, ohist)
         2: AFNI.command.history(ExecName, args, NULL)
         3: read.rPkgsInstall.opts.batch(args, verb = 0)
        An irrecoverable exception occurred. R is aborting now ...
        Segmentation fault

R RHOME : /Library/Frameworks/R.framework/Resources

------------------------------ python libs -------------------------------

++ module loaded: matplotlib.pyplot
   module file : /opt/homebrew/lib/python3.14/site-packages/matplotlib/pyplot.py
   matplotlib version : 3.10.7

** failed to load module flask
-- flask is required

** failed to load module flask_cors
-- flask_cors is required

-------------------------------- env vars --------------------------------
PATH                       = /opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/pkg/env/global/bin:/opt/X11/bin:/usr/local/munki:/opt/homebrew/opt/python/libexec/bin:/Library/Frameworks/R.framework/Resources:/usr/local/gfortran/bin:/Users/paulhamilton/abin:/opt/homebrew/opt/python/libexec/bin:/opt/homebrew/opt/python/libexec/bin:/opt/homebrew/opt/python/libexec/bin:/opt/homebrew/opt/python/libexec/bin:/opt/homebrew/opt/python/libexec/bin:/opt/homebrew/opt/python/libexec/bin:/opt/homebrew/opt/python/libexec/bin:/opt/homebrew/opt/python/libexec/bin:/usr/local/gfortran/bin:/opt/homebrew/opt/python/libexec/bin

PYTHONPATH                 = 
R_LIBS                     = /Users/paulhamilton/sw/R-4.3.1
LD_LIBRARY_PATH            = 
DYLD_LIBRARY_PATH (sub-shell) = :/opt/X11/lib/flat_namespace
DYLD_FALLBACK_LIBRARY_PATH (sub-shell) = 
CONDA_SHLVL                = 
CONDA_DEFAULT_ENV          = 
CC                         = 
HOMEBREW_PREFIX            = /opt/homebrew

----------------------------- eval dot files -----------------------------
----------- AFNI $HOME files -----------

    .afnirc                   : found
    .sumarc                   : found
    .afni/help/all_progs.COMP : found

--------- shell startup files ----------

   -- considered operations: path, apsearch
   
   -- note: followers should not need edits, so edit flags should be 0
      (have 0 follower(s), which can be ignored)
   
   no modifications needed across 1 dot files
   
------------------------------ data checks -------------------------------
data dir : missing AFNI_data6
data dir : missing AFNI_data7
data dir : missing AFNI_demos
data dir : missing suma_demo
data dir : missing afni_handouts
atlas    : found TT_N27+tlrc  under /Users/paulhamilton/abin

------------------------------ OS specific -------------------------------
XQuartz version      : 2.8.5

which brew           : /opt/homebrew/bin/brew
brew version         : Homebrew 6.0.8

which git            : /usr/bin/git
git version          : git version 2.50.1 (Apple Git-155)
which gcc            : /usr/bin/gcc
gcc version          : Apple clang version 21.0.0 (clang-2100.1.1.101)

brew gcc(s)          : /opt/homebrew/bin/gcc-13
                       /opt/homebrew/bin/gcc-16
CommandLineTools SDK : MacOSX26.5.sdk

=========================  summary, please fix:  =========================
*  AFNI programs show FAILURE
*  missing R packages (see rPkgsInstall)
*  python library flask is required
*  python library flask_cors is required
*  insufficient data for AFNI bootcamp
   (see "Prepare for Bootcamp" on install pages)

Paul,

I ran into the same compatibility issue on my Mac: R version 4.6.x isn't playing nice with the current version of AFNI.

To fix this, I suggest pointing your environment back to an older, compatible R version (e.g. 4.5.3). You can update your symbolic link by running the following commands (you may need sudo for the /Library directory):

cd /Library/Frameworks/R.framework/Versions/
sudo rm Current
sudo ln -s 4.5xxx Current

In case 4.5xxx isn't already installed on your machine, you will need to download and install that version first.

Once the R path is reverted, go ahead and rebuild AFNI:

build_afni.py -build_root ~/afni_build
afni_system_check.py -check_all

Hopefully, this resolves the issue for you as well. Let me know how it goes.

Gang Chen

Thanks much, Gang.

Your fix worked just fine. My actual battle was with my version of R which insists on auto-updating itself and assigning Current to the most recent version of R every night around midnight. Got that fixed, too. Now just letting the permutations pile up. :star_struck:

Paul

Ha, the automatic R upgrade explains the mysterious midnight breakdown! Glad to hear the issue is fully resolved now.

Gang Chen

Argh. I got cocky and spoke too soon. I assumed that Homebrew auto-updates were the culprit so I added

HOMEBREW_NO_AUTO_UPDATE=1

to my .zshrc file but time went by and version 4.6 showed back up in /Library/Frameworks/R.framework/Versions linked to Current.

I don't have auto-updates turned on for R, either. I'll keep trying to find the culprit but let me know if I'm missing any obvious alternatives? Looking at activity logs on my machine, I see some suspicious looking stuff involving libxpc.dylib happening exactly when the unwanted update to R 4.6 occurs. Will dig more.

Take care,

Paul

Have you tracked down the culprit behind the automatic R upgrade yet, Paul?

Gang Chen

Thanks for checking in, Gang. I got distracted and haven't returned to this in the last week. I've disabled automatic updates in homebrew and running getOption("updateR.auto") on my 4.5-arm64 installation returns NULL. I'm on a managed computer and had considered that the sysadmins might have something running in the background to cause this mischief, but R is not in the managed software portfolio of our university.

I will have three weeks of vacation coming up and I'm going to take the cowards way out and make 4.5-arm64 Current, set the permutations running, and unplug my computer from the Internet while I'm gone. :scream:

Once I'm back and feeling fresh I'll try to dig into this problem more. Let me know if you have any ideas!

Hi Gang--

Some resolution to this mystery. It was, indeed, some well-meaning system administration by my home university that was auto-updating R. Problem now fixed and permutations are permuting...

All best,

Paul

Hi Paul,

Glad to hear you finally solved the mystery! Ironically, the exact same thing happened to me a few days ago: my institute-managed Mac laptop automatically switched R to version 4.6.1 as well.

What's the secret solution to fix it?

Gang Chen

Hi Gang—

Our IT guys provided the following (non) answer:

What caused the problem initially was the managed updates of the package R.

The "fix" is that we no longer provide managed updates to the R-package.

:upside_down_face: