hajimehoshi / ebiten

Ebitengine - A dead simple 2D game engine for Go
https://ebitengine.org
Apache License 2.0
11.02k stars 660 forks source link

Crazy CPU usage when running inside Docker #3062

Closed mcuadros closed 3 months ago

mcuadros commented 3 months ago

Ebitengine Version

v2.7.8

Operating System

Go Version (go version)

1.22

What steps will reproduce the problem?

You can run the 2048 example inside a docker container executing this command (in Linux):

 docker run -it --rm \                                                                    
          --net=host \
          --env="DISPLAY" \
          ghcr.io/mcuadros/ebiten-environment:1.22-bookworm \
          go run github.com/hajimehoshi/ebiten/v2/examples/2048@latest

If, for security reasons you rather not use a docker image, you can generate it using this docker file:

FROM golang:1.22-bookworm

RUN apt-get update && apt-get -y --no-install-recommends install \
    # common
    unzip wget build-essential cmake curl git sudo pkg-config \
    # ebiten
    libc6-dev libgl1-mesa-dev libxcursor-dev libxi-dev libxinerama-dev \
    libxrandr-dev libxxf86vm-dev libasound2-dev libswresample4 && \
    # cleanup
    rm -rf /var/lib/apt/lists/*

What is the expected result?

Normal CPU usage, the same when its running directly on the host

What happens instead?

When ebiten engine runs inside of a docker container, the CPU usage is extremely high close to 100% in all the CPUs.

Anything else you feel useful to add?

No response

mcuadros commented 3 months ago

Problem solved. It looks like ebiten needs access to /dev/dri

 docker run -it --rm \                                                                    
          --device /dev/dri \
          --net=host \
          --env="DISPLAY" \
          ghcr.io/mcuadros/ebiten-environment:1.22-bookworm \
          go run github.com/hajimehoshi/ebiten/v2/examples/2048@latest