Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application crash on pebble #173

Open
edouardkleinhans opened this issue Sep 29, 2016 · 10 comments
Open

Application crash on pebble #173

edouardkleinhans opened this issue Sep 29, 2016 · 10 comments

Comments

@edouardkleinhans
Copy link

Hello,

When I try to run pebblejs sample on my watch, it always failed with error like this :

Do you have any idea ?

[INFO] ocess_manager.c:417: Heap Usage for App : Total Size <5592B> Used <4036B> Still allocated <644B>
[PHONE] pebble-app.js:?: JS: stopping app: 4368FFA4-F0FB-4823-90BE-F754B076BDAA TimeStyle
[PHONE] pebble-app.js:?: JS: starting app: 4CE95E77-F075-47AE-BE7D-D2E7C7C6DF87 Test_js
[PHONE] pebble-app.js:?: JS: Test_js: JavaScript Error:
TypeError: undefined is not an object (evaluating 'v.x')
at copy (lib/vector2.js:38:15)
at size (ui/window.js:260:29)
at Window (ui/window.js:75:12)
at Card (ui/card.js:47:14)
at app.js:10:23
at require (loader.js:44:16)
at require (loader.js:41:55)
at main.js:41:10

@matopeto
Copy link

matopeto commented Oct 3, 2016

Please share your code, maybe you run/copy it from old sample.

@edouardkleinhans
Copy link
Author

var UI = require('ui');
var Settings = require('settings');
var ajax = require('ajax');
var Vibe = require('ui/vibe');
var menuSettings;
var sectionsMenu = [];
var itemsMenu = [];
var jebbleApiUrl = "plugins/jebble/core/api/jebble_api.php";
var jeeApiUrl = "core/api/jeeApi.php";

Settings.option('jeedomBaseUrl', 'https://dom.kleinhans.info/jeedom/');
Settings.option('jeedomApiKey', 'p5ecbuny626yhig1wjjl');
Settings.option('reset', 'false');

Settings.data('menu',
   JSON.stringify([{"id":"19","name":"Confort","group":"Chauffage"},{"id":"20","name":"Eco","group":"Chauffage"},{"id":"21","name":"Off","group":"Chauffage"},{"id":"12","name":"Allumer Salon","group":"Lumi\u00e8res"},{"id":"13","name":"Eteindre Salon","group":"Lumi\u00e8res"},{"id":"18","name":"Fermer Volet","group":"Volets"},{"id":"17","name":"Ouvrir Volet","group":"Volets"}])
);

var cardError = new UI.Card({
title: "Erreur",
body: "Une erreur est survenue"
});

var cardResult = new UI.Card({});

var cardWait = new UI.Card({
title: "",
body: "Chargement..."
});

// Create Menu Card
var menu = new UI.Menu({
sections: []
});

var sousMenu = new UI.Menu({
sections: []
});

function httpCall(url, params, method, sync, returnDatas) {
var jeedomUrl = Settings.option("jeedomBaseUrl").replace(//?$/, '/');
var result = 'Fait';
var _async = sync ? false : true;
var _method = method ? method : 'GET';
console.log("url: " + jeedomUrl + url + "?apikey=" + Settings.option("jeedomApiKey") + (params ? params : ""));
ajax(
{
url: jeedomUrl + url + "?apikey=" + Settings.option("jeedomApiKey") + (params ? params : ""),
type: 'json',
method: _method,
async: _async
},
function(data, status, request) {
//console.log('return: ' + data);
if(returnDatas) {
result = data;
}
},
function(error, status, request) {
console.log('The ajax request failed: ' + error);
result = error;
}
);
return result;
}

function loadMenuSettings() {
console.log('load menu settings');
// var response = httpCall(jebbleApiUrl, "", "GET", true, true);
// Persist
// Settings.data('menu', JSON.stringify(response));
Settings.option("reset", false);
}

function constructMenu() {
menuSettings = Settings.data('menu');
if(menuSettings) {
// console.log(menuSettings);
var elements = JSON.parse(menuSettings);
for (var e in elements){
var currentGroup = elements[e].group ? elements[e].group : "Aucun";
if(!itemsMenu[currentGroup]){
itemsMenu[currentGroup] = [];
}
// console.log("e: " + e + " Name: " + elements[e].name + " Element Id: " + elements[e].id);
itemsMenu[currentGroup].push({title: elements[e].name, command: elements[e].id});
}

for (var s_itemsMenu in itemsMenu){
//  console.log("s_itemsMenu: " + s_itemsMenu);
  sectionsMenu.push({title: s_itemsMenu});
}
menu.section(0, {title: 'Jebble', items: sectionsMenu}); //Set Title for menu
menu.show();
cardWait.hide();
} else {
cardError.show();
cardWait.hide();

}
}

cardWait.show();

Settings.config(
{ url:'https://dl.dropboxusercontent.com/u/13087853/configuration_jebble.html?' + encodeURIComponent(JSON.stringify(Settings.option()))},
function(e) {
console.log('opened config');
},
function(e) {
if(e.options != "CANCELLED" && e.response.charAt(0) == "{" && e.response.slice(-1) == "}" && e.response.length > 5) {
// console.log(e.response);
// console.log('Recieved settings!');
Settings.option(JSON.parse(decodeURIComponent(e.response)));
loadMenuSettings();
constructMenu();
Vibe.vibrate('short');
} else {
console.log("cancelled");
}
}
);

if(!Settings.data('menu') || Settings.option("reset")){
loadMenuSettings();
}/* else {
console.log('construct menu');
}*/

constructMenu();

menu.on('select', function (event) {
// console.log("event: " + event.item.title);
sousMenu.section(0, {title: event.item.title, items: itemsMenu[event.item.title]});
sousMenu.show();
});

sousMenu.on('select', function (event) {
var result = httpCall(jeeApiUrl, "&type=scenario&id=" + event.item.command + "&action=start", "GET", true, true);
Vibe.vibrate('short');
//console.log("result command[" + event.item.command + "] : " + result);
cardResult.body(result);
cardResult.show();
setTimeout(function() {cardResult.hide();}, 500);
});

@matopeto
Copy link

matopeto commented Oct 3, 2016

I run your code in cloud pebble (emulators) and on the watch too (Pebble steel), but it is working. When you get the error? What is your watch. It may be not work with Pebble 2. I sent Pull request for Pebble 2 support: #170 Feel free to try with my pull request.

@edouardkleinhans
Copy link
Author

My watch is a pebble (first gen). Everytime I launch this app, it crash.

@pattyland
Copy link

pattyland commented Oct 15, 2016

Same here. My App works in Simulators for aplite and basalt. Test on a Pebble Time Steel: works. Test on a Pebble Classic: crashes with the exact error message from above!
Related topic: https://forums.pebble.com/t/pebble-js-crash/24705 ("anymore"!)

I made a new project, this is the full code of app.js:

var UI = require('ui');
var main = new UI.Window();

Crashes on Pebble classic with:

[HANDY] pebble-app.js:?: JS: starting app: 33B76CEC-E1F6-40A9-91CC-72F94E28A9AB Test
[HANDY] pebble-app.js:?: JS: Test: JavaScript Error:
TypeError: undefined is not an object (evaluating 'v.x')
    at copy (lib/vector2.js:38:15)
    at size (ui/window.js:260:29)
    at Window (ui/window.js:75:12)
    at app.js:2:25
    at require (loader.js:44:16)
    at require (loader.js:41:55)
    at main.js:41:10

@matopeto
Copy link

More info here: https://forums.pebble.com/t/pebble-js-crash/24705/8

It looks like Pebble.getActiveWatchInfo return null like here: https://forums.pebble.com/t/getactivewatchinfo-returning-null-on-ios/23800

@dnmgns
Copy link

dnmgns commented Jan 20, 2017

What about waiting for the ready event? Like suggested here: https://developer.pebble.com/blog/2013/12/20/Pebble-Javascript-Tips-and-Tricks/
I guessing that an addEventListener("ready") added to pebblejs/src/js/platform/platform.js would solve this, right?

@dnmgns
Copy link

dnmgns commented Jan 21, 2017

For the record, I'm getting this on a Pebble Time Steel but works fine in emulator:
[01:19:06] pkjs> JS: starting app: DA23189C-A117-4AF1-95F5-CCA07C843842 test
[01:19:06] pkjs> Error: Cellar Temp: TypeError: null is not an object (evaluating 'Pebble.getActiveWatchInfo().platform') at line 2186 in pebble-js-app.

@iSevenDays
Copy link

I also get the error above. Did anybody find the fix?

@iSevenDays
Copy link

The issue is that some pebble watch has color "unknown".
https://developer.rebble.io/developer.pebble.com/docs/c/Foundation/WatchInfo/index.html#WatchInfoColor
Weird to know, but getActiveWatchInfo depends on this property.
If you use iOS application, you need to inject the following methods(use IPAPatch as the example):

  • (BOOL)NSUUID_pb_isSystemAppUUID {
    return NO;
    }
  • (NSUInteger)PBWatch_watchColor {
    //NSUInteger color = [self PBWatch_watchColor];
    return 14; <-- Pebble Time Steel. Check your model from the URL above, the counter starts from 0.
    }
    [TWXRuntime exchangeInstanceMethod:@"pb_isSystemAppUUID" ofClass:@"NSUUID"];
    [TWXRuntime exchangeInstanceMethod:@"watchColor" ofClass:@"PBWatch"];

PM me for more details in case you don't know how to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants