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

Crash in MBImageAPI #34

Open
natalia-osa opened this issue Aug 28, 2018 · 2 comments
Open

Crash in MBImageAPI #34

natalia-osa opened this issue Aug 28, 2018 · 2 comments

Comments

@natalia-osa
Copy link
Contributor

natalia-osa commented Aug 28, 2018

Crash happens when trying to fetch a larger map size.

MapboxImageAPI.swift line 227:

group.notify(queue: DispatchQueue.main) {
    self.pendingFetches.removeValue(forKey: groupID)
    completion(!hadFailure ? imageBuilder.makeImage() : nil) // HERE: EXC_BAD_ACCESS (code=2
}

what later affects:

terrainNode.fetchTerrainTexture("mapbox/satellite-v9", zoom: 14, progress: { _, _ in }, completion: { image in
    terrainNode.geometry?.materials[4].diffuse.contents = image // here
})

In the console I receive tons of following informations:
2018-08-28 13:46:51.938021+0200 AppName[1937:978808] [Unknown process name] CGBitmapContextInfoCreate: unable to allocate 608605984 bytes for bitmap data

@avi-c
Copy link
Contributor

avi-c commented Aug 28, 2018

This issue and Issue #33 have the same root cause. Since the SDK right now uses a fixed zoom level of 12 when asking for tiles regardless of the lat/lon bounds that are being rendered, there are problems when the lat/lon bounds exceed some threshold. The image API will request the necessary number of tiles at zoom level 12 that are needed to cover the request bounds. When it tries to stitch all those tiles together into a single CGImage for the terrain image or heightmap image, if the resultant CGImage would exceed the allowable size then no image is created and we'll later crash because of it.

I have an experimental fix for this that dynamically calculates the zoom level while trying to minimize the size of the final image. I don't think it's quite ready to merge into master, but I'll put it up as a PR for everyone to check out.

@avi-c
Copy link
Contributor

avi-c commented Aug 28, 2018

I created PR #39 with my proposal for preventing this crash.

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

2 participants