Author Topic: updateRect() causes Android App to Crash  (Read 755 times)

AKotowski

  • RFduino Jr. Member
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
updateRect() causes Android App to Crash
« on: July 17, 2017, 10:03:12 AM »
I writing an Android UI. Everything is working except updationg rectangles.  A single call to update a rectangle causes the app to stop with an error message on the phone.
I am using Android V 7.0, Simblee 1.1.3.  Here is the update fragment. 
Code: [Select]
      if (SimbleeForMobile.updatable){
        SimbleeForMobile.updateValue(signalField, signal_Strength*100);
//        SimbleeForMobile.updateRect(ssIndicatorField, ssindicatorX-20, ssindicatorY, int(ssLength), ssWidth);
//        SimbleeForMobile.updateRect(ssIndicator2Field, ssindicatorX-22, ssindicatorY-2, 104 , ssWidth+4);               
        SimbleeForMobile.updateColor(ssIndicator2Field, YELLOW);               
      };

If I un-comment either of the commented lines the crash occurs.

Any suggestions, comments?

THanks

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: updateRect() causes Android App to Crash
« Reply #1 on: July 17, 2017, 03:28:02 PM »
Need more info. Can't tell what you are doing with just those calls. So have to guess. For example if your ssWidth is mean to be the width of you bar indicator(assuming you are using the rectangle as a bar graph. Then perhaps you have it in the wrong location. The fifth field is the height of the rectangle. The forth field is the width of the rectangle. So, I don't, perhaps you are exceeding the range. Just guessing. How about posting a complet sketch that should work if the two lines worked. In other words, don't need the whole project... Just a test script to get just this part your project tested out.

AKotowski

  • RFduino Jr. Member
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: updateRect() causes Android App to Crash
« Reply #2 on: July 17, 2017, 05:27:07 PM »
Thanks, good thought about index values.  Here with constant numbers:

Code: [Select]
void createDebug1Screen()
{
  SimbleeForMobile.beginScreen(WHITE, PORTRAIT);
  ssIndicatorField = SimbleeForMobile.drawRect(200, 200, 100, 50, RED);

  toHomeScreenButtonID = SimbleeForMobile.drawButton(HOME_BUTTON_LEFT_MARGIN, HOME_BUTTON_TOP_MARGIN, HOME_BUTTON_WIDTH, HOME_BUTTON_TEXT);
  SimbleeForMobile.setEvents(toHomeScreenButtonID, EVENT_RELEASE);
  SimbleeForMobile.endScreen();
}


And here is the update code:
Code: [Select]
    case DEBUG_1_SCREEN:
      if (SimbleeForMobile.updatable){
       SimbleeForMobile.updateRect(ssIndicatorField, 200, 200, 100, 50);
      };
     break;

.
This is based on the SimbleeUITest example.
ssIndicatorField is a global type uint8_t.
Same results as before:   if the updateRect is commented out the code runs indefinitely, otherwise it stops after a few seconds when the debug 1 screen is displayed.  I see a red rectangle on the screen.

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: updateRect() causes Android App to Crash
« Reply #3 on: July 17, 2017, 07:57:02 PM »
I would appreciate code that I can just grab and put into the IDE. As is I have to generate a bunch that I don't know if you'd do it that way.

AKotowski

  • RFduino Jr. Member
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: updateRect() causes Android App to Crash
« Reply #4 on: July 18, 2017, 09:54:13 AM »
Here is code that has the problem.  I modified the example "TwoScreens"
I removed the comments.  Lines I added or changed are marked by //AK
Thanks for your help
Code: [Select]
#include <SimbleeForMobile.h>

int toScreen2ButtonID;

int toScreen1ButtonID;

int currentScreen;


uint8_t ss;                                                    //AK

/*
 * Traditional Arduino setup routine
 *
 * Initialize the SimbleeForMobile environment.
 */
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Setup beginning");
 
  SimbleeForMobile.deviceName = "2 ScreensAK";                  //AK
  SimbleeForMobile.advertisementData = "Sample";

  SimbleeForMobile.domain = "twoscreensak.simblee.com";         //AK
 
  SimbleeForMobile.begin();
 
  Serial.println("Setup completed");
}

void loop() {
  // put your main code here, to run repeatedly:
  // process must be called in the loop for Simblee UI
  if (SimbleeForMobile.updatable){                                   //AK
    SimbleeForMobile.updateRect(ss, 200, 200, 100, 50);              //AK
  };                                                                 //AK
  SimbleeForMobile.process(); 
}

void SimbleeForMobile_onConnect()
{
  currentScreen = -1;
}

void SimbleeForMobile_onDisconnect()
{
}

void ui()

  if(SimbleeForMobile.screen == currentScreen) return;
 
  currentScreen = SimbleeForMobile.screen;
  switch(SimbleeForMobile.screen)
  {
    case 1:
      createScreen1();
      break;
       
    case 2:
      createScreen2();
      break;
           
   default:
      Serial.print("ui: Uknown screen requested: ");
      Serial.println(SimbleeForMobile.screen);
  }
}

void ui_event(event_t &event)
{
//  printEvent(event);
  if(event.id == toScreen1ButtonID && event.type == EVENT_RELEASE && currentScreen == 2)
  {
    SimbleeForMobile.showScreen(1);
  } else if(event.id == toScreen2ButtonID && event.type == EVENT_RELEASE && currentScreen == 1)
  {
    SimbleeForMobile.showScreen(2);
  }
}

void createScreen1()
{
  //
  // Portrait mode is the default, so that isn't required
  // here, but shown for completeness. LANDSCAPE could be
  // used for that orientation.
  //
  SimbleeForMobile.beginScreen(YELLOW, PORTRAIT);

  int textID = SimbleeForMobile.drawText(80, 60, "Screen 1", BLACK, 40);
  toScreen2ButtonID = SimbleeForMobile.drawButton(100, 200, 100, "Screen 2");

  ss = SimbleeForMobile.drawRect(200, 200, 100, 50, RED);                          //AK

  SimbleeForMobile.setEvents(toScreen2ButtonID, EVENT_RELEASE);
  SimbleeForMobile.endScreen();
}

void createScreen2()
{
  //
  // Default to Portrait orientation
  //
  SimbleeForMobile.beginScreen(WHITE);

  int textID = SimbleeForMobile.drawText(80, 60, "Screen 2", BLACK, 40);
  toScreen1ButtonID = SimbleeForMobile.drawButton(100, 200, 100, "Screen 1");

  SimbleeForMobile.setEvents(toScreen1ButtonID, EVENT_RELEASE);
  SimbleeForMobile.endScreen();
}

void printEvent(event_t &event)
{
  Serial.println("Event:");
  Serial.print("  ID: ");
  Serial.println(event.id);
 
  Serial.print("   Type: ");
  Serial.println(event.type); 

  Serial.print("   Value: ");
  Serial.println(event.value);
 
  Serial.print("   Text: ");
  Serial.println(event.text); 
 
  Serial.print("   Coords: ");
  Serial.print(event.x); 
  Serial.print(","); 
  Serial.println(event.y); 
}

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: updateRect() causes Android App to Crash
« Reply #5 on: July 18, 2017, 02:19:58 PM »
Some minor things first...
1). The spec defines IDs as 'uint8_t'. Don't know why many examples are still using 'int' and have not been corrected, yet.
2). SimbleeForMobile.domain should use your own domain or other than Simblee.com's.

But your problem is you are trying to update/draw your bargraph when you are not in the screen it is in. Thus the crash.
So be sure to test that you are in the screen of the rectangle you are wanting to change.
  if (SimbleeForMobile.updatable && currentScreen == 1){
Also, be sure your coordinates don't overwrite other objects or go off screen. I moved yours bargraph down below the button.

Code: [Select]
void loop() {

  if (SimbleeForMobile.updatable && currentScreen == 1){
    SimbleeForMobile.updateRect(ss, 80, 300, 150, 50);
  }
  SimbleeForMobile.process();
}

AKotowski

  • RFduino Jr. Member
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: updateRect() causes Android App to Crash
« Reply #6 on: July 18, 2017, 04:42:25 PM »
I've made the changes as you suggested, but still the same crash.  It does happen when the updateRect() occurs.  I can change the color of the rectangle, but when I update the rectangle the crash happens.  Here is the updated code:
Code: [Select]
#include <SimbleeForMobile.h>

uint8_t toScreen2ButtonID;
uint8_t toScreen1ButtonID;
uint8_t currentScreen;
uint8_t ss;                                                    //AK

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Setup beginning");
 
  SimbleeForMobile.deviceName = "2 ScreensAK";                  //AK
  SimbleeForMobile.advertisementData = "Sample";
//  SimbleeForMobile.domain = "twoscreensak.simblee.com";         //AK
  SimbleeForMobile.begin();
  Serial.println("Setup completed");
}

void loop() {
  delay(2000);
  if (SimbleeForMobile.updatable && currentScreen == 1 ){                                   //AK
    SimbleeForMobile.updateColor(ss, GRAY);
    SimbleeForMobile.updateRect(ss, 80, 300, 150, 50);              //AK
  };
  SimbleeForMobile.process(); 
}
void SimbleeForMobile_onConnect()
{
  currentScreen = -1;
}

void SimbleeForMobile_onDisconnect()
{
}

void ui()

  if(SimbleeForMobile.screen == currentScreen) return;
  currentScreen = SimbleeForMobile.screen;
  switch(SimbleeForMobile.screen)
  {
    case 1:
      createScreen1();
      break;
       
    case 2:
      createScreen2();
      break;
   default:
      Serial.print("ui: Uknown screen requested: ");
      Serial.println(SimbleeForMobile.screen);
  }
}

void ui_event(event_t &event)
{
//  printEvent(event);
  if(event.id == toScreen1ButtonID && event.type == EVENT_RELEASE && currentScreen == 2)
  {
    SimbleeForMobile.showScreen(1);
  } else if(event.id == toScreen2ButtonID && event.type == EVENT_RELEASE && currentScreen == 1)
  {
    SimbleeForMobile.showScreen(2);
  }
}

void createScreen1()
{
  SimbleeForMobile.beginScreen(YELLOW, PORTRAIT);

  uint8_t textID = SimbleeForMobile.drawText(80, 60, "Screen 1", BLACK, 40);
  toScreen2ButtonID = SimbleeForMobile.drawButton(100, 200, 100, "Screen 2");

  ss = SimbleeForMobile.drawRect(80, 300, 150, 50, RED);                          //AK
  SimbleeForMobile.setEvents(toScreen2ButtonID, EVENT_RELEASE);
  SimbleeForMobile.endScreen();
}
void createScreen2()
{
  SimbleeForMobile.beginScreen(WHITE);
  int textID = SimbleeForMobile.drawText(80, 60, "Screen 2", BLACK, 40);
  toScreen1ButtonID = SimbleeForMobile.drawButton(100, 200, 100, "Screen 1");
  SimbleeForMobile.setEvents(toScreen1ButtonID, EVENT_RELEASE);
  SimbleeForMobile.endScreen();
}

void printEvent(event_t &event)
{
  Serial.println("Event:");
  Serial.print("  ID: ");
  Serial.println(event.id);
 
  Serial.print("   Type: ");
  Serial.println(event.type); 

  Serial.print("   Value: ");
  Serial.println(event.value);
 
  Serial.print("   Text: ");
  Serial.println(event.text); 
 
  Serial.print("   Coords: ");
  Serial.print(event.x); 
  Serial.print(","); 
  Serial.println(event.y); 
}

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: updateRect() causes Android App to Crash
« Reply #7 on: July 18, 2017, 07:58:51 PM »
I don't know. This works for me. If it works for you, perhaps you can do a diff.

Code: [Select]
#include <SimbleeForMobile.h>

uint8_t toScreen2ButtonID;

uint8_t toScreen1ButtonID;

uint8_t currentScreen;


uint8_t ss;                                                    //AK

/*
 * Traditional Arduino setup routine
 *
 * Initialize the SimbleeForMobile environment.
 */
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Setup beginning");
 
  SimbleeForMobile.deviceName = "2Screens";                  //AK
  SimbleeForMobile.advertisementData = "Sample";

  //SimbleeForMobile.domain = "twoscreensak.simblee.com";         //AK // You should use your own domain
 
  SimbleeForMobile.begin();
 
  Serial.println("Setup completed");
}

void loop() {
  // put your main code here, to run repeatedly:
  // process must be called in the loop for Simblee UI
  if (SimbleeForMobile.updatable && currentScreen == 1){                                   //AK
    //SimbleeForMobile.updateRect(ss, 80, 300, 150, 50);              //AK
  };                                                                 //AK
  SimbleeForMobile.process();
}

void SimbleeForMobile_onConnect()
{
  currentScreen = -1;
}

void SimbleeForMobile_onDisconnect()
{
}

void ui()
{
  if(SimbleeForMobile.screen == currentScreen) return;
 
  currentScreen = SimbleeForMobile.screen;
  switch(currentScreen)
  {
    case 1:
      createScreen1();
      break;
       
    case 2:
      createScreen2();
      break;
           
   default:
      Serial.print("ui: Unknown screen requested: ");
      Serial.println(SimbleeForMobile.screen);
  }
}

void ui_event(event_t &event)
{
//  printEvent(event);
  if(event.id == toScreen1ButtonID && event.type == EVENT_RELEASE && currentScreen == 2)
  {
    SimbleeForMobile.showScreen(1);
  } else if(event.id == toScreen2ButtonID && event.type == EVENT_RELEASE && currentScreen == 1)
  {
    SimbleeForMobile.showScreen(2);
  }
}

void createScreen1()
{
  //
  // Portrait mode is the default, so that isn't required
  // here, but shown for completeness. LANDSCAPE could be
  // used for that orientation.
  //
  SimbleeForMobile.beginScreen(YELLOW, PORTRAIT);

  int textID = SimbleeForMobile.drawText(80, 60, "Screen 1", BLACK, 40);
  toScreen2ButtonID = SimbleeForMobile.drawButton(100, 200, 100, "Screen 2");

  ss = SimbleeForMobile.drawRect(80, 300, 100, 50, RED);                          //AK

  SimbleeForMobile.setEvents(toScreen2ButtonID, EVENT_RELEASE);
  SimbleeForMobile.endScreen();
}

void createScreen2()
{
  //
  // Default to Portrait orientation
  //
  SimbleeForMobile.beginScreen(WHITE);

  int textID = SimbleeForMobile.drawText(80, 60, "Screen 2", BLACK, 40);
  toScreen1ButtonID = SimbleeForMobile.drawButton(100, 200, 100, "Screen 1");

  SimbleeForMobile.setEvents(toScreen1ButtonID, EVENT_RELEASE);
  SimbleeForMobile.endScreen();
}

void printEvent(event_t &event)
{
  Serial.println("Event:");
  Serial.print("  ID: ");
  Serial.println(event.id);
 
  Serial.print("   Type: ");
  Serial.println(event.type);

  Serial.print("   Value: ");
  Serial.println(event.value);
 
  Serial.print("   Text: ");
  Serial.println(event.text);
 
  Serial.print("   Coords: ");
  Serial.print(event.x);
  Serial.print(",");
  Serial.println(event.y);
}

AKotowski

  • RFduino Jr. Member
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: updateRect() causes Android App to Crash
« Reply #8 on: July 19, 2017, 08:49:02 AM »
The offending line (36) //SimbleeForMobile.updateRect(ss, 80, 300, 150, 50);
is commented out.
Please try uncommenting that line

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: updateRect() causes Android App to Crash
« Reply #9 on: July 19, 2017, 10:40:12 AM »
Since you really just wanted to change the width of the bargraph use...

SimbleeForMobile.updateW(ss, width);
I know this works.

Also, just thought, you are updating in the loop and would seem to be at a too high rate for
the SimbleeForMobile.process();

So need to scheme how to update the bargraph at a slower rate.
Could put delay(200) after the updateW, but being in the loop that slows down response to/from phone.

So best to use a update routine using millis and millisLast examples.

Don't know why SimbleForMobile.updateRect is not working so well. Perhaps way too many things to update in the loop too often.
Don't really need it since you can update just what needs to be updated. Other than that, I suggest calling RFdigital to get their attention on the matter.

« Last Edit: July 19, 2017, 04:06:53 PM by tolson »

AKotowski

  • RFduino Jr. Member
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: updateRect() causes Android App to Crash
« Reply #10 on: July 19, 2017, 03:54:52 PM »
Thanks

AKotowski

  • RFduino Jr. Member
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: updateRect() causes Android App to Crash
« Reply #11 on: July 20, 2017, 10:27:29 AM »
Yes, updateW() solves my problem.
The app crashes regardless of the update frequency, even if updateRect() is only called once.
Thanks for your help

RFD_Nelson

  • RFduino Team
  • *****
  • Posts: 42
  • Karma: +0/-0
    • View Profile
Re: updateRect() causes Android App to Crash
« Reply #12 on: July 24, 2017, 05:25:38 AM »
Hi AKotowski,

Can you please try changing this line:
Code: [Select]
ss = SimbleeForMobile.drawRect(80, 300, 150, 50, RED); to this:
Code: [Select]
ss = SimbleeForMobile.drawRect(80, 300, 150, 50, RED, RED);
and then removing the updateColor() line from the loop()?

Thanks,

Nelson

AKotowski

  • RFduino Jr. Member
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: updateRect() causes Android App to Crash
« Reply #13 on: July 25, 2017, 08:31:52 PM »
Yes, adding the second color parameter allows the program to work

 

anything