简体   繁体   English

为什么我的游戏可以在Linux上正常运行,而不能在Windows上运行? (Java .jar)

[英]Why does my game run fine on Linux, but not in Windows? (Java .jar)

When deploying my game in a .jar, it runs fine with no errors on Linux / Mac. 在.jar中部署游戏时,它在Linux / Mac上运行正常,没有错误。

However on Windows, (specifically testing Windows 10 as of yet), I get these errors on launch and then a blank screen in my JFrame: 但是,在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)

and

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)

So it appears Windows is not liking my thread pool rendering, and for some reason while it finds the map files inside a .jar on Linux, it does not find them when on Windows. 因此,Windows似乎不喜欢我的线程池渲染,并且由于某种原因,虽然在Linux上在.jar中找到映射文件,但在Windows上却找不到它们。

... So much for "Write once, Run anywhere", right? ...“写一次,随处运行”就这么多了,对吧? What could be the problems? 可能是什么问题?

edit: This is how I am reading the map.txt files: 编辑:这就是我阅读map.txt文件的方式:

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

(for loops to iterate over the data)
  1. For the first error probably adding -Dsun.java2d.d3d=false to the command line will help (disable usage of Direct3D for 2D rendering). 对于第一个错误,可能在命令行中添加-Dsun.java2d.d3d=false会有所帮助(禁用将Direct3D用于2D渲染)。 Eg: 例如:

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

  2. As for the second one, we would need to see how you write the files (FileWriter is mentioned), it might be eg that you don't have res\\maps directory. 至于第二个,我们将需要查看如何编写文件(提到了FileWriter),例如,您可能没有res\\maps目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的jar在Windows而不是Linux上可以工作 - Why my jar works on windows and not on linux 如果 jar 文件具有 L 属性/重解析点,为什么 Java 应用程序无法在 Windows 上运行 - Why does Java application fail to run on Windows if jar file has L-attribute/reparse point 为什么我的Java应用程序在全屏模式下运行得如此之慢? (当窗口时很好) - Why does my Java application run so slowly in full-screen mode? (and fine when windowed) 为什么这不绘制我的多边形? (Java游戏) - Why does this not draw my Polygon? (Java game) 游戏事件运行正常,但场景无法渲染 - Game Events run fine, but scene does not render 为什么我的java -jar命令无法在我的shell中运行 - why my java -jar command can't run in my shell 如何使用第3方jar和我自己的jar在Linux中编译和运行Java - how to compile and run java in linux with 3rd party jar and my own jar 如何在Linux / Windows中运行Jar文件 - How to run Jar File in Linux/Windows 在Linux上运行Selenium WebDriver jar时出错(在Windows上运行正常) - Error while running selenium WebDriver jar on Linux (Working fine on Windows) 为什么我的 JAR 文件没有运行? (IntelliJ, JavaFX, Maven) - Why does my JAR file not run? (IntelliJ, JavaFX, Maven)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM