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

[5_4_X][TIMOB-15765] Android: TableView - JNI ERROR (app bug): local reference table overflow (max=512) #8148

Merged
merged 1 commit into from Jul 21, 2016

Conversation

sgtcoolguy
Copy link
Contributor

@sgtcoolguy sgtcoolguy commented Jul 20, 2016

JIRA: https://jira.appcelerator.org/browse/TIMOB-15765

Description:
Back port of #8147

Can't add unit tests on 5_4_X branch, unfortunately, so I guess a manual test is needed. Set this as your app.js and run on an older emulator (< Android 6) and a newer emulator (6+):

var numberOfTableRowsToTest = 400; // 50 is enough to trigger on Android 4.4.2. 400 hits error on Android 6.0/23

var vAnswerTable = Ti.UI.createTableView({
    data: [Ti.UI.createTableViewRow({title:'Loading...'})],
});

var numOfQuestions = numberOfTableRowsToTest / 5;
var numOfAnswers = numOfQuestions * 4;
var sections = [];

for (var i = 0; i < numOfQuestions; i++) {
    var questionTableSection = Ti.UI.createTableViewSection({});

    var questionRow = Ti.UI.createTableViewRow({});

    questionTableSection.add(questionRow);

    for (var z = 0; z < numOfAnswers; z++) {
        var answerRow = Ti.UI.createTableViewRow({});
        var lAnswer = Ti.UI.createLabel({});

        answerRow.add(lAnswer);
        questionTableSection.add(answerRow);
    }
    sections.push(questionTableSection);
}

// Add the sections created above to the table view
vAnswerTable.setData(sections);

for (var i = 0; i < vAnswerTable.data.length; i++) {
    Ti.API.info("Here after " + i + " iterations outer loop. Current section: " + vAnswerTable.data[i]);
    for (var k = 0; k < vAnswerTable.data[i].rowCount; k++) {
        Ti.API.info("Here after " + k + " iterations inner loop, " + i + " iterations outer loop. Current section row: "+  vAnswerTable.data[i].rows[k]);
    }
}

On older Android it would complain about a JNI local ref overflow at 512 entries. On newer it would complain about a slightly different variant of the error (weak global refs, with a max of 51200).

@sgtcoolguy sgtcoolguy added this to the 5.4.0 milestone Jul 20, 2016
@ashcoding
Copy link
Contributor

Functionally tested. Working well.
Approved

@ashcoding
Copy link
Contributor

Also tested with

Ti.UI.backgroundColor = 'white';
var win = Ti.UI.createWindow({
    exitOnClose : true,
    layout : 'vertical'
});

var button = Titanium.UI.createButton({
    title : 'Get Contacts Here',
    top : 60
});

win.add(button);

win.open();

var performAddressBookFunction = function() {
    var singleValue = ['recordId', 'firstName', 'middleName', 'lastName', 'fullName', 'prefix', 'suffix', 'nickname', 'firstPhonetic', 'middlePhonetic', 'lastPhonetic', 'organization', 'jobTitle', 'department', 'note', 'birthday', 'created', 'modified', 'kind'];
    var multiValue = ['email', 'address', 'phone', 'instantMessage', 'relatedNames', 'date', 'url'];
    var people = Ti.Contacts.getAllPeople();
    Ti.API.info('Total contacts: ' + people.length);

    for (var i = 0,
        ilen = people.length; i < ilen; i++) {
        Ti.API.info('---------------------' + i);

        var person = people[i];
        if (person != null) {
            var firstname = person.firstName || "Null";
            var lastname = person.lastName || "Null"
            Ti.API.info(firstname + "-" + lastname);
        } else {
            Ti.API.info("Person is null at" + i);
        }
    }

};
var addressBookDisallowed = function() {
    alert("Not Allowed");
};

button.addEventListener('click', function(e) {
    if (Ti.Contacts.hasContactsPermissions()) {
        performAddressBookFunction();
    } else {
        Ti.Contacts.requestContactsPermissions(function(e) {
            if (e.success) {
                performAddressBookFunction();
            } else {
                addressBookDisallowed();
            }
        });
    }
});

@ashcoding ashcoding merged commit 8dbedcd into tidev:5_4_X Jul 21, 2016
@sgtcoolguy sgtcoolguy deleted the TIMOB-15765-5_4_X branch July 21, 2016 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants