Vscode: Ubuntu vs code black screen on loading any file or project

Created on 15 May 2016  路  8Comments  路  Source: microsoft/vscode

  • VSCode Version:
  • OS Version: ubuntu 14.04.4 LTS

Steps to Reproduce:

  1. Open vs code
  2. Black screen on the vs code window

Most helpful comment

@johnhidey is correct, this will be removed when reinstalling via deb/rpm packages. The best way to force args like this is to use an alias to override the code command by putting this in your ~/.bashrc file:

alias code='code --disable-gpu'

All 8 comments

Same issue here

  • VSCode 1.1
  • Ubuntu 14.04.4 LTS

UPDATE:
Found the fix in the documentation. Somehow missed it. @ianaykh you fix it by launching vscode with the disable gpu flag: code --disable-gpu

Documentation found here: VS Code Main Windows is Blank

Thanks but do I have to do this every time I launch vs code from the terminal? Is there a permanent fix?

I see that there is an option to set preferences in vs code. Is there anyway that I can disable the gpu?

Disclaimer: I am not a Linux dev/regular user. I am in the process of learning Linux myself. I can not be held responsible for this failing or causing you grief.

Now that the disclaimer is out of the way here is what I did.
After installing via the .deb package, I edited the /usr/share/code/bin/code file using a text editor.

#!/usr/bin/env bash
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.

ARGS=$@

# If root, ensure that --user-data-dir is specified
if [ "$(id -u)" = "0" ]; then
    while test $# -gt 0
    do
        if [[ $1 == --user-data-dir=* ]]; then
            DATA_DIR_SET=1
        fi
        shift
    done
    if [ -z $DATA_DIR_SET ]; then
        echo "It is recommended to start vscode as a normal user. To run as root, you must specify an alternate user data directory with the --user-data-dir argument." 1>&2
        exit 1
    fi
fi

if [ ! -L $0 ]; then
    # if path is not a symlink, find relatively
    VSCODE_PATH="$(dirname $0)/.."
else
    if which readlink >/dev/null; then
        # if readlink exists, follow the symlink and find relatively
        VSCODE_PATH="$(dirname $(readlink $0))/.."
    else
        # else use the standard install location
        VSCODE_PATH="/usr/share/code"
    fi
fi

ELECTRON="$VSCODE_PATH/code"
CLI="$VSCODE_PATH/resources/app/out/cli.js"
ATOM_SHELL_INTERNAL_RUN_AS_NODE=1 "$ELECTRON" "$CLI" $ARGS
exit $?

Above is the original file that is installed via the .deb package. I added 1 line and modified another. The line that I added was DEFAULT_ARGS=--disable-gpu right before the ARGS=$@ line. Then at the bottom of the file I modified ATOM_SHELL_INTERNAL_RUN_AS_NODE=1 "$ELECTRON" "$CLI" $ARGS to be ATOM_SHELL_INTERNAL_RUN_AS_NODE=1 "$ELECTRON" "$CLI" $DEFAULT_ARGS $ARGS

Below is complete copy of the file which I modified.

#!/usr/bin/env bash
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.

DEFAULT_ARGS=--disable-gpu
ARGS=$@

# If root, ensure that --user-data-dir is specified
if [ "$(id -u)" = "0" ]; then
    while test $# -gt 0
    do
        if [[ $1 == --user-data-dir=* ]]; then
            DATA_DIR_SET=1
        fi
        shift
    done
    if [ -z $DATA_DIR_SET ]; then
        echo "It is recommended to start vscode as a normal user. To run as root, you must specify an alternate user data directory with the --user-data-dir argument." 1>&2
        exit 1
    fi
fi

if [ ! -L $0 ]; then
    # if path is not a symlink, find relatively
    VSCODE_PATH="$(dirname $0)/.."
else
    if which readlink >/dev/null; then
        # if readlink exists, follow the symlink and find relatively
        VSCODE_PATH="$(dirname $(readlink $0))/.."
    else
        # else use the standard install location
        VSCODE_PATH="/usr/share/code"
    fi
fi

ELECTRON="$VSCODE_PATH/code"
CLI="$VSCODE_PATH/resources/app/out/cli.js"
ATOM_SHELL_INTERNAL_RUN_AS_NODE=1 "$ELECTRON" "$CLI" $DEFAULT_ARGS  $ARGS
exit $?

@ianaykh This fix would most likely be overwritten when you install an update released for vscode

@johnhidey is correct, this will be removed when reinstalling via deb/rpm packages. The best way to force args like this is to use an alias to override the code command by putting this in your ~/.bashrc file:

alias code='code --disable-gpu'

ubuntu 16.10 vs code latest also work.

As a workaround, I have edited file /usr/share/applications/code.desktop

Replacing
Exec=/usr/share/code/code --unity-launch %U
with
Exec=/usr/share/code/code --disable-gpu --unity-launch %U
solved my problem of launching code through launcher.

Just in case one may need...

I run Ubuntu in Virtual Box and I get this behavior if "Enable 3D Acceleration" is checked in Virtual Box. After unchecking the box it loads fine. The --disable-gpu option also works. Atom.io also has the same issue. Hope this helps someone.

Was this page helpful?
0 / 5 - 0 ratings