Why does app crash on certain variable references?

You must Login before you can answer or comment on any questions.

I'm trying to attach functions to certain elements (using JQuery), and the elements are dynamically created. I'm using a loop, so I have to do something to use the correct variable names in the functions. One other thing: I am using values retrieved from Ruby, and I'm trying to call a Ruby function.

So here's the line that crashes my app:

addedItem.find("#repoRemove_" + repo.name).click(function(name) { return function() { window.p2pdoc_settings.testout(name); }; }(repo.name));

Strangely enough, I can crash it with just this single line as well:

repo_name = repo.name;

But the following lines actually work (though you'll notice they don't handle my needs):

addedItem.find("#repoRemove_" + repo.name).click(function(name) { return function() { window.p2pdoc_settings.testout(name); }; }("def"));

addedItem.find("#repoRemove_" + repo.name).click(function(name) { return function() { alert(name) }; }(repo.name));

I'm ready to try anything else. I've tried "new Function()"; I've tried putting the functions and variables in all kinds of scopes; I've tried different combinations of nesting for the functions. But I'll try whatever brainstorms you've got. Thanks.

— asked 11 months ago by Trent Larson
1 Comment
  • It looks like the Ruby (AKA Kroll) bridge ends up causing issues, since all these references seem to crash when they're accessing my Ruby objects. And this thing is doubly frustrating because it seems to be intermittent: I find a piece of code that works, but then after a few tries it breaks and then continues to break.

    So I tried erasing the 'dist' directory, and things worked better. I actually got different results from some of my debugging printouts! So something ends up getting whacked in that 'dist' directory. Ug.

    — commented 11 months ago by Trent Larson

3 Answers

Nope. Erasing my dist directory doesn't always work.

The answer has something to do with the application settings which are stored in ~/Library/Application\ Support/Titanium/appdata/ here on my Mac. Each application has a folder based on the application ID, ie. where it suggests "com.companyname.appname" when you set up a new project; since I was developing on the same project in different places as things change and I test (eg. source control, Studio vs Developer), I guess that mucked things up.

Creating a new app with a different ID and then copying source files over (except tiapp.xml and manifest files) now lets me work without crashing. (BTW, it wasn't enough to move the old appdata folder out of the way.)

OK, this is interesting: in a different crash situation I add the following (to print the moreInfo result of a Ruby call to the console) in just the right location and it doesn't crash any more:

Titanium.API.print("results: " + moreInfo + "\n");

— answered 7 months ago by Trent Larson
answer permalink
14 Comments
  • This works, too:

    var nothing = moreInfo.toString();

    — commented 7 months ago by Trent Larson

  • Trent,

    What is returned ? IOW, what is nothing at that point ?

    One way to isolate your problem would be to put a try/catch block around the code in question, not sure if that would give you any hints or not, but couldn't hurt.

    — commented 7 months ago by Alan DuBoff

  • "nothing" has the value I expect, ie. the text of the "moreInfo" result... if I take out that line, then it crashes later (on code that inserts something in the DOM in this particular case).

    These app crashes are not caught in a try/catch (but thanks for the suggestion... keep 'em coming).

    — commented 7 months ago by Trent Larson

  • Show 11 more comments

Your Answer

Think you can help? Login to answer this question!