Exported Application freezing on MacOS

I am making a game with Processing 3, and it runs perfectly in the PDE; although, when I export the application and run it, the game freezes when a certain method is called: gameOver(). The gameOver() method is called whenever the player is hurt by an enemy (which is whenever an enemy touches the player).

The only thing that I can think of is that it loads an image, but I have used the add file button to add the image and everything.

I'm running macOS Sierra 10.12.6.

Here is the link to the code and applications. http://www.mediafire.com/folder/seq00jfeqsl69/Open_Desktop_Adventure

Answers

  • Could you just post the relevant code here?

    You really should do all you image loading in setup(). Maybe your gameOver() function is being called every frame, and thus the image is being reloaded every frame? (This wouldn't happen if you loaded it in setup()).

  • I'm not quite sure which code is relevant, because the gameOver() method references other methods and variables that the program uses.

    All images are loaded within setup().

    gameOver is called every frame the player is touching the enemy, but the inside only executes every 30 frames after the method is initially called.

  • edited January 2018

    I hope this is relevant (these are fragments from different classes, not continuous):

      if (hurtCooldown.value < 30) {
        hurtCooldown.inc();
        indicateDamage = true;
      } else {
        indicateDamage = false;
      }
    
        if (touchingPlayer) {
          if (holdingItem && items[holdingItemIndex].itemType == "sword" && ((playerPos.y >= enemyPos.y) && (playerPos.x <= enemyPos.x))) {
            destroy();
          } else {
            gameOver();
          }
        }
    
    void gameOver() {
      if (hurtCooldown.value >= 30) {
        playerHealth--;
        hurtCooldown.reset();
      }
      if (playerHealth <= 0) {
        gameEnd("die");
      }
    }
    
    void gameEnd(String tempResults) {
      onEndScreen = true;
      gameResults = tempResults;
    }
    
    void drawHealth() {
      if (indicateDamage) {
        tint(#FF0000);
      } else {
        noTint();
      }
      if (playerHealth == 3) {
        image(health3, 0, 0, 90, 30);
      }
    
      if (playerHealth == 2) {
        image(health2, 0, 0, 90, 30);
      }
    
      if (playerHealth == 1) {
        image(health1, 0, 0, 90, 30);
      }
    
      if (playerHealth == 0) {
        image(health0, 0, 0, 90, 30);
      }
    }
    
  • I replaced every time I had a String == String with the String.equals(String), but it didn't fix the issue I am having.

  • I've narrowed down where the source of the problem is by disabling different parts of the code, but the program only freezes when it decrements the playerHealth variable.

  • Aha! It appears as though I have made the simple mistake of forgetting to put some of the images in the data folder! It's working just fine now!

  • Congrats @thesuperdaine -- I love a happy ending. Thank you for telling us how it worked out.

    If problems like this are really hard to track down then you can use try/catch blocks to print or log the error message to a text file. They aren't used much in sketches, but can be very useful for exported apps when all else fails.

Sign In or Register to comment.