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

时间:2016-04-08 19:32:31

标签: 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 个答案:

答案 0 :(得分:0)

  1. 对于第一个错误,可能将-Dsun.java2d.d3d=false添加到命令行将有所帮助(禁用Direct3D用于2D渲染)。 E.g:

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

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