CN1: ios app crashes when showing picker component - codenameone

My CN1 app crashes on iOS only (not on android).
With the native sources and xcode I found the error location:
The error comes up when a form is shown which includes a Picker-component.
In xcode I found that this line in my code is causing the error:
picker.setType(Display.PICKER_TYPE_STRINGS);
My code:
private boolean setPicker() {
picker.remove();
picker.setSelectedString(null);
picker.setType(Display.PICKER_TYPE_STRINGS);
String[] arr = RatingObject.getListAsStringArray();
if (arr.length > 0) {
gui_ro_Picker.setStrings(arr);
.....
Error:
Thread 5: EXC_BAD_ACCESS (code=1, address=0x0)
Code where the error appears:
#ifdef NEW_CODENAME_ONE_VM
JAVA_BOOLEAN com_codename1_impl_ios_IOSImplementation_instanceofObjArrayI___java_lang_Object_R_boolean(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT n1)
{
// second part of the expression check that this isn't a primitive array
return n1->__codenameOneParentClsReference->isArray && cn1_array_start_offset + 100 < n1->__codenameOneParentClsReference->classId;
}
xcode marks explicitly the return line with the error
Do you have any advice on this?
Update:
Moving picker.setType(Display.PICKER_TYPE_STRINGS); into the constructor solved the issue.

For me moving picker.setType(Display.PICKER_TYPE_STRINGS) into the constructor solved this issue.
Thanks for the advices!

Related

CodenameOne IOS app crashing due to null threadsToDelete

I have a codenameOne app that works fine on Android but occasionally crashes on iOS.
From xcode it looks like its failing at:
JAVA_VOID java_lang_Thread_releaseThreadNativeResources___long(CODENAME_ONE_THREAD_STATE, JAVA_LONG nativeThreadId) {
for(int i = 0 ; i < NUMBER_OF_SUPPORTED_THREADS ; i++) {
if(threadsToDelete[i] != 0 && threadsToDelete[i]->threadId == nativeThreadId) {
free(threadsToDelete[i]->blocks);
free(threadsToDelete[i]->threadObjectStack);
free(threadsToDelete[i]->callStackClass);
free(threadsToDelete[i]->callStackLine);
free(threadsToDelete[i]->callStackMethod);
free(threadsToDelete[i]->pendingHeapAllocations);
free(threadsToDelete[i]);
threadsToDelete[i] = 0;
break;
}
}
}
in nativeMethods.m. It says threadsToDelete is null in that if statement. This seems to happen when I open a new form showing a picture, then switch back to the original form. I do start a new thread to save certain details to amazon. But it doesn't crash everytime.
I have fixed this issue in Github here. It will be included with the next build server update (probably today, possibly next week).

Dart TreeSanitzer: No static getter 'trusted' declared in class 'NodeTreeSanitizer'

I'm using the Bootjack Datepicker and after upgrading Dart to 1.12.1, I'm all of a sudden seeing only half a calendar with no days and with this exception:
Exception: No static getter 'trusted' declared in class
'NodeTreeSanitizer'. NoSuchMethodError: method not found: 'trusted'
Receiver: Type: class 'NodeTreeSanitizer'
This is the only line of code needed to wire the calendar:
Calendar.use();
If you need to manually wire the calendar, you can manually call:
Calendar.wire(querySelector("div.calendar"));
Both of them are giving me the exception in calendar.dart
The code that seems to be breaking is:
void _dayView() {
TableElement calBody = element.querySelector('.cnt');
Element dow = calBody.tBodies[0].createFragment(_DOW_TEMPLATE).children[0];
List<Element> children = dow.children;
List<String> swkDays = _dfmt.dateSymbols.SHORTWEEKDAYS;
int ofs = (_firstDayOfWeek + 1) % 7;
//render week days
for (int i = swkDays.length; --i >= 0;) {
children[i].text = swkDays[(i + ofs) % 7];
}
var buffer = new StringBuffer();
for (int i = 6; --i >= 0;) {
buffer.write(_DAYROW_TEMPLATE);
}
calBody.tBodies[0]
..append(dow)
..appendHtml(buffer.toString(), treeSanitizer: NodeTreeSanitizer.trusted); <<<<<<<< ERROR
}
Looking at appendHtml, I can see treeSanitizer is an optional param, so that syntax looks fine. In the abstract class NodeTreeSanitizer, I can see: static const trusted = const _TrustedHtmlTreeSanitizer();, so that seems to be fine as well.
Any idea what could be causing this error?
I've logged a bug here in the meantime: https://github.com/rikulo/bootjack-datepicker/issues/2
Looks like your Dartium version is outdated.
Please compare the output of dart --version (command line) and the Dart version on the about://version page in Dartium.

Markers and Windows(Angular google maps) not working after upgrade to angular 1.3.8

I have been using angular-google-maps for sometime. I have not faced any major issues till now. But one of my colleagues had upgraded angular to 1.3.8 recently. And since then I am getting the following errors while instantiating the and directives and I do not see any markers. Here are the errors I get. Any inputs or directions to debug will be awesome. Thanks in advance.
Here is the first error:
Error: this.mapCtrl.getMap is not a function
this.MarkersParentModel</MarkersParentModel.prototype.createMarkers#http://localhost/scripts/1b3f05c4.modules.js:2637:75
__bind/<#http://localhost/scripts/1b3f05c4.modules.js:2569:16
this.MarkersParentModel</MarkersParentModel.prototype.onTimeOut#http://localhost/scripts/1b3f05c4.modules.js:2612:16
__bind/<#http://localhost/scripts/1b3f05c4.modules.js:2569:16
__bind/<#http://localhost/scripts/1b3f05c4.modules.js:2234:16
IMarkerParentModel/<#http://localhost/scripts/1b3f05c4.modules.js:2290:11
timeout/timeoutId<#http://localhost/bower_components/angular/angular.js:16205:28
completeOutstandingRequest#http://localhost/bower_components/angular/angular.js:4902:7
Browser/self.defer/timeoutId<#http://localhost/bower_components/angular/angular.js:5282:7
http://localhost/bower_components/angular/angular.js
Line 11594
And here is the second error:
Error: this.linked.ctrls[0].getMap is not a function
this.WindowsParentModel</WindowsParentModel.prototype.createChildScopesWindows#http://localhost/scripts/1b3f05c4.modules.js:2860:21
__bind/<#http://localhost/scripts/1b3f05c4.modules.js:2726:16
WindowsParentModel/<#http://localhost/scripts/1b3f05c4.modules.js:2785:18
timeout/timeoutId<#http://localhost/bower_components/angular/angular.js:16205:28
completeOutstandingRequest#http://localhost/bower_components/angular/angular.js:4902:7
Browser/self.defer/timeoutId<#http://localhost/bower_components/angular/angular.js:5282:7
http://localhost/bower_components/angular/angular.js
Line 11594
Line 2860:
var markersScope, modelsNotDefined, _this = this;
this.isIconVisibleOnClick = true;
if (angular.isDefined(this.linked.attrs.isiconvisibleonclick)) {
this.isIconVisibleOnClick = this.linked.scope.isIconVisibleOnClick;
}
>>>> this.gMap = this.linked.ctrls[0].getMap();
markersScope = this.linked.ctrls.length > 1 && this.linked.ctrls[1] != null ? this.linked.ctrls[1].getMarkersScope() : void 0;
modelsNotDefined = angular.isUndefined(this.linked.scope.models);
if (modelsNotDefined && (markersScope === void 0 || markersScope.markerModels === void 0 && markersScope.models === void 0)) {
this.$log.info('No models to create windows from! Need direct models or models derrived from markers!');
return;
}
Line 2637:
this.gMarkerManager = new directives.api.managers.MarkerManager(this.mapCtrl.getMap());

'Mutating method sent to immutable object error' in Xcode

I am unsure why I get this error when I run my program a certain way.
2014-05-15 16:19:28.932 Puzzle[1002:f803] *** WebKit discarded an uncaught exception in the webView:shouldInsertText:replacingDOMRange:givenAction: delegate: <NSInternalInconsistencyException> -[__NSCFArray replaceObjectAtIndex:withObject:]: mutating method sent to immutable object
I have an NSMutableArray called 'levelsCompleteArray' that I am trying to cycle through to see when the first NO, (or 0) appears and to set that iteration to a variable called 'picIndex'. If there are no YES's in the array, then the program works fine. When there is one in the next iteration, however, I get the message posted above. Does anyone know why? Code below:
[levelsCompleteArray replaceObjectAtIndex:picIndex withObject:[NSNumber numberWithBool:YES]];
BOOL wonLevel=NO;
int i=picIndex;
while (wonLevel==NO)
{
BOOL status =[[levelsCompleteArray objectAtIndex:i] boolValue];
if (status==1)
{
i=i+1;
if(i==3)
{
picIndex=0;
wonLevel=YES;
}
}
else
{
picIndex=i;
wonLevel=YES;
}
}
It looks like levelsCompleteArray is an NSArray which is immutatable. To turn it into a mutable array try this:
NSMutableArray* mutableLevelsCompleteArray = [[NSMutableArray alloc] initWithArray:levelsCompleteArray];

Verifying purchase receipts in both iOS 6 and 7

I am verifying in-app-purchase receipts using the following code:
- (void) completeTransaction:(SKPaymentTransaction*) transaction
{
NSData* receipt = nil;
// 1. Attempt <app receipt> first (iOS 7.x)
NSBundle* mainBundle = [NSBundle mainBundle];
if ([mainBundle respondsToSelector:#selector(appStoreReceiptURL)]) {
NSURL* appStoreReceiptURL = [mainBundle appStoreReceiptURL]; // <- CRASH
receipt = [NSData dataWithContentsOfURL:appStoreReceiptURL];
}
// 2. Fallback to <transaction receipt> (iOS < 7.0)
if (!receipt) {
receipt = [transaction transactionReceipt];
}
// 3. Have server verify it with iTunes:
[self verifyReceipt:receipt forTransaction:transaction];
}
On an iOS 6 device, the execution stops at the line NSURL* appStoreReceiptURL = [mainBundle appStoreReceiptURL]; and the console spits:
-[NSBundle appStoreReceiptURL]: unrecognized selector sent to instance 0x208492d0
Am I missing something? Wasn't -respondsToSelector: supposed to take care of this? Must I fall back to checking the OS version directly??
YES you should check version number directly in case of this appStoreReceiptURL Method.
appStoreReceiptURL
In iOS, use the following code to detect whether this method is available:
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// Load resources for iOS 6.1 or earlier
} else {
// Load resources for iOS 7 or later
}
Note: The general best practice of weak linking using the respondsToSelector: method cannot be used here. Prior to iOS 7, the method (appStoreReceiptURL) was implemented as private API, but that implementation called the doesNotRecognizeSelector: method.
Reference:NSBundle Class reference

Resources