Skip to content

Commit

Permalink
Fix: 修复的在 inigraph() 之前调用 newimage() 会引起程序崩溃的问题
Browse files Browse the repository at this point in the history
 原因: 在创建图像时创建了 GDI+ 对象但并未在此之前对 GDI+ 进行初始化 。wysaid#59 中引入(083423f)
  • Loading branch information
yixy-only committed Apr 17, 2024
1 parent 008d333 commit 29e6e5e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/ege_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ int waitdealmessage(_graph_setting* pg);
float EGE_PRIVATE_GetFPS(int add); // 获取帧数

void setmode(int gdriver, int gmode);

// GDI+ 初始化
void gdipluinit();
}
11 changes: 9 additions & 2 deletions src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,7 @@ inline void init_img_page(struct _graph_setting* pg)
{
if (!pg->has_init) {
#ifdef EGE_GDIPLUS
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&pg->g_gdiplusToken, &gdiplusStartupInput, NULL);
gdipluinit();
#endif
}
}
Expand Down Expand Up @@ -1015,4 +1014,12 @@ long getGraphicsVer()
return EGE_VERSION_NUMBER;
}

void gdipluinit()
{
if (graph_setting.g_gdiplusToken == 0) {
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&graph_setting.g_gdiplusToken, &gdiplusStartupInput, NULL);
}
}

} // namespace ege
1 change: 1 addition & 0 deletions src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void IMAGE::construct(int width, int height)
refDC = ::GetDC(graph_setting.hwnd);
}

gdipluinit();
reset();
initimage(refDC, width, height);
setdefaultattribute();
Expand Down

0 comments on commit 29e6e5e

Please sign in to comment.