Skip to content

Visual Studio Code Snap Crashes on Ubuntu 22.04 with "read out of range" Error

Problem Statement

Visual Studio Code installed via Snap crashes immediately on startup in Ubuntu 22.04, showing repeated [ERROR:process_memory_range.cc(75)] read out of range errors in terminal logs. This issue occurs with the May 2024 release (v1.90) and is caused by compatibility problems between VS Code's GPU acceleration features and Ubuntu's environment when using the Snap package. The crash prevents VS Code from launching, impacting developers needing reliable editor access.

WARNING

These solutions apply specifically to Snap installations. Remove other installations with sudo snap remove code or sudo apt remove code before proceeding.

1. Add GPU Workaround Flag (Temporary Fix)

Run VS Code with the --in-process-gpu flag to disable GPU process isolation:

bash
code --in-process-gpu

To apply this permanently to desktop shortcuts:

  1. Copy the .desktop file locally:

    bash
    cp /var/lib/snapd/desktop/applications/code_code.desktop ~/.local/share/applications/
  2. Edit the desktop file:

    bash
    nano ~/.local/share/applications/code_code.desktop
  3. Add --in-process-gpu to all Exec lines (before %F or %U):

    ini
    Exec=env ... /snap/bin/code --in-process-gpu %F
  4. Update desktop database:

    bash
    update-desktop-database ~/.local/share/applications

Why this works: This flag bypasses the problematic GPU process separation, eliminating the memory-range crash.

2. Revert to Stable Snap Version (One-Time Downgrade)

Revert to the last known stable version (v1.89.1):

bash
sudo snap revert code

Verify the version after reverting:

bash
code --version
# Should output: 1.89.1 [...]

Why this works: Avoids bugs introduced in v1.90. Future Snap updates may resolve the issue – wait before re-updating.

3. Install Official .deb Package (Snap Alternative)

For a permanent non-Snap solution:

  1. Remove the Snap version:

    bash
    sudo snap remove code
  2. Add Microsoft's repository:

    bash
    sudo apt install -y wget gpg apt-transport-https
    wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | sudo tee /usr/share/keyrings/vscode.gpg > /dev/null
    echo "deb [signed-by=/usr/share/keyrings/vscode.gpg] https://packages.microsoft.com/repos/code stable main" | sudo tee /etc/apt/sources.list.d/vscode.list
  3. Install VS Code:

    bash
    sudo apt update && sudo apt install code

Explanation and Best Practices

  • GPU Workaround vs. Revert: Use --in-process-gpu if you need v1.90 features. Revert if you prefer version stability.
  • .deb Installation: The most robust solution but forfeits Snap's containerization benefits.
  • Expected Fix: Microsoft is aware of the issue (GitHub #212494). Monitor updates using:
    bash
    sudo snap refresh --list

Verify Your Environment

After applying any solution, confirm functionality with:

bash
code --verbose

Ensure no ERROR:process_memory_range.cc appears in logs.