You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Racket语言生成的.exe文件无法正常打开问题求助

Solution for Racket pict3d Executable Closing Immediately

The core issue here is that when running your code in the Racket/DrRacket IDE, the REPL keeps the process alive and automatically renders your pict3d scene. But when packaged as an executable, the program runs through your code once, creates the scene, then immediately exits—without waiting for you to close the window.

Here's how to fix this:

Step 1: Modify Your Code to Keep the Window Open

You need to explicitly tell your program to display the scene and wait for the window to close before exiting. The simplest way is to use the run-pict3d function, which handles rendering the scene and running the event loop until you close the window.

Here's the updated working code:

#lang racket
(require pict3d)

(run-pict3d
 (combine
  (with-color (rgba "red") (sphere (pos 1 0 0) 1/10))
  (with-color (rgba "blue") (sphere (pos 0 1 1) 1/10))
  (for/list ([t (in-range 1/10 1 1/10)])
    (define v (pos-between (pos 1 0 0) (pos 0 1 1) t))
    (sphere v 1/20))))

If you want more control over window management, you can split the logic into separate steps:

#lang racket
(require pict3d)

; Define your 3D scene
(define my-scene
  (combine
   (with-color (rgba "red") (sphere (pos 1 0 0) 1/10))
   (with-color (rgba "blue") (sphere (pos 0 1 1) 1/10))
   (for/list ([t (in-range 1/10 1 1/10)])
     (define v (pos-between (pos 1 0 0) (pos 0 1 1) t))
     (sphere v 1/20))))

; Show the scene and get a handle to the window
(define scene-window (show-pict3d my-scene))

; Wait until the window is closed before exiting the program
(wait-for-event scene-window 'close)

Step 2: Package Correctly with raco exe

Instead of relying on GRacket's export feature, use Racket's official command-line tool for reliable packaging:

  1. Save your updated code to a file (e.g., 3d-scene.rkt).
  2. Open a command prompt/terminal, navigate to the file's directory.
  3. Run this command to create an executable:
    raco exe 3d-scene.rkt
    
  4. For a standalone executable that doesn't require Racket to be installed on the target machine, use:
    raco distribute 3d-scene-dist 3d-scene.rkt
    
    This creates a folder 3d-scene-dist with your executable and all required dependencies bundled in.

Why This Works

  • run-pict3d starts the pict3d event loop, which keeps the program running as long as the window is open.
  • raco exe ensures all necessary libraries (including pict3d) are properly bundled into the executable, avoiding missing dependency issues that could cause crashes or premature exits.

内容的提问来源于stack exchange,提问作者Alik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:58:29