This looks like a bad corner case for handling clipPath .
canvas.clipPath(fourthPath);
causes merging with the previous firstPath , however, since they are complex (non-rectangular) shapes, the system tries to draw them as scanlines and merge them subsequently. To do this merge, it needs to allocate some memory, but as you can see in SkRegion.cpp , it is suitable for the heuristic worst case .
static int compute_worst_case_count(int a_count, int b_count) { int a_intervals = count_to_intervals(a_count); int b_intervals = count_to_intervals(b_count);
For your paths, this worst_case_count approaching 2 GB and you get an interrupt due to not getting this large memory from malloc .
I could not find a way out of this using different parameters. Anything that avoids merging clipPath should help, for example, call clipPath with Region.Op.REPLACE . Region.Op.INTERSECT does not work either.
I would like to focus on avoiding calling a clip in a complex way on top of a complex path.
If this suits your use case, you can use the same Path object to set canvas.clipPath() . For example:
Picture picture = new Picture(); Canvas canvas = picture.beginRecording(12240, 15840); Path path = new Path(); path.moveTo(3058, 12365); path.lineTo(8499, 3038); path.lineTo(9494, 3619); path.lineTo(4053, 12946); path.close(); canvas.clipPath(path); // do stuff with canvas path.moveTo(3065, 12332); path.lineTo(4053, 12926); path.lineTo(9615, 3669); path.lineTo(8628, 3075); path.close(); canvas.clipPath(path, Region.Op.REPLACE); // do more stuff with canvas picture.endRecording(); return picture;
Since Path contains the previous figures, you can simply continue updating it. If this does not apply to your case, you need to either make these numbers smaller, or break complex areas into smaller ones to avoid the worst case heuristic , to get too big.