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