2

I have a function that instantiates an object of "SkPath" on stack. After that I call few functions such as "moveTo", "lineTo", "cubicTo" ( which is simply adds new points to inner array inside of the SkPath object). Then I instantiate object of "SkPaint" class also on the stack.

Then I call "drawPath" function of "SkCanvas" object and pass SkPath and SkPaint objects as args and, it crashes.

I've done some investigation. It turns out that array inside SkPath is not valid anymore because the constructor of SkPaint is nulling its (SkPaint's) object by calling sk_bzero(this, sizeof(*this)); ("memset" to 0 for "pointer" with size of "*pointer") by doing this it also somehow cleans up pointer to array that belongs to previously declared object of SkPath.

I have fixed it by instantiation SkPaint before SkPath but problem still remains, since I have few more issues similar to this one and well... I want to understand what is going on. The same code works fine on Android 2.2.

I'm not using hardware acceleration.

SkPath skPath;  
skPath.setFillType(fillType);
skPath.moveTo(x1, y1);
skPath.cubicTo(x1, y1, x2, y2, x3, y3);
skPath.lineTo(x1, y1);
skPath.close();

SkPaint paint; //<- will call constructor that cleans up pointer to array

paint.setAntiAlias(true);
GfxRGB rgb;
state->getFillRGB(&rgb);
paint.setColor(GfxRGB2SkColor(rgb));
paint.setStyle(SkPaint::kFill_Style);
paint.setAlpha((U8CPU) (state->getFillOpacity() * 255));

canvas->drawPath(skPath, paint); // <- will crash here
Programmer Bruce
  • 64,977
  • 7
  • 99
  • 97
user714917
  • 21
  • 3
  • you're not showing how `canvas` is initialized - can it be null there? also you're using object `skPath`, but passing `path` to `drawPath` so either this doesn't compile, or you've left out important detais. – Mat Apr 19 '11 at 11:17
  • Moreover if you try to call getPoints right after SkPoint instantiation exception will be thrown. Could it be somehow related to Motorolla Xoom hardware architecture? Maybe because of the dual core processor? – user714917 Apr 20 '11 at 10:54
  • @Mat No, "canvas" initialized properly. As I've mentioned before it works if you initialize SkPaint before SkPath. According to "path" instead of "skPath" I left it there by mistake wile copy-pasting. Sorry. – user714917 Apr 20 '11 at 10:56

0 Answers0