java - 为什么我的游戏在 Linux 上运行良好,但在 Windows 上运行不正常? (Java.jar)

标签 java linux windows multithreading jar

在 .jar 中部署我的游戏时,它在 Linux/Mac 上运行良好,没有错误。

但是在 Windows 上(目前专门测试 Windows 10),我在启动时遇到这些错误,然后在我的 JFrame 中出现空白屏幕:

Exception in thread "PooledThread7" java.lang.IllegalStateException: Buffers have not been created
    at sun.awt.windows.WComponentPeer.getBackBuffer(Unknown Source)
    at java.awt.Component$FlipBufferStrategy.getBackBuffer(Unknown Source)
    at java.awt.Component$FlipBufferStrategy.flip(Unknown Source)
    at java.awt.Component$FlipBufferStrategy.show(Unknown Source)
    at engine.Game$Render.render(Game.java:250)
    at engine.Game$Render.run(Game.java:167)
    at engine.PooledThread.run(ThreadPool.java:89)

java.io.FileNotFoundException: res\maps\map.txt (The system cannot find the path specified)
    at java.io.FileOutputStream.open0(Native Method)
    at java.io.FileOutputStream.open(Unknown Source)
    at java.io.FileOutputStream.<init>(Unknown Source)
    at java.io.FileOutputStream.<init>(Unknown Source)
    at java.io.FileWriter.<init>(Unknown Source)
    at engine.testMapCreator.init(testMapCreator.java:69)
    at engine.Game.init(Game.java:126)
    at engine.Game.main(Game.java:80)

Windows 似乎不喜欢我的线程池渲染,并且出于某种原因,虽然它在 Linux 上找到 .jar 中的映射文件,但在 Windows 上找不到它们。

...“一次编写,随处运行”就这么多吧?可能是什么问题?

编辑:这就是我阅读 map.txt 文件的方式:

InputStream is = Game.class.getResourceAsStream("/map.txt")
Scanner scanner = new Scanner(is);

(for loops to iterate over the data)

最佳答案

  1. 对于第一个错误,可能在命令行中添加 -Dsun.java2d.d3d=false 会有所帮助(禁止使用 Direct3D 进行 2D 渲染)。例如:

    java -Dsun.java2d.d3d=false -jar some.jar

  2. 至于第二个,我们需要看看你是如何写文件的(提到了FileWriter),它可能是例如你没有 res\maps 目录。

关于java - 为什么我的游戏在 Linux 上运行良好,但在 Windows 上运行不正常? (Java.jar),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36507875/

相关文章:

java - Netbeans profiler 保留内存计算错误?

java - Ajax 调用在 Android 模拟器 Web View 中不起作用

windows - 如何在批处理文件中生成输出文件的自动编号?

c++ - 后期绑定(bind)到具有 "extern"定义变量的库

linux - (open + write) 与 (fopen + fwrite) 到 kernel/proc/

c# - 清除面板的背景图像

java - 实现自定义连接池?

java - 如何在 Gradle 中生成元模型?

node.js - Bitbucket 管道运行 npm 失败

Linux 的 C++ 调试器类似于 MS Visual Studio 的调试器?