App freezes or seems unresponsive. APDE gives no errors.

edited April 2017 in Android Mode

Hi guys,

I've been using APDE for not too long now and I can't seem to get my sketch (which is running fine on my PC) to run on my tablet.

I've tried a bunch, but can't seem to get it to work.

This is the code:

PImage img, clk, sad, smile, itemIcon, sad_p, smile_p;
Animation rose;
int sep = 175;
int sel = 1;
int t = 101;
float opac = 0;
int frm = 350;
int event = 0;
boolean go = false;
int delay = 50;
int op = 2;
int item = 0;
int time = 0;
int moveBy = 120;
int textX = 105;
int textY = 35;
boolean animationReady = false;
void setup() {
  fullScreen ();
  frameRate  (10);
  orientation(LANDSCAPE);
  smile = loadImage("icons/smiley.png");
  sad = loadImage("icons/sad.png");
  sad_p= loadImage("icons/druksad.png");
  smile_p= loadImage("icons/drukblij.png");
  background(0);
  text("Loading...", 10, 10);
}
void draw() {
  if (animationReady == false) {
    rose = new Animation ("rose/rose ", 66);
    rose.loadAnimation();
  }
  if (t > delay && event != 2) {
    switch (event) {
    case 0:
      break;
    case 1:
      event = 2;
      break;
    case 2:
      event = 0;
      break;
    case 3:
      event = 0;
      break;
    }
    sel++;
    opac = 0;
    if (sel == 4) {
      sel = 1;
    }
    go = true;
    t=0;
    if (event == 0) {
      img = loadImage("family"+sel+".jpg");
    }
  }
  t++;
  if (go == true) {
    tint(255, opac);
    imageMode(CENTER);
    image(img, width/2, height/2, width, height);
    if (event == 3) {
      rose.display(width/2, height/2);
    }
    if (event == 1) {
      fill(0);
      rect(0, 0, width, 50);
      fill(255);
      textSize(30);
      switch (item) {
      case 1:
        text("Om 8 uur begint het ontbijt. Smakelijk eten!", textX, textY);
        break;
      case 2:
        text("Om 1 uur ga je kaarten. Veel succes!", textX, textY);
        break;
      case 3:
        text("Om 3 uur ga je zingen in het koor. Veel plezier!", textX, textY);
        break;
      case 4:
        text("Om 2 uur ga je even lekker koffie drinken.", textX, textY);
        break;
      case 5:
        text("Om 1 uur ga je even schilderen. Maak er iets moois van.", textX, textY);
        break;
      case 6:
        text("Om 7 uur ga je douchen.", textX, textY);
        break;
      case 7:
        text("Om 4 uur moet je je kamer opruimen.", textX, textY);
        break;
      case 8:
        text("Om 2 uur begint de wedstrijd. Neem maar vast plaats achter de TV!", textX, textY);
        break;
      case 9:
        text("Om 12 uur ga je zwemmen.", textX, textY);
        break;
      }
      image(clk, width/2-sep, height/2, frm, frm);  
      image(itemIcon, width/2+sep, height/2, frm, frm);
    }
    if (event == 2) {
      fill(0);
      rect(0, 0, width, 50);
      fill(255);
      textSize(30);
      sep = sep + 290;
      switch (item) {
      case 1: 
        text("Hoe was het ontbijt?", textX, textY);
        break;
      case 2:
        text("Hoe was het kaarten?", textX, textY);
        break;
      case 3:
        text("Hoe ging het zingen?", textX, textY);
        break;
      case 4:
        text("Hoe was de koffie?", textX, textY);
        break;
      case 5:
        text("Vond je het schilderen leuk?", textX, textY);
        break;
      case 6:
        text("Vond je het douchen fijn?", textX, textY);
        break;
      case 7:
        text("Vind je het leuk om je kamer op te ruimen?", textX, textY);
        break;
      case 8:
        text("Hoe was de wedstrijd?", textX, textY);
        break;
      case 9:
        text("Vond je het zwemmen leuk?", textX, textY);
        break;
      }
      image(sad, width/2-sep, height/2-moveBy, frm, frm);  
      image(smile, width/2+sep, height/2-moveBy, frm, frm);
      image(sad_p, (width/2-sep)-frm/2+(frm/5)/2, (height/2-frm/2)-moveBy, frm/5, frm/5);
      image(smile_p, (width/2+sep)-frm/2+(frm/5)/2, (height/2-frm/2)-moveBy, frm/5, frm/5);
      if (mousePressed == true &&
        mouseX > ((width/2-sep)-frm/2) &&
        mouseX < ((width/2-sep)+frm/2) &&
        mouseY > ((height/2)-frm/2) &&
        mouseY < ((height/2)+frm /2)) {
        event = 3;
        op = 0;
      }
      if (mousePressed == true &&
        mouseX > ((width/2+sep)-frm/2) &&
        mouseX < ((width/2+sep)+frm/2) &&
        mouseY > ((height/2)-frm/2) &&
        mouseY < ((height/2)+frm /2)) {
        event = 3;
        op = 1;
      }
      sep = 175;
    }
    if (event == 3) {
      fill(0);
      rect(0, 0, width, 50);
      fill(255);
      textSize(30);
      text("Dankjewel voor de reactie!", textX, textY);
    }
    if (opac == 255) {
      go = false;
    }
    opac = opac + 25;
  }
}
void touchStarted() {
  if (event == 0) {
    opac = 0;
    img = loadImage("items/item (" + item + ").jpg");
    switch (item) {
    case 0:
      time = 8;
      break;
    case 1:
      time = 1;
      break;
    case 2:
      time = 3;
      break;
    case 3:
      time = 2;
      break;
    case 4:
      time = 1;
      break;
    case 5:
      time = 7;
      break;
    case 6:
      time = 4;
      break;
    case 7:
      time = 2;
      break;
    case 8:
      time = 12;
      break;
    }
    clk = loadImage("icons/time/"+ time +"u.png");
    switch (item) {
    case 0:
      itemIcon = loadImage("icons/tafel.png"); 
      break;
    case 1:
      itemIcon = loadImage("icons/kaart1.png"); 
      break;
    case 2:
      itemIcon = loadImage("icons/koor1.png"); 
      break;
    case 3:
      itemIcon = loadImage("icons/koffie1.png"); 
      break;
    case 4:
      itemIcon = loadImage("icons/schilderen1.png"); 
      break;
    case 5:
      itemIcon = loadImage("icons/douchen1.png"); 
      break;
    case 6:
      itemIcon = loadImage("icons/opruimen1.png"); 
      break;
    case 7:
      itemIcon = loadImage("icons/voetbal1.png"); 
      break;
    case 8:
      itemIcon = loadImage("icons/zwem1.png"); 
      break;
    }
    event = 1;
    go = true;
    t=0;
    item++;
  }
  if (event == 2) {
    event = 0;
    t=0;
  }
}
class Animation {
  PImage[] images;
  int imageCount;
  int frame;
  boolean getImages = false;
  String imageName = "";
  Animation(String imagePrefix, int count) {
    imageCount = count;
    images = new PImage[imageCount];
    imageName = imagePrefix;
  }
  void loadAnimation() {
    for (int i = 0; i < imageCount; i++) {
      String filename = imageName + "(" + i + ").jpg"; 
      images[i] = loadImage(filename);
    }
    animationReady = true;
  }
  void display(float xpos, float ypos) {
    frame = (frame+1) % imageCount;
    image(images[frame], xpos, ypos, width, height);
  }
  int getWidth() {
    return images[0].width;
  }
}

When I run the sketch on APDE it builds my app, I install it and run it as usual. It shows a black screen with the text "loading..." in the top left corner, just like I programmed it. But that's it. It doesn't continue from there. No errors or anything.

Can any of you tell what might be causing this?

All the best,

  • Ryan

PS: Sorry for the formatting of my program. When you program in a hurry it can never be good...

Tagged:

Answers

  • edited April 2017

    @Qcode===

    difficult to help you what P5 version? what version of the android mode? what .... (perhaps you have to create a runnable for your images downloaded in setup(), android does not like that!!)

  • Processing version 3.0.1, android mode version 3.0.2, android version 4.4.2.

  • Ryan,

    First check is to make sure a simple app works. Something like this:

    void setup(){fullScreen();}
    
    void draw(){
      fill(random(256),random(256);random(256));
      ellipse(mouseX,mouseY,100,100);
    }
    

    Based on your description, it looks like your program is loading properly. Do you get any error in the console at all? You might also want to add some println statements to check the state of your program where it seems to get stuck.

    Btw, have you run other apps before on your phone?

    Below from a previous post: https://forum.processing.org/two/discussion/comment/94848/#Comment_94848

    Kf


    Processing version

    Android mode Version

    Operating system

    Target APIs you have tried (Installed through the Android SDK manager and visible in the Processing IDE Android mode)

    Android SDK version. Did you install it yourself or using the automatic installation offered by the Processing IDE android mode?

    Have you run Android apps in Processing before? In any other SDK like Eclipse or Android Studio (AS)?

    Is this your first time? Did you enabled the developer mode in your device?

    did you check the following website as a reference: http://android.processing.org/install.html Did you try any other set of instructions? Which ones? Can you provide your link?

    Are you running your app in an actual device or through an emulator? (NOTE: It is strongly recommended to do it on an actual device)

    In case you found something meaningful in the forum or in other site, please provide links (If nothing found... leave blank).

    Have you tried anything else? For example, renaming/removing the manifest and letting Processing recreate the manifest for you again? (To access the manifest, press ctrl+k in your sketch and there should be a file called "manifest.xml")

    EDITED:****** Extra questions as suggested by akenaton

    Have you activated the debug mode on your phone + what is your phone OS ? ) + give us more error code (not only the first 2 lines)

  • edited May 2017

    Hey thanks for the quick responses!

    The example sketch you send did run successfully without any problems.

    The first few times I ran it, it generated no issues. Now, it generates a null pointer exception and the app closes or freezes (apparently randomly). I do notice that when it manages to start, it does rotate the screen into the landscape orientation. I'm not to sure why it does that, while it doesn't show the println that I put in front of it. I've added println("setup started"); and println("setup finished"); to the setup function, and another println at the end of the draw function. None of them show in the console.

    If it helps, I'm not running this on an emulator of any kind, I'm running this on my Samsung Galaxy Tab 3, and I'm programming it through the APDE app. However, I've programmed it on my PC first, got it running there and then migrated it to the tablet, for it to be loaded into APDE. I put everything where it's supposed to be, data folders and all images are present inside the "sketchbook" folder of the device. I'm running the device in developer mode. You have the entire program's code, so no secrets there.

    Thanks again for helping me out here.

    EDIT: I just reinstalled the app entirely, by manually uninstalling it. Now it ran for about half a second showing the "loading..." text which is in the setup function. However, it still does not print to the console and stops almost immediately after running.

  • APDE.... Sorry, not much experience with it. Maybe @hudson_m4000 can help? He has some experience working with APDE.

    I could try running your code via APDE in few hours. Do you have a link for instructions of how to operate the APDE app? In the meantime, have you run your app from the Processing IDE in Android mode directly? If running it from the Processing IDE works, then we can figure there could be some sort of bug in the APDE app. That is a first thing to do for starters.

    Kf

  • Can you provide your images?

    Kf

  • Download the data folder here.

    These are the exact files I got working on my pc.

    Please note: In order for this to work, you'll have to change this bit:

        switch (item) {
            case 0:
              itemIcon = loadImage("icons/tafel.png"); 
              break;
            case 1:
              itemIcon = loadImage("icons/kaart1.png"); 
              break;
            case 2:
              itemIcon = loadImage("icons/koor1.png"); 
              break;
            case 3:
              itemIcon = loadImage("icons/koffie1.png"); 
              break;
            case 4:
              itemIcon = loadImage("icons/schilderen1.png"); 
              break;
            case 5:
              itemIcon = loadImage("icons/douchen1.png"); 
              break;
            case 6:
              itemIcon = loadImage("icons/opruimen1.png"); 
              break;
            case 7:
              itemIcon = loadImage("icons/voetbal1.png"); 
              break;
            case 8:
              itemIcon = loadImage("icons/zwem1.png"); 
              break;
            }
    

    To this:

    itemIcon = loadImage ( "icons/itemIcon"+ item + ".png");

    If it works, it should show a slideshow of some very cringy stock photos. The important part is that it should show a notification screen with black and white icons when you touch the screen.

    Thanks a lot for trying this out!

  • I will try it later today. I let you know as I am getting familiar with the app.

    Kf

  • edited May 2017

    @kfrajer I'm not an APDE user much ... easier to just use my laptop. I do use AIDE though for final apk production.

  • I had a similar issue with similarly hurried code, filled with images and timed changes. The app was running, but it was painfully slow. Changing the frame rate did nothing either. But if I changed the t++ to t+=3 It started to work. I only had this problem on my Polaroid 7 tablet. It works great on a galaxy tab 4. I don't know if this is related to your problem, but everything is worth exploring.

  • I found that one of the biggest culprits was the sheer amount of loadImage instances. It was running out of memory often. So I tried to optimize the code as much as possible with changes such as the one in my post from may 2nd. I also compressed each image. Now it works semi-fine. It's not perfect but optimization will fix a lot, I hope.

  • edited May 2017 Answer ✓

    In general: Do not use loadImage() in draw().

    Constantly reloading image files at 60fps is a huge performance issue in any version of Processing (or really any language).

    Use loadImage() in setup, or for spaced out events when you cannot preload.

Sign In or Register to comment.