浏览代码

image: better error detection in the GDI+ image codec.

legacy
Sam Hocevar sam 12 年前
父节点
当前提交
72a6839dce
共有 1 个文件被更改,包括 27 次插入15 次删除
  1. +27
    -15
      src/image/codec/gdiplus-image.cpp

+ 27
- 15
src/image/codec/gdiplus-image.cpp 查看文件

@@ -50,6 +50,18 @@ private:

bool GdiPlusImageData::Open(char const *path)
{
Gdiplus::Status status;
ULONG_PTR token;
Gdiplus::GdiplusStartupInput input;
status = Gdiplus::GdiplusStartup(&token, &input, NULL);
if (status != Gdiplus::Ok)
{
#if !LOL_RELEASE
Log::Error("error %d while initialising GDI+\n", status);
#endif
return false;
}

size_t len;
len = mbstowcs(NULL, path, 0);
wchar_t *wpath = new wchar_t[len + 1];
@@ -62,30 +74,30 @@ bool GdiPlusImageData::Open(char const *path)
return false;
}

ULONG_PTR token;
Gdiplus::GdiplusStartupInput input;
Gdiplus::GdiplusStartup(&token, &input, NULL);

bitmap = NULL;
status = Gdiplus::Ok;
for (wchar_t const *wname = wpath; *wname; wname++)
if ((bitmap = Gdiplus::Bitmap::FromFile(wname, 0)))
break;

delete[] wpath;
if (!bitmap)
{
bitmap = Gdiplus::Bitmap::FromFile(wname, 0);
if (bitmap)
{
status = bitmap->GetLastStatus();
if (status == Gdiplus::Ok)
break;
#if !LOL_RELEASE
Log::Error("could not load %s\n", path);
if (status != Gdiplus::InvalidParameter)
Log::Error("error %d loading %s\n", status, path);
#endif
return false;
delete bitmap;
}
}

if (bitmap->GetLastStatus() != Gdiplus::Ok)
delete[] wpath;
if (!bitmap)
{
#if !LOL_RELEASE
Log::Error("error %d loading %s\n",
(unsigned)bitmap->GetLastStatus(), path);
Log::Error("could not load %s\n", path);
#endif
delete bitmap;
return false;
}



正在加载...
取消
保存