lwjglgamedev / lwjglbook-leg

Source code of the chapters of the book 3D Game Development with LWJGL 3
https://ahbejarano.gitbook.io/lwjglgamedev/
Apache License 2.0
560 stars 202 forks source link

Unable to load resources #69

Closed kaphula closed 4 years ago

kaphula commented 4 years ago

I cloned this project and opened it with Intellij IDEA and everything seems to build nicely, but when I try to run the chapters that include loading resources, the programs throw exceptions:

java.lang.Exception: Image file [textures/grassblock.png] not loaded: Unable to open file
    at org.lwjglb.engine.graph.Texture.loadTexture(Texture.java:43)
    at org.lwjglb.engine.graph.Texture.<init>(Texture.java:16)
    at org.lwjglb.game.DummyGame.init(DummyGame.java:50)
    at org.lwjglb.engine.GameEngine.init(GameEngine.java:40)
    at org.lwjglb.engine.GameEngine.run(GameEngine.java:27)
    at org.lwjglb.game.Main.main(Main.java:13)
java.lang.NullPointerException
    at org.lwjglb.game.DummyGame.cleanup(DummyGame.java:114)
    at org.lwjglb.engine.GameEngine.cleanup(GameEngine.java:69)
    at org.lwjglb.engine.GameEngine.run(GameEngine.java:32)
    at org.lwjglb.game.Main.main(Main.java:13)

Did I miss something obvious here? Do I need to manually edit the project configuration files somehow?

Changing absolute path for the texture filenames seems to fix the issue somewhat, but with chapter27 and Assimp aiImportFile seems to return null always.

lwjglgamedev commented 4 years ago

Hi,

It should run directly from IDEA. I've tested with chapter 7 (p2) and seems to work fine, are you sure that in your working directory there is a textures folder with the texture file in it ? Either you don't have that file or either your working directory is not the project's root.

If I recall correctly, the code that uses assimp the folder for textures is passed as a parameter. The null you are getting seems to be caused by the loading of the model itself.

Let me know if some of this helps.

kaphula commented 4 years ago

Hey, thanks for the quick reply. Setting the working directory correctly from the Run/Debug Configurations fixed the issue. I totally forgot that the working directory can be (and needs to be) set this way manually.