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

Proper way to switch between multiple maps on multiple "pages"? #66

Closed
bitfabrikken opened this issue Jan 18, 2017 · 23 comments
Closed
Labels

Comments

@bitfabrikken
Copy link
Contributor

I've got this app where I switch between multiple pages (views), that have different maps on them.
In some cases, I need to add the same annotations to them, and in some cases I don't.
Because of this, I prefer to have the annotations "prebuilt" so I can just add them to any map view later on.

Currently I do this:
• Create annotations and store them in e.g. app.annotations
• Show view1: Create new map view, add to view1, add annotations
• Show view2: Remove annotations, remove map view from view1 and null it, hide view1, create map view, add to view2, add annotations
• Show view 1 again: Remove annotations, remove map view from view2 and null it, hide view2, create map view, add to view1, add annotations

This works alright with the ti.map module, but with ti.googlemaps, I often get IndexOutOfRange errors, causing the app to crash.

I'm now wondering if I'm doing something incorrectly, and what the proper way to do this would be?

@bitfabrikken
Copy link
Contributor Author

Made an example app.js here, at the bottom, which can reproduce the various crashes.
Its simply 3 views with 3 buttons for switching between 3 maps, with shared annotations which have been prebuilt.

Range exception:

Jan 19 10:20:53 Dans-Mac-mini TiShadow[52224]: Google Maps SDK for iOS and Google Places API for iOS version: 2.1.28321.0
Jan 19 10:20:54 Dans-Mac-mini locationd[50232]: Location icon should now be in state 'Active'
Jan 19 10:20:56 Dans-Mac-mini TiShadow[52224]: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 33 beyond bounds [0 .. 32]'
	*** First throw call stack:
	(
		0   CoreFoundation                      0x00000001122d734b __exceptionPreprocess + 171
		1   libobjc.A.dylib                     0x000000010f44b21e objc_exception_throw + 48
		2   CoreFoundation                      0x0000000112208f1b -[__NSArrayM objectAtIndex:] + 203
		3   CoreFoundation                      0x000000011226fa1f -[NSMutableArray removeObject:] + 127
		4   TiShadow                            0x000000010a852408 __42-[TiGooglemapsViewProxy removeAnnotation:]_block_invoke.247 + 52
		5   libdispatch.dylib                   0x0000000113238810 _dispatch_call_block_and_release + 12
		6   libdispatch.dylib                   0x000000011325a12e _dispatch_client_callout + 8
		7   libdispatch.dylib                   0x000000011324024c _dispatch_queue_override_invoke + 809
		8   libdispatch.dylib                   0x0000000113241a0e _dispatch_root_queue_drain + 506
		9   libdispatch.dylib                   0x00000001132417b4 _dispatch_worker_thread3 + 113
		10  libsystem_pthread.dylib             0x0000000113606712 _pthread_wqthread + 1299
		11  libsystem_pthread.dylib             0x00000001136061ed start_wqthread + 13
	)
Jan 19 10:20:56 Dans-Mac-mini SpringBoard[50229]: [KeyboardArbiter] HW kbd: Failed to set (null) as keyboard focus
Jan 19 10:20:56 Dans-Mac-mini com.apple.CoreSimulator.SimDevice.78A29E35-2726-46BF-8A9B-12A768CB0AF5.launchd_sim[50212] (UIKitApplication:dk.bitfabrikken.tishadow[0xd64c][52224]): Service exited due to Abort trap: 6

Crash when starting up app again after the above crash:

TiShadow[52394]: objc[52394]: Class PLBuildVersion is implemented in both /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.1.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x1166ec998) and /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.1.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x116511d38). One of the two will be used. Which one is undefined.
Jan 19 10:23:47 Dans-Mac-mini logd[50223]: metadata shared cached uuid is null (using logd's shared cache info) TiShadow (52394)
Jan 19 10:23:47 Dans-Mac-mini logd[50223]: Failed to harvest strings for pathless uuid '00000000-0000-0000-0000-000000000000'
Jan 19 10:23:47 Dans-Mac-mini TiShadow[52394]: assertion failed: 16C67 14B72: libxpc.dylib + 62597 [17F6B510-0FB1-30D3-B29C-D74A5D63719E]: 0x7d
Jan 19 10:23:49 Dans-Mac-mini TiShadow[52394]: TiShadow(52394,0x700007c20000) malloc: *** error for object 0x60800000a9c0: pointer being freed was not allocated
	*** set a breakpoint in malloc_error_break to debug
Jan 19 10:23:49 Dans-Mac-mini SpringBoard[50229]: [KeyboardArbiter] HW kbd: Failed to set (null) as keyboard focus
Jan 19 10:23:49 Dans-Mac-mini com.apple.CoreSimulator.SimDevice.78A29E35-2726-46BF-8A9B-12A768CB0AF5.launchd_sim[50212] (UIKitApplication:dk.bitfabrikken.tishadow[0x5674][52394]): Service exited due to Abort trap: 6

Another time when starting the app:

assertion failed: 16C67 14B72: libxpc.dylib + 62597 [17F6B510-0FB1-30D3-B29C-D74A5D63719E]: 0x7d
com.apple.CoreSimulator.SimDevice.78A29E35-2726-46BF-8A9B-12A768CB0AF5.launchd_sim[50212] (UIKitApplication:dk.bitfabrikken.tishadow[0x99ab][52080]): Service exited due to Segmentation fault: 11

app.js

var maps = require("ti.googlemaps");
maps.setAPIKey("<YOUR_GOOGLE_MAPS_API_KEY>");

var win = Ti.UI.createWindow({
});

win.open();


var coords = [];
for (var i=0;i<50;i++) {
    coords.push({
        latitude: i,
        longitude: i
    });
}

//prebuild annotations
var annos = [];
for (var i=0;i<50;i++) {
    var annotation = maps.createAnnotation({
        latitude: i,
        longitude: i,
        title: "title",
        subtitle: "subtitle",
        // pinColor: "green",
        // image: "myPin.png"
    });
    annos.push(annotation);
}


//create views to switch between
var views = [];
var curr_view;
for (var i=0;i<3;i++) {
    views.push(Ti.UI.createView({
        backgroundColor: "green",
        bottom: 50,
        index: i
    }));
}


//create buttons for switching views
var buttons = [];
var selected_button = null;
var buttons_view = Ti.UI.createView({
    backgroundColor: "red",
    height: 50,
    bottom: 0,
    layout: "horizontal",
});
win.add(buttons_view);

for (var i=0;i<views.length;i++) {
    
    var button = Ti.UI.createButton({
        title: "view"+i,
        index: i,
        width: Math.floor(100/views.length)+"%", 
        height: Ti.UI.FILL,
        backgroundColor: "#aaa",
        color: "black",
        borderColor: "black",
    }); 
    
    button.addEventListener('click',function(e){
       change_view(this.index);
    });
    buttons[i] = button;
    buttons_view.add(button);

}

function change_view(index){
    console.log("change_view("+index+")");
    
    if (curr_view && curr_view.index == index) {
        console.log("can't change view, already on index "+index);
        return;
    }
    
    if (selected_button) selected_button.backgroundColor = "#ccc";
    selected_button = buttons[index];
    selected_button.backgroundColor = "white";
    
    if (curr_view) {
        curr_view.mapView.removeAnnotations(annos);
        win.remove(curr_view);
        curr_view.remove(curr_view.mapView);
        curr_view.mapView = null;
    }
    
    curr_view = views[index];
    
    curr_view.mapView = maps.createView({
        mapType: maps.MAP_TYPE_TERRAIN,
        indoorEnabled: false,
        indoorPicker: false,
        compassButton: false,
        myLocationButton: false,
        myLocationEnabled: false,
        region: {
            latitude: coords[0].latitude,
            longitude: coords[0].longitude,
            zoom: 3
        }
    });
    
    curr_view.add(curr_view.mapView);
    win.add(curr_view);
    
    
    curr_view.mapView.addAnnotations(annos);
    
}

change_view(0);

@hansemannn
Copy link
Owner

Yeah, that's a problem and not possible so far, because the annotations are stored in an internal data structure in the map view.

@hansemannn hansemannn added the bug label Jan 19, 2017
@bitfabrikken
Copy link
Contributor Author

Oh, I see. What's the best work-around you think?
The reason I prebuild them, is because some of the users on my app have 300+ annotations, and having to rebuild those every time they switch maps/pages is pretty bad for the UX.

@bitfabrikken
Copy link
Contributor Author

bitfabrikken commented Jan 19, 2017

Tried an alternate way: Having just one map created at startup, and removing it from one view, then adding it to another view. That doesn't work either; the map just doesn't appear to be added.

My idea here was to just reuse the same map, with the same annotations, and hiding/showing the annotations depending on the view.

It's beginning to look like the only way I will be able to make this work, is by creating the map view from scratch every time it is used.

Edit: Ooops closed it by mistake.

@bitfabrikken
Copy link
Contributor Author

I just made this example based on the above (see below), but this time the mapview and annotations are created every time the view is changed. It still crashes like above - any ideas?

Clicking each view button a few times in rapid succession:

Jan 19 13:12:17 Dans-Mac-mini TiShadow[61136]: assertion failed: 16C67 14B72: libxpc.dylib + 62597 [17F6B510-0FB1-30D3-B29C-D74A5D63719E]: 0x7d
Jan 19 13:12:20 Dans-Mac-mini TiShadow[61136]: 1 entries in the zip file
Jan 19 13:12:21 Dans-Mac-mini locationd[50232]: Location icon should now be in state 'Active'
Jan 19 13:12:21 Dans-Mac-mini TiShadow[61136]: Google Maps SDK for iOS and Google Places API for iOS version: 2.1.28321.0
Jan 19 13:12:22 Dans-Mac-mini CoreSimulatorBridge[50238]: Pasteboard change listener callback port <NSMachPort: 0x7fc69f626ae0> registered
Jan 19 13:12:26 Dans-Mac-mini TiShadow[61136]: TiShadow(61136,0x1177a23c0) malloc: *** error for object 0x6000003842a0: Invalid pointer dequeued from free list
	*** set a breakpoint in malloc_error_break to debug
Jan 19 13:12:26 Dans-Mac-mini com.apple.CoreSimulator.SimDevice.78A29E35-2726-46BF-8A9B-12A768CB0AF5.launchd_sim[50212] (UIKitApplication:dk.bitfabrikken.tishadow[0x650c][61136]): Service exited due to Abort trap: 6

Again switching between views by pressing the buttons (this time slowly):

Jan 19 13:14:24 Dans-Mac-mini TiShadow[61252]: objc[61252]: Class PLBuildVersion is implemented in both /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.1.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x11825c998) and /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.1.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x118081d38). One of the two will be used. Which one is undefined.
Jan 19 13:14:24 Dans-Mac-mini logd[50223]: metadata shared cached uuid is null (using logd's shared cache info) TiShadow (61252)
Jan 19 13:14:24 Dans-Mac-mini logd[50223]: Failed to harvest strings for pathless uuid '00000000-0000-0000-0000-000000000000'
Jan 19 13:14:24 Dans-Mac-mini TiShadow[61252]: assertion failed: 16C67 14B72: libxpc.dylib + 62597 [17F6B510-0FB1-30D3-B29C-D74A5D63719E]: 0x7d
Jan 19 13:14:27 Dans-Mac-mini TiShadow[61252]: 1 entries in the zip file
Jan 19 13:14:28 Dans-Mac-mini locationd[50232]: Location icon should now be in state 'Active'
Jan 19 13:14:28 Dans-Mac-mini TiShadow[61252]: Google Maps SDK for iOS and Google Places API for iOS version: 2.1.28321.0
Jan 19 13:14:29 Dans-Mac-mini TiShadow[61252]: TiShadow(61252,0x10d87b3c0) malloc: *** error for object 0x600000384920: Invalid pointer dequeued from free list
	*** set a breakpoint in malloc_error_break to debug
Jan 19 13:14:29 Dans-Mac-mini SpringBoard[50229]: [KeyboardArbiter] HW kbd: Failed to set (null) as keyboard focus
Jan 19 13:14:29 Dans-Mac-mini com.apple.CoreSimulator.SimDevice.78A29E35-2726-46BF-8A9B-12A768CB0AF5.launchd_sim[50212] (UIKitApplication:dk.bitfabrikken.tishadow[0x6cbb][61252]): Service exited due to Abort trap: 6

Crash at app startup after the above caused a crash:

Jan 19 13:15:53 Dans-Mac-mini TiShadow[61339]: objc[61339]: Class PLBuildVersion is implemented in both /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.1.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x1161ed998) and /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.1.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x116012d38). One of the two will be used. Which one is undefined.
Jan 19 13:15:53 Dans-Mac-mini logd[50223]: metadata shared cached uuid is null (using logd's shared cache info) TiShadow (61339)
Jan 19 13:15:53 Dans-Mac-mini logd[50223]: Failed to harvest strings for pathless uuid '00000000-0000-0000-0000-000000000000'
Jan 19 13:15:53 Dans-Mac-mini TiShadow[61339]: assertion failed: 16C67 14B72: libxpc.dylib + 62597 [17F6B510-0FB1-30D3-B29C-D74A5D63719E]: 0x7d
Jan 19 13:15:55 Dans-Mac-mini TiShadow[61339]: TiShadow(61339,0x700005441000) malloc: *** error for object 0x608000387d20: pointer being freed was not allocated
	*** set a breakpoint in malloc_error_break to debug
Jan 19 13:15:55 Dans-Mac-mini SpringBoard[50229]: [KeyboardArbiter] HW kbd: Failed to set (null) as keyboard focus
Jan 19 13:15:55 Dans-Mac-mini com.apple.CoreSimulator.SimDevice.78A29E35-2726-46BF-8A9B-12A768CB0AF5.launchd_sim[50212] (UIKitApplication:dk.bitfabrikken.tishadow[0x6cd0][61339]): Service exited due to Abort trap: 6
var maps = require("ti.googlemaps");
maps.setAPIKey("<YOUR_GOOGLE_MAPS_API_KEY>");

var win = Ti.UI.createWindow({
});

win.open();


var coords = [];
for (var i=0;i<50;i++) {
    coords.push({
        latitude: i,
        longitude: i
    });
}



//create views to switch between
var views = [];
var curr_view;
for (var i=0;i<3;i++) {
    views.push(Ti.UI.createView({
        backgroundColor: "green",
        bottom: 50,
        index: i
    }));
}


//create buttons for switching views
var buttons = [];
var selected_button = null;
var buttons_view = Ti.UI.createView({
    backgroundColor: "red",
    height: 50,
    bottom: 0,
    layout: "horizontal",
});
win.add(buttons_view);

for (var i=0;i<views.length;i++) {
    
    var button = Ti.UI.createButton({
        title: "view"+i,
        index: i,
        width: Math.floor(100/views.length)+"%", 
        height: Ti.UI.FILL,
        backgroundColor: "#aaa",
        color: "black",
        borderColor: "black",
    }); 
    
    button.addEventListener('click',function(e){
       change_view(this.index);
    });
    buttons[i] = button;
    buttons_view.add(button);

}

var busy = false;

function change_view(index){
    console.log("change_view("+index+")");
    
    if (busy) {
        console.log("BUSY");
        return;
        
    }
    busy = true;
    
    if (curr_view && curr_view.index == index) {
        console.log("can't change view, already on index "+index);
        return;
    }
    
    if (selected_button) selected_button.backgroundColor = "#ccc";
    selected_button = buttons[index];
    selected_button.backgroundColor = "white";
    
    if (curr_view) {
        console.log("removing mapView from curr_view index: "+curr_view.index);
        curr_view.remove(mapView);
        
        win.remove(curr_view);
        
    }
    
    curr_view = views[index];
    
    
    var mapView = maps.createView({
        mapType: maps.MAP_TYPE_TERRAIN,
        indoorEnabled: false,
        indoorPicker: false,
        compassButton: false,
        myLocationButton: false,
        myLocationEnabled: false,
        region: {
            latitude: coords[0].latitude,
            longitude: coords[0].longitude,
            zoom: 3
        }
    });
    curr_view.add(mapView);

    var annos = [];
    for (var i=0;i<50;i++) {
        var annotation = maps.createAnnotation({
            latitude: i,
            longitude: i,
            title: "title",
            subtitle: "subtitle",
            // pinColor: "green",
            // image: "myPin.png"
        });
        annos.push(annotation);
    }

    mapView.addAnnotations(annos);
    
    
    win.add(curr_view);
    
    busy = false;
    
    
}

change_view(0);

@bitfabrikken bitfabrikken reopened this Jan 19, 2017
@bitfabrikken
Copy link
Contributor Author

@hansemannn Can you tell me if I'm doing something wrong in the latest example above? I try to create the mapview + annotations every time from scratch, but there's still crashes, like when I try to reuse map/annotations.

@hansemannn
Copy link
Owner

I didn't look into multiple maps so far. But I can think that having an array that is used multiple times (even if pushed to multiple times), could cause issues. I would need to re-think the way to organize annotations internally, that's a biggie.

@bitfabrikken
Copy link
Contributor Author

@hansemannn Alright, I understand and thus why I tried to create both maps and annotations from scratch. But it still does crash, and I have no idea why it's happening. It's not that anything is reused in this case, so it doesn't make much sense to me.

@hansemannn
Copy link
Owner

I see TiShadow there, can you try it without?

@bitfabrikken
Copy link
Contributor Author

@hansemannn I just tried without TiShadow, running on simulator - it crashes immediately when launching (can see the views and buttons for a fraction of a second). Very weird that it actually can start in TiShadow, but not standalone. The output errors are:

[INFO] :   Application started
[INFO] :   test/1.0 (5.5.1.b18727f)
[INFO] :   [object TiGooglemapsModule] loaded
[INFO] :   change_view(0)
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextDrawImage: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGBitmapContextGetData: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextDrawImage: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGBitmapContextGetData: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextDrawImage: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGBitmapContextGetData: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextDrawImage: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGBitmapContextGetData: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextDrawImage: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGBitmapContextGetData: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextDrawImage: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGBitmapContextGetData: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextDrawImage: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGBitmapContextGetData: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextDrawImage: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGBitmapContextGetData: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextDrawImage: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGBitmapContextGetData: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   2017-01-20 14:13:33.294 test[67935:8163408] ((null)) was false: Cannot find image dav_one_way_16_256
[INFO] :   2017-01-20 14:13:33.294 test[67935:8163408] ((null)) was false: Image data can't be NULL.
[INFO] :   2017-01-20 14:13:33.295 test[67935:8163408] ((null)) was false: Invalid texture state for dav_one_way_16_256.
[INFO] :   2017-01-20 14:13:33.295 test[67935:8163408] ((null)) was false: Cannot find image polyline_colors_texture
[INFO] :   2017-01-20 14:13:33.295 test[67935:8163408] ((null)) was false: Image data can't be NULL.
[INFO] :   2017-01-20 14:13:33.295 test[67935:8163408] ((null)) was false: Invalid texture state for routesTextureState.
[INFO] :   2017-01-20 14:13:33.296 test[67935:8163408] ((null)) was false: Cannot find image polyline_colors_texture_dim
[INFO] :   2017-01-20 14:13:33.296 test[67935:8163408] ((null)) was false: Image data can't be NULL.
[INFO] :   2017-01-20 14:13:33.296 test[67935:8163408] ((null)) was false: Invalid texture state for routesDimTextureState.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextSetStrokeColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextGetCompositeOperation: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextSetCompositeOperation: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextFillRects: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextSetCompositeOperation: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextSetStrokeColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextGetBlendMode: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextSetBlendMode: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextFillRects: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextSetBlendMode: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextSetStrokeColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextGetBlendMode: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextSetBlendMode: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextFillRects: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   Jan 20 14:13:33  test[67935] <Error>: CGContextSetBlendMode: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[INFO] :   2017-01-20 14:13:33.364 test[67935:8163408] This app has attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSLocationWhenInUseUsageDescription key with a string value explaining to the user how the app uses this data
[INFO] :   2017-01-20 14:13:33.384 test[67935:8163408] ((null)) was false: Cannot find image GMSSprites-0-2x
[INFO] :   test(67935,0x10b6ae3c0) malloc: *** error for object 0x7fdc8bc0f0e8: incorrect checksum for freed object - object was probably modified after being freed.
[INFO] :   *** set a breakpoint in malloc_error_break to debug

@hansemannn
Copy link
Owner

[INFO] : 2017-01-20 14:13:33.364 test[67935:8163408] This app has attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSLocationWhenInUseUsageDescription key with a string value explaining to the user how the app uses this data

@bitfabrikken
Copy link
Contributor Author

@hansemannn I added it now and rebuilt (cleaned too), but the iOS location dialog disappears too quickly to accept. I did however go to settings and enabled location for the app. Still crashes on startup with the same errors.

@hansemannn
Copy link
Owner

Another note: Don't (ever) access sub-view references using the dot-assignment (curr_view.mapView.removeAnnotations) and instead call methods on the map view directly.

@bitfabrikken
Copy link
Contributor Author

OK but I am not doing that in the latest example above, and it still crashes.

@bitfabrikken
Copy link
Contributor Author

@hansemannn is there any way I can get you to run the latest example above? To confirm/not confirm if it's also occuring on your end?

@bitfabrikken
Copy link
Contributor Author

@hansemannn I played around with it some more, and now it doesn't crash, when switching between views. The difference? Using mapView.addAnnotation for each annotation seperately, instead of addAnnotations. So there might be some issues with that particular function.

Working example using single addAnnotation, where addAnnotations is commented out (crashes when switching views several times):

var maps = require("ti.googlemaps");
maps.setAPIKey("<YOUR_GOOGLE_MAPS_API_KEY>");

var win = Ti.UI.createWindow({
});
win.open();


var coords = [];
for (var i=0;i<50;i++) {
    coords.push({
        latitude: i,
        longitude: i
    });
}



//create views to switch between
var views = [];
var curr_view;
for (var i=0;i<3;i++) {
    views.push(Ti.UI.createView({
        backgroundColor: "green",
        bottom: 50,
        index: i
    }));
}


//create buttons for switching views
var buttons = [];
var selected_button = null;
var buttons_view = Ti.UI.createView({
    backgroundColor: "red",
    height: 50,
    bottom: 0,
    layout: "horizontal",
});
win.add(buttons_view);

for (var i=0;i<views.length;i++) {
    
    var button = Ti.UI.createButton({
        title: "view"+i,
        index: i,
        width: Math.floor(100/views.length)+"%", 
        height: Ti.UI.FILL,
        backgroundColor: "#aaa",
        color: "black",
        borderColor: "black",
    }); 
    
    button.addEventListener('click',function(e){
       change_view(this.index);
    });
    buttons[i] = button;
    buttons_view.add(button);

}

var busy = false;


var mapView;
function change_view(index){
    console.log("change_view("+index+")");
    
    if (busy) {
        console.log("BUSY");
        return;
        
    }
    busy = true;
    
    if (curr_view && curr_view.index == index) {
        console.log("can't change view, already on index "+index);
        return;
    }
    
    if (selected_button) selected_button.backgroundColor = "#ccc";
    selected_button = buttons[index];
    selected_button.backgroundColor = "white";
    
    if (curr_view) {
        console.log("removing mapView from curr_view index: "+curr_view.index);
        
        mapView.removeAllAnnotations();
        
        curr_view.remove(mapView); 
          
        win.remove(curr_view);
          
        mapView = null;
         
        delete mapView;
        
    } 
    
    curr_view = views[index];
    
    
    mapView = maps.createView({
        mapType: maps.MAP_TYPE_TERRAIN,
        indoorEnabled: false,
        indoorPicker: false,
        compassButton: false,
        myLocationButton: false,
        myLocationEnabled: false,
        region: {
            latitude: coords[0].latitude,
            longitude: coords[0].longitude,
            zoom: 3
        }
    });
    curr_view.add(mapView);

   // var annos = [];
    for (var i=0;i<50;i++) {
        var annotation = maps.createAnnotation({
            latitude: i+i, 
            longitude: i,
            title: "title",
            subtitle: "subtitle",
            // pinColor: "green",
            // image: "myPin.png"
        });
        //annos.push(annotation);
        mapView.addAnnotation(annotation);
    }

    //mapView.addAnnotations(annos);
    
  
    win.add(curr_view);
    
    busy = false;
    
    
}

change_view(0);

@bitfabrikken
Copy link
Contributor Author

@hansemannn The other crashes were caused by having both run-on-main-thread and use-app-thinning enabled. Everything works fine with those two disabled (except for mapView.addAnnotations). I apologize for the confusion, I wasn't aware of those "new" parameters.

@hansemannn
Copy link
Owner

That are interesting findings! I pushed some changes that should fix the main-thread issues (the app-thinning shouldn't affect this). The addAnnotations was also changed now, give it a try. Please build from the source to get the patch from master.

@bitfabrikken
Copy link
Contributor Author

Just tested with 2.7.0, works splendidly! Thank you so much for all your work @hansemannn :)

@hansemannn
Copy link
Owner

@bitfabrikken So the one from master (self-built) or from the Releases page? I didn't update that version so far.

@bitfabrikken
Copy link
Contributor Author

@hansemannn Just a side note, the original example in the first post here, also works now. That is, the example where I only create the annotations once, and then reuse them on subsequent mapViews! This is awesome!

@bitfabrikken
Copy link
Contributor Author

@hansemannn I'm not sure, I just did "git pull"

@hansemannn
Copy link
Owner

that's from master, thx! Will release a 2.7.1 with that patch then. 🚀

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

No branches or pull requests

2 participants