gpt4 book ai didi

ios - 自定义标记性能 iOS,崩溃,结果为 "((null)) was false: Reached the max number of texture atlases, can not allocate more."

转载 作者:可可西里 更新时间:2023-11-01 03:18:35 42 4
gpt4 key购买 nike

我在我的应用程序中集成了 Google map ,并且还使用了 Google Places API。在我从 Google Places API(大约 60 个)获得所有结果后,我在自定义标记的帮助下显示它们。我正在制作的自定义标记包括“地点图像”和“地点名称”,因此我必须先在 UIView 中绘制它,然后借助以下函数将其呈现为 UIImage

- (UIImage *)imageFromView:(UIView *) view
{
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {

UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, [[UIScreen mainScreen] scale]);
} else {
UIGraphicsBeginImageContext(view.frame.size);
}
[view.layer renderInContext: UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return image;
}

首先所有的标记都被渲染和绘制得很容易。

现在我有一个 slider ,范围从 100 米到 5 公里,用作搜索半径优化器。由于 slider 将移动(假设值为 2km),因此所有标记都将被删除,并且仅再次绘制与用户位置的距离小于 slider 值的那些标记。在我测试 slider 功能时,应用程序崩溃并显示

((null)) was false: Reached the max number of texture atlases, can not allocate more.

我上传屏幕截图是为了清楚地了解情况。请帮忙。

image when radius is 5km

image when radius is 2.4km

image when radius is 1.7km

还要提一下,在屏幕上您会看到绿色标记和蓝色标记。蓝色标记是那些离用户位置较近的标记,而绿色标记则远离特定距离。由于用户位置会发生变化,因此有两种情况:

  1. 如果它正在接近一个绿色标记,那么它将转向一个蓝色标记
  2. 如果它远离蓝色标记,那么它会变成绿色标记。

最佳答案

我正在开发一个可以有数千个化身在 map 上四处移动的应用程序,并且也遇到了这个错误。聚类是一个潜在的解决方案,但由于这么多化身都在移动,我怀疑计算会过于占用 CPU。

我使用的解决方案是保留对基本头像图像的引用,并在屏幕上显示超过 50 个头像时使用它。只有当屏幕上有 < 50 个头像时,我才会为每个头像生成唯一的图像和他们的名字。

// GMSMarker
static var avatarDic:[String:UIImage] = Dictionary()

func removeName() {
// use a single image reference here so that google map does not crash
if let image = avatarDic[avatarBase] {
self.icon = image
}
else {
avatarDic[avatarBase] = UIImage(named:avatarBase)
self.icon = avatarDic[avatarBase]
}
}

func addName() {
self.icon = // draw name on base image
}

// GMSMapView
var userIcons:[String:MyMarker] = Dictionary()
var iconWithNames:Set<MyMarker> = Set()

func mapView(mapView: GMSMapView!, didChangeCameraPosition position: GMSCameraPosition!) {
// find visible avatars til limit
let bottomLeft = self.mapView.projection.visibleRegion().nearLeft
let topRight = self.mapView.projection.visibleRegion().farRight
var visibleMarkerSet:Set<MyMarker> = Set()
for (key, marker) in self.userIcons {
if (marker.position.latitude > bottomLeft.latitude && marker.position.latitude < topRight.latitude && marker.position.longitude > bottomLeft.longitude && marker.position.longitude < topRight.longitude) {
visibleMarkerSet.insert(marker)
}

// not showing if > 50
if (visibleMarkerSet.count > 50) {
visibleMarkerSet = Set()
break
}
}

// remove names
for markerWithName in self.iconWithNames {
if (visibleMarkerSet.contains(markerWithName) == false) {
markerWithName.removeName()
}
}
// add names
for visibleMarker in visibleMarkerSet {
visibleMarker.addName()
}
self.iconWithNames = visibleMarkerSet
}

关于ios - 自定义标记性能 iOS,崩溃,结果为 "((null)) was false: Reached the max number of texture atlases, can not allocate more.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29390359/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com