Index: src/obj_arc.c =================================================================== --- src/obj_arc.c (revision 27882) +++ src/obj_arc.c (revision 27883) @@ -377,8 +377,16 @@ /* copies an arc to buffer */ void *pcb_arcop_add_to_buffer(pcb_opctx_t *ctx, pcb_layer_t *Layer, pcb_arc_t *Arc) { - pcb_layer_t *layer = &ctx->buffer.dst->Layer[pcb_layer_id(ctx->buffer.src, Layer)]; - pcb_arc_t *a = pcb_arc_new(layer, Arc->X, Arc->Y, + pcb_arc_t *a; + pcb_layer_id_t lid = pcb_layer_id(ctx->buffer.src, Layer); + pcb_layer_t *layer; + + /* the buffer may not have the specified layer, e.g. on loose subc subc-aux layer */ + if (lid == -1) + return NULL; + + layer = &ctx->buffer.dst->Layer[lid]; + a = pcb_arc_new(layer, Arc->X, Arc->Y, Arc->Width, Arc->Height, Arc->StartAngle, Arc->Delta, Arc->Thickness, Arc->Clearance, pcb_flag_mask(Arc->Flags, PCB_FLAG_FOUND | ctx->buffer.extraflg), pcb_false); Index: src/obj_line.c =================================================================== --- src/obj_line.c (revision 27882) +++ src/obj_line.c (revision 27883) @@ -420,7 +420,14 @@ void *pcb_lineop_add_to_buffer(pcb_opctx_t *ctx, pcb_layer_t *Layer, pcb_line_t *Line) { pcb_line_t *line; - pcb_layer_t *layer = &ctx->buffer.dst->Layer[pcb_layer_id(ctx->buffer.src, Layer)]; + pcb_layer_id_t lid = pcb_layer_id(ctx->buffer.src, Layer); + pcb_layer_t *layer; + + /* the buffer may not have the specified layer, e.g. on loose subc subc-aux layer */ + if (lid == -1) + return NULL; + + layer = &ctx->buffer.dst->Layer[lid]; line = pcb_line_new(layer, Line->Point1.X, Line->Point1.Y, Line->Point2.X, Line->Point2.Y, Line->Thickness, Line->Clearance, pcb_flag_mask(Line->Flags, PCB_FLAG_FOUND | ctx->buffer.extraflg)); Index: src/obj_poly.c =================================================================== --- src/obj_poly.c (revision 27882) +++ src/obj_poly.c (revision 27883) @@ -499,9 +499,16 @@ /* copies a polygon to buffer */ void *pcb_polyop_add_to_buffer(pcb_opctx_t *ctx, pcb_layer_t *Layer, pcb_poly_t *Polygon) { - pcb_layer_t *layer = &ctx->buffer.dst->Layer[pcb_layer_id(ctx->buffer.src, Layer)]; pcb_poly_t *polygon; + pcb_layer_id_t lid = pcb_layer_id(ctx->buffer.src, Layer); + pcb_layer_t *layer; + /* the buffer may not have the specified layer, e.g. on loose subc subc-aux layer */ + if (lid == -1) + return NULL; + + layer = &ctx->buffer.dst->Layer[lid]; + polygon = pcb_poly_new(layer, Polygon->Clearance, Polygon->Flags); pcb_poly_copy(polygon, Polygon, 0, 0); pcb_poly_copy_meta(polygon, Polygon);