Skip to content

Commit

Permalink
Merge pull request #153 from yixy-only/fix_crash_when_newimage_before…
Browse files Browse the repository at this point in the history
…_initgraph

Fix: 修复在 inigraph() 之前调用 newimage()  会引起程序崩溃的问题
  • Loading branch information
chirsz-ever authored Apr 18, 2024
2 parents 008d333 + 29e6e5e commit 176658e
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
@@ -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
@@ -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
}
}
@@ -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
@@ -61,6 +61,7 @@ void IMAGE::construct(int width, int height)
refDC = ::GetDC(graph_setting.hwnd);
}

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

0 comments on commit 176658e

Please sign in to comment.