Skip to content

Commit 5870da4

Browse files
committed
Fix crash in drawQuery for layers with labelitem (#5281)
1 parent 8771b59 commit 5870da4

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

mapdraw.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ int pointLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj
15681568
}
15691569
if(MS_DRAW_LABELS(drawmode)) {
15701570
if (layer->labelcache) {
1571-
if (msAddLabelGroup(map, image, layer->index, c, shape, point, -1) != MS_SUCCESS) return (MS_FAILURE);
1571+
if (msAddLabelGroup(map, image, layer, c, shape, point, -1) != MS_SUCCESS) return (MS_FAILURE);
15721572
} else {
15731573
for (l = 0; l < layer->class[c]->numlabels; l++)
15741574
if(msGetLabelStatus(map,layer,shape,layer->class[c]->labels[l]) == MS_ON) {
@@ -1765,7 +1765,7 @@ int polygonLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer,
17651765
for (i = 0; i < layer->class[c]->numlabels; i++)
17661766
if (layer->class[c]->labels[i]->angle != 0) layer->class[c]->labels[i]->angle -= map->gt.rotation_angle; /* TODO: is this correct ??? */
17671767
if (layer->labelcache) {
1768-
if (msAddLabelGroup(map, image, layer->index, c, anno_shape, &annopnt,
1768+
if (msAddLabelGroup(map, image, layer, c, anno_shape, &annopnt,
17691769
MS_MIN(shape->bounds.maxx - shape->bounds.minx, shape->bounds.maxy - shape->bounds.miny)) != MS_SUCCESS) {
17701770
return MS_FAILURE;
17711771
}

maplabel.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, char
273273
ts->rotation = l->angle * MS_DEG_TO_RAD;
274274
}
275275

276-
int msAddLabelGroup(mapObj *map, imageObj *image, int layerindex, int classindex, shapeObj *shape, pointObj *point, double featuresize)
276+
int msAddLabelGroup(mapObj *map, imageObj *image, layerObj* layer, int classindex, shapeObj *shape, pointObj *point, double featuresize)
277277
{
278278
int l,s, priority;
279279
labelCacheSlotObj *cacheslot;
@@ -283,8 +283,11 @@ int msAddLabelGroup(mapObj *map, imageObj *image, int layerindex, int classindex
283283
classObj *classPtr=NULL;
284284
int numtextsymbols = 0;
285285
textSymbolObj **textsymbols, *ts;
286+
int layerindex = layer->index;
286287

287-
layerPtr = (GET_LAYER(map, layerindex)); /* set up a few pointers for clarity */
288+
// We cannot use GET_LAYER here because in drawQuery the drawing may happen
289+
// on a temp layer only.
290+
layerPtr = layer;
288291
classPtr = GET_LAYER(map, layerindex)->class[classindex];
289292

290293
if(classPtr->numlabels == 0) return MS_SUCCESS; /* not an error just nothing to do */

mapserver.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2308,7 +2308,7 @@ void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, char
23082308
MS_DLL_EXPORT int WARN_UNUSED msGetStringSize(mapObj *map, labelObj *label, int size, char *string, rectObj *r);
23092309

23102310
MS_DLL_EXPORT int WARN_UNUSED msAddLabel(mapObj *map, imageObj *image, labelObj *label, int layerindex, int classindex, shapeObj *shape, pointObj *point, double featuresize, textSymbolObj *ts);
2311-
MS_DLL_EXPORT int WARN_UNUSED msAddLabelGroup(mapObj *map, imageObj *image, int layerindex, int classindex, shapeObj *shape, pointObj *point, double featuresize);
2311+
MS_DLL_EXPORT int WARN_UNUSED msAddLabelGroup(mapObj *map, imageObj *image, layerObj *layer, int classindex, shapeObj *shape, pointObj *point, double featuresize);
23122312
MS_DLL_EXPORT void insertRenderedLabelMember(mapObj *map, labelCacheMemberObj *cachePtr);
23132313
MS_DLL_EXPORT int msTestLabelCacheCollisions(mapObj *map, labelCacheMemberObj *cachePtr, label_bounds *lb, int current_priority, int current_label);
23142314
MS_DLL_EXPORT int msTestLabelCacheLeaderCollision(mapObj *map, pointObj *lp1, pointObj *lp2);

0 commit comments

Comments
 (0)