stackgl / headless-gl

🎃 Windowless WebGL for node.js
1.73k stars 166 forks source link

Does it works on replit? #277

Closed onchainyaotoshi closed 4 months ago

onchainyaotoshi commented 4 months ago

I also try to running with below scripts: xvfb-run :99 -screen 0 1280x1024x24 & export DISPLAY=:99; npm run start:live xvfb-run :99 -screen 0 1024x768x24 & export DISPLAY=:99; npm run start:live xvfb-run -s "-ac -screen 0 1024x768x24" npm run start:live xvfb-run --auto-servernum --server-num=1 -s "-ac -screen 0 1280x1024x24" npm run start:live

with gl version: "^6.0.2",

Errors:

THREE.WebGLRenderer: Error creating WebGL context. file:///home/runner/frame-cube/node_modules/three/build/three.module.js:28929 throw new Error( 'Error creating WebGL context.' ); ^

Error: Error creating WebGL context. at new WebGLRenderer (file:///home/runner/frame-cube/node_modules/three/build/three.module.js:28929:13) at CubeView.initScene (file:///home/runner/frame-cube/src/utils/rubik/cube-view.js:34:21) at new CubeView (file:///home/runner/frame-cube/src/utils/rubik/cube-view.js:12:10) at Rubik.renderToBase64 (file:///home/runner/frame-cube/src/utils/rubik/index.js:23:17) at renderFrameUnsolvedRubik (file:///home/runner/frame-cube/src/controllers/rubik-controller.js:32:18) at startSession (file:///home/runner/frame-cube/src/controllers/rubik-controller.js:72:5) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

dhritzkiv commented 4 months ago

Hi there.

I'm not familiar with replit, so I can't completely offer any advice on what may be going on there.

What output do you see if you run

xvfb-run --auto-servernum -s "-ac -screen 0 1024x768x24" `which glxinfo`
onchainyaotoshi commented 4 months ago

so i manage to install glxinfo and it returns:

/nix/store/00rxyj8xxpq1sadd3adm6q6ls7hx0rmx-mesa-demos-9.0.0/bin/glxinfo

if i run glxinfo without xvfb:

name of display: :0 Error: couldn't find RGB GLX visual or fbconfig

Screenshot_55

onchainyaotoshi commented 4 months ago

so i create a file check-gl.js to test it on replit which is a linux platform too.

import createGL from 'gl';

function delay(time) {
  return new Promise(resolve => setTimeout(resolve, time));
} 

const ctx = createGL(300, 300);
console.log("ctx", null);

await delay(5000);
throw new Error('finish');

and i run the script with:

xvfb-run --auto-servernum -s "-ac -screen 0 1024x768x24" node ./scripts/check-gl.js

and the result is "ctx null"

Screenshot_54

dhritzkiv commented 4 months ago

Have you made sure to install the relevant dependencies for your system?

Note: these dependencies vary by system, and I'm not familiar with the replit environment, so I can't advise more specifically.

onchainyaotoshi commented 4 months ago

I have installed all the necessary packages through replit.nix. Without these installations, the node-gyp build phase would not complete successfully.

{ pkgs }: {

  deps = [
      pkgs.vim-full
      pkgs.pciutils
    pkgs.postgresql
    pkgs.nodejs_20
    pkgs.python310Full

    #for node-gyp (build-essential)
    pkgs.gcc
    pkgs.gnumake

    #for gl & canvas
    pkgs.pkg-config
    pkgs.xvfb-run

    #for gl node-gyp build
    pkgs.mesa
    pkgs.mesa-demos

    #for fix couldn't find RGB GLX visual or fbconfig when run this shell command: xvfb-run --auto-servernum -s "-ac -screen 0 1024x768x24" glxinfo

    #for canvas 
    pkgs.cairo
    pkgs.pango
    pkgs.libjpeg
    pkgs.giflib
    pkgs.librsvg
    pkgs.libuuid
    pkgs.binutils

    # Add other dependencies here
  ];

  #https://github.com/Automattic/node-canvas/issues/1893#issuecomment-1096988007
  env = { 
    LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
      pkgs.libuuid
    ];
    PYTHONHOME = "${pkgs.python310Full}";
    PYTHONBIN = "${pkgs.python310Full}/bin/python3.10";
    LANG = "en_US.UTF-8";
  }; 
}
onchainyaotoshi commented 4 months ago

So, I am considering leaving it as is and migrating to another hosting site. Do you have any suggestions for hosting sites that might support these packages?

onchainyaotoshi commented 4 months ago

I just moved to DigitalOcean, and it works now. Thanks for your help, bro!

dhritzkiv commented 4 months ago

Glad you were able to get it to work.

Generally, it shouldn't depend on a specific hosting provider – it more so depends on the environment that you're trying to get it to work in, and what complications/restrictions it imposes. It's possible with more work you might have been able to get it set up in Replit/Nix, but it seems like there were an unknown number of obstacles in the way.