I'm a beginner of skia, I built skia as a static lib on my macos,and made a demo code, but it crash on sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul function, i pass 400, 500 for it, but when i print it in SkSurface::MakeRasterN32Premul function,it is changed to a strange value, and failed to create surface , the output is:
Hello, World!
w=-1074793840 h=400
Program ended with exit code: 9
where i print is SkSurface_Raster.cpp:
sk_sp<SkSurface> SkSurface::MakeRasterN32Premul(int width, int height,
const SkSurfaceProps* surfaceProps) {
std::cout << "w=" << width << " h=" << height << std::endl;
return MakeRaster(SkImageInfo::MakeN32Premul(width, height), surfaceProps);
}
the build cmd is :
bin/gn gen out/Static --args=" is_official_build=false extra_cflags_cc=["-frtti"] "
i repeat everythine on ubuntu, i works fine, everythine is ok. I don't know what worry with my code, can anyone help me , thanks
my code is:
#include "SkSurface.h"
#include "SkPath.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkImage.h"
#include "SkStream.h"
#include "SkImageInfo.h"
void draw(SkCanvas* canvas) {
canvas->save();
canvas->translate(SkIntToScalar(128), SkIntToScalar(128));
canvas->rotate(SkIntToScalar(45));
SkRect rect = SkRect::MakeXYWH(-90.5f, -90.5f, 181.0f, 181.0f);
SkPaint paint;
paint.setColor(SK_ColorBLUE);
canvas->drawRect(rect, paint);
canvas->restore();
}
int haha() {
const int width = 400;
const int height = 500;
const char* path = "demo.png";
sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(width, height);
if (surface) {
std::cout << "good surface" << std::endl;
std::cout << surface->width() << std::endl;
std::cout << surface->height() << std::endl;
} else {
std::cout << "bad surface 0" << std::endl;
}
SkCanvas* rasterCanvas = surface->getCanvas();
//draw(rasterCanvas);
sk_sp<SkImage> img(surface->makeImageSnapshot());
if (!img) { return 0; }
sk_sp<SkData> png(img->encodeToData());
if (!png) { return 0; }
SkFILEWStream out(path);
(void)out.write(png->data(), png->size());
return 0;
}
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
haha();
return 0;
}