CheerpJ issue returned

Hello, I have been trying to publish my game (currently on a Jar file) to an html page. I am not sure if there are some things that I am currently during wrong since I am unable to get my desired result. I attached the output (both on the UI and the terminal) as well as the code I currently have. It would be appreciated if I can fix this ASAP. Thanks!
No description
No description
No description
35 Replies
apignotti
apignotti2mo ago
Please also attach the actual output in the browser console. This is the output in your terminal. Another important question. Does the game work when you run it with native java using the command java -jar PlatformGameProject.jar
Can eater
Can eaterOP2mo ago
I just checked that the game works when running with native java
No description
Can eater
Can eaterOP2mo ago
I am currently using wav files in my project btw (as shown in the repository: https://github.com/rentsdue/PlatformGameProject)
No description
Can eater
Can eaterOP2mo ago
It seems that CheerpJ doesn't support wav files?
apignotti
apignotti2mo ago
You are using an older version CheerpJ, please use a more modern version: https://cjrtnc.leaningtech.com/3_20241001_530/cj3loader.js
Can eater
Can eaterOP2mo ago
I thought I am using cheerpj3 though
apignotti
apignotti2mo ago
The above link is a new version of CheerpJ 3, it's a nightly build We will soon release CheerpJ 3.1, but it will take some more weeks
Can eater
Can eaterOP2mo ago
How do I integrate it into my project? I only copied the code from the website
apignotti
apignotti2mo ago
You simply change the <script> tag to reference this new version
Can eater
Can eaterOP2mo ago
I changed the <script> tag to reference this new version - however there are still issues with the code. It also seems to have the same error when I use the "TextDemo.jar" file instead. For reference I attached a copy of my code and project structure as well on this message. Thanks for the help one again!
No description
No description
No description
apignotti
apignotti2mo ago
That is a completely unrelated problem caused by an issue on our toolchains. Apologies, please try again with this build instead: https://cjrtnc.leaningtech.com/3_20241010_541/cj3loader.js
Can eater
Can eaterOP2mo ago
Sorry, it still seems to get the same error as the previous one Never mind the error is gone
Can eater
Can eaterOP2mo ago
Although I got a *bit of sound and the terminal outputs stuff as intended, the images from the game do not show up.
No description
Can eater
Can eaterOP2mo ago
This is the intended output btw (this project uses java.awt.Graphics and javax.swing.JPanel - is this the issue?)
No description
Can eater
Can eaterOP2mo ago
Once again thanks for your help!
apignotti
apignotti2mo ago
Swing is completely supported, that is not the problem. I cannot make any guess without further information though. Is there any other message in console beside the FPS ones? Can you confirm that all the images are included in the JAR and not loaded from elsewhere?
Can eater
Can eaterOP2mo ago
I got some more precise console messages, I am unsure how to fix them.
No description
No description
No description
Can eater
Can eaterOP2mo ago
Hopefully this is not something inherent to my game as it is runnable via cmd prompt. Tysm once more!
apignotti
apignotti2mo ago
None of those messages are errors, there is nothing to fix I suspect your jar might be loading images from other places in your system. Can you confirm that all the images are inside the jar? In other words, how do you load the images in the Java code? Are you loading them using system paths like c:\users\...\image.jpg?
Can eater
Can eaterOP2mo ago
public static BufferedImage[] GetAllLevels() {
List<String> levelNames = Arrays.asList("1.png", "2.png", "3.png", "4.png", "5.png", "6.png", "7.png", "8.png", "9.png", "10.png");
BufferedImage[] levels = new BufferedImage[levelNames.size()];

for (int i = 0; i < levels.length; i++) {
try (InputStream is = LoadSave.class.getResourceAsStream("/levels/" + levelNames.get(i))) {
if (is == null) {
System.err.println("File not found: " + levelNames.get(i));
System.exit(1);
}
levels[i] = ImageIO.read(is);
} catch (IOException e) {
e.printStackTrace();
}
}

return levels;
}
public static BufferedImage[] GetAllLevels() {
List<String> levelNames = Arrays.asList("1.png", "2.png", "3.png", "4.png", "5.png", "6.png", "7.png", "8.png", "9.png", "10.png");
BufferedImage[] levels = new BufferedImage[levelNames.size()];

for (int i = 0; i < levels.length; i++) {
try (InputStream is = LoadSave.class.getResourceAsStream("/levels/" + levelNames.get(i))) {
if (is == null) {
System.err.println("File not found: " + levelNames.get(i));
System.exit(1);
}
levels[i] = ImageIO.read(is);
} catch (IOException e) {
e.printStackTrace();
}
}

return levels;
}
It seems that I am loading them with system paths (and all the images are found within the "res folder" of my repository If this is the issue, do I need to fix this by changing the way images are rendered in my jar file? As I am a beginner to java programming, I am unsure how to proceed forwards with this step. Thanks again!
apignotti
apignotti2mo ago
I don't this the problem is here. If the image could not be loaded you would get an error message Can you verify that you don't get a "File not found" error at the very end of the console log?
Can eater
Can eaterOP2mo ago
When I run it on my laptop nothing happens (no file error, jar file works perfectly), but I did find 1 error message
No description
No description
apignotti
apignotti2mo ago
The error message is not fatal, ignore it I don't think the problem is connected to the images. The best approach I can suggest is to add error messages in Java to understand when the code stop. You can also share with us the JAR and we can take a look, but we are currently very busy and won't be able to help for several weeks
Can eater
Can eaterOP2mo ago
https://github.com/rentsdue/PlatformGameProject The jar file is on this repository (I couldn't send it via discord since I don't have Nitro).
GitHub
GitHub - rentsdue/PlatformGameProject
Contribute to rentsdue/PlatformGameProject development by creating an account on GitHub.
apignotti
apignotti2mo ago
As far as I can see the jar is not included in this repo
Can eater
Can eaterOP2mo ago
I think it can be accessed via this google drive link Thanks for all the help so far!
apignotti
apignotti2mo ago
I could only take a quick look, but I think I have a good idea why the game does not work. The problem is that you have thread that is spinning forever, without ever pausing. This is a not a great idea, as it wastes lots of CPU power, but it works with native Java since the other threads can still run. But in the browser there is only one single thread, and CheerpJ runs all the Java threads on top of this single thread. If a thread never stops, other threads never run Try to put a short sleep or Thread.yield in your game main loop
Can eater
Can eaterOP2mo ago
Thanks a lot for your help - while I could get the game to show up, it is still extremely slow. Nonetheless, thanks a lot for nudging me in the correct direction regarding modifying my game loop! At least the video game displayed this time... speeding up the FPS and the speed of the game rn on CheerpJ is the main issue for me atm
apignotti
apignotti2mo ago
Just to be sure, are you keeping the developer tools open? They slow down the execution by a lot Putting this side, it is quite likely that to run the game at good speed you need support for graphical acceleration that CheerpJ does not support at this time.
Can eater
Can eaterOP2mo ago
Sorry I am unsure of what you mean by developer tools. Since I'm relatively new to java programming what are some examples that I should check in my code for?
apignotti
apignotti2mo ago
"Developer tools" are the browser tools to debug code. The one with the console with the FPS lines being printed out. Keeping that open significantly worsen performance
Can eater
Can eaterOP2mo ago
Aka the console line?
apignotti
apignotti2mo ago
The browser console, unsure what you are referring to with 'line'
Can eater
Can eaterOP2mo ago
Thanks It is still pretty slow but I am trying to reduce the FPS and UPS of the game and see if there's a difference
Want results from more Discord servers?
Add your server