SkSurface::MakeRasterN32Premul input parm is abnormal and crash on macos(13.1)

75 views
Skip to first unread message

Mr. T

unread,
Mar 12, 2023, 11:14:35 AM3/12/23
to skia-discuss

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;
}

craste...@gmail.com

unread,
Mar 12, 2023, 1:52:50 PM3/12/23
to skia-discuss
I would point out that, not only is the width weird, but the height is incorrect too.
Could it be that the Skia library was compiled with a different definition of what an "int" is from your main application?

Mr. T

unread,
Mar 29, 2023, 12:06:22 PM3/29/23
to skia-discuss
did you slove it?

craste...@gmail.com

unread,
Mar 29, 2023, 11:04:46 PM3/29/23
to skia-discuss
I wasn't trying to solve it.  I don't have that problem and I don't have a machine with macos.
I was trying to suggest you investigate the size of an int in your application vs the size of an int in your skia library.
If they are different, then that might be the problem.

Reply all
Reply to author
Forward
0 new messages