diff --git a/src/widgets.cpp b/src/widgets.cpp index b6424d0..ce398c3 100644 --- a/src/widgets.cpp +++ b/src/widgets.cpp @@ -56,18 +56,15 @@ static Image *loadIntoImageCache(Context &ctx, const char *filename) { return image; } - image = new Image; - if (image == nullptr) { - return nullptr; - } - - int w, h, bytesPerPixel; + int w = 0; + int h = 0; + int bytesPerPixel = 0; unsigned char *data = stbi_load(filename, &w, &h, &bytesPerPixel, 0); if (data == nullptr) { return nullptr; } - - + + image = new Image; int pitch = w * bytesPerPixel; pitch = (pitch + 3) & ~3; image->mSurfaceImpl = Renderer::createSurfaceImpl(data, w, h, bytesPerPixel, pitch);