Skip to content

Commit c8c7fe6

Browse files
committed
描画の際にメモリリークしている問題を修正
1 parent 81092bd commit c8c7fe6

24 files changed

+568
-197
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[こちら](https://github.com/mimaraka/aviutl-plugin-curve_editor/releases/latest)から最新バージョンのCurve Editor(`curve_editor-v*.zip`)をダウンロードしてください。
88

99
## インストール
10-
同梱されている`curve_editor.auf``exedit.auf`のあるフォルダもしくは`plugins`フォルダ内に入れ、`@Curve Editor.tra``script`フォルダ**直下**に入れてください。
10+
`curve_editor-v*.zip`を解凍し、同梱されている`curve_editor.auf``exedit.auf`のあるフォルダもしくは`plugins`フォルダ内に入れ、`@Curve Editor.tra``script`フォルダ**直下**に入れてください。
1111
(※scriptフォルダ直下に入れないと、ドラッグ&ドロップ機能を使用することができません。)
1212
[Visual C++ 2015/2017/2019/2022 再頒布可能パッケージ (x86)](https://aka.ms/vs/17/release/vc_redist.x86.exe)をインストールしていない場合は、こちらもインストールしてください。
1313

@@ -100,5 +100,12 @@ AviUtl 1.00, 1.10
100100
## バグ報告
101101
バグ報告はこのリポジトリのIssuesまたはTwitter([@mimaraka](https://twitter.com/mimaraka))のDMにてお願いします。
102102

103+
## その他
104+
当プラグイン・スクリプトは以下のプラグイン・スクリプトを参考にして作成されました:
105+
- [ベジェ軌道T](https://www.nicovideo.jp/watch/sm20632293)
106+
- [Aulsグラフエディタ](https://auls.client.jp/)
107+
- [イージング設定時短プラグイン](https://github.com/kumrnm/aviutl-easing-quick-setup)
108+
- [イージング簡単選択](https://github.com/hebiiro/AviUtl-Plugin-SelectEasing)
109+
103110
## 免責事項
104111
当プラグイン・スクリプトを使用したことによっていかなる損害が生じても、製作者は一切の責任を負わないものとします。

curve_editor/curve_editor.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ copy "$(SolutionDir)@Curve Editor.tra" "C:\Users\njotn\UserDirectory\AviUtl_Plug
217217
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
218218
</ClCompile>
219219
<ClCompile Include="cve_curve_bezier_value.cpp" />
220+
<ClCompile Include="cve_d2d_paint.cpp" />
220221
<ClCompile Include="cve_dialogproc.cpp">
221222
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">/Zc:strictStrings- %(AdditionalOptions)</AdditionalOptions>
222223
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">/Zc:strictStrings- %(AdditionalOptions)</AdditionalOptions>

curve_editor/curve_editor.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
<ClCompile Include="cve_editbox.cpp">
7676
<Filter>ソース ファイル</Filter>
7777
</ClCompile>
78+
<ClCompile Include="cve_d2d_paint.cpp">
79+
<Filter>ソース ファイル</Filter>
80+
</ClCompile>
7881
</ItemGroup>
7982
<ItemGroup>
8083
<ClInclude Include="cve_header.hpp">

curve_editor/cve_bitmap_buffer.cpp

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,31 @@
1313

1414

1515
//---------------------------------------------------------------------
16-
// 初期化
16+
// コンストラクタ
1717
//---------------------------------------------------------------------
18+
cve::Bitmap_Buffer::Bitmap_Buffer() :
19+
bitmap(NULL),
20+
hwnd(NULL),
21+
hdc_memory(NULL),
22+
brush(nullptr),
23+
rect({NULL})
24+
{}
25+
26+
27+
28+
//---------------------------------------------------------------------
29+
// デストラクタ
30+
//---------------------------------------------------------------------
31+
cve::Bitmap_Buffer::~Bitmap_Buffer()
32+
{
33+
DeleteDC(hdc_memory);
34+
DeleteObject(bitmap);
35+
36+
release(&brush);
37+
}
38+
39+
40+
1841
void cve::Bitmap_Buffer::init(HWND hw)
1942
{
2043
hwnd = hw;
@@ -24,21 +47,9 @@ void cve::Bitmap_Buffer::init(HWND hw)
2447
SelectObject(hdc_memory, bitmap);
2548
ReleaseDC(hw, hdc);
2649

27-
if (brush == nullptr)
28-
g_render_target->CreateSolidColorBrush(D2D1::ColorF(0, 0, 0), &brush);
29-
}
30-
31-
3250

33-
//---------------------------------------------------------------------
34-
// 終了
35-
//---------------------------------------------------------------------
36-
void cve::Bitmap_Buffer::exit() const
37-
{
38-
DeleteDC(hdc_memory);
39-
DeleteObject(bitmap);
40-
41-
brush->Release();
51+
if (g_render_target != nullptr && brush == nullptr)
52+
g_render_target->CreateSolidColorBrush(D2D1::ColorF(0, 0, 0), &brush);
4253
}
4354

4455

@@ -48,7 +59,7 @@ void cve::Bitmap_Buffer::exit() const
4859
//---------------------------------------------------------------------
4960
bool cve::Bitmap_Buffer::d2d_setup(COLORREF cr)
5061
{
51-
if (g_render_target != nullptr && g_d2d1_factory != nullptr) {
62+
if (g_render_target != nullptr && g_factory != nullptr) {
5263
g_render_target->BindDC(hdc_memory, &rect);
5364
g_render_target->BeginDraw();
5465
g_render_target->SetTransform(D2D1::Matrix3x2F::Identity());
@@ -151,8 +162,8 @@ void cve::Bitmap_Buffer::draw_grid()
151162
// ラウンドエッジを描画
152163
//---------------------------------------------------------------------
153164
void cve::Bitmap_Buffer::draw_rounded_edge(int flag, float radius) {
154-
ID2D1GeometrySink* sink;
155-
ID2D1PathGeometry* edge;
165+
ID2D1GeometrySink* sink = nullptr;
166+
ID2D1PathGeometry* edge = nullptr;
156167
D2D1_POINT_2F pt_1, pt_2, pt_3;
157168

158169
D2D1_POINT_2F pts_1[] = {
@@ -176,7 +187,7 @@ void cve::Bitmap_Buffer::draw_rounded_edge(int flag, float radius) {
176187
D2D1::Point2F((float)rect.right - radius, (float)rect.bottom)
177188
};
178189

179-
g_d2d1_factory->CreatePathGeometry(&edge);
190+
g_factory->CreatePathGeometry(&edge);
180191
edge->Open(&sink);
181192

182193
for (int i = 0; i < 4; i++) {
@@ -202,8 +213,12 @@ void cve::Bitmap_Buffer::draw_rounded_edge(int flag, float radius) {
202213

203214
sink->Close();
204215
brush->SetColor(D2D1::ColorF(TO_BGR(g_theme[g_config.theme].bg)));
205-
if (edge)
216+
217+
if (edge != nullptr)
206218
g_render_target->FillGeometry(edge, brush, NULL);
219+
220+
release(&edge);
221+
release(&sink);
207222
}
208223

209224

@@ -215,7 +230,7 @@ void cve::Bitmap_Buffer::draw_panel_main(const RECT& rect_sepr)
215230
{
216231
ID2D1StrokeStyle* style = nullptr;
217232

218-
g_d2d1_factory->CreateStrokeStyle(
233+
g_factory->CreateStrokeStyle(
219234
D2D1::StrokeStyleProperties(
220235
D2D1_CAP_STYLE_ROUND,
221236
D2D1_CAP_STYLE_ROUND,
@@ -260,10 +275,9 @@ void cve::Bitmap_Buffer::draw_panel_main(const RECT& rect_sepr)
260275
brush, CVE_SEPARATOR_LINE_WIDTH, style
261276
);
262277

263-
// brush->Release();
264-
265278
g_render_target->EndDraw();
266279
}
280+
release(&style);
267281

268282
//ビットマップをバッファから画面に転送
269283
transfer();
@@ -323,7 +337,7 @@ void cve::Bitmap_Buffer::draw_panel_editor()
323337
d2d_setup(TO_BGR(g_theme[g_config.theme].bg_graph));
324338

325339
//描画
326-
if (g_render_target != nullptr && g_d2d1_factory != nullptr) {
340+
if (g_render_target != nullptr && g_factory != nullptr) {
327341
g_render_target->BeginDraw();
328342

329343
//グリッド

curve_editor/cve_button.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ BOOL cve::Button::init(
2525
)
2626
{
2727
id = ct_id;
28-
description = (LPTSTR)desc;
29-
edge_flag = flag;
28+
text_tooltip = (LPTSTR)desc;
29+
flag_edge = flag;
3030
hwnd_parent = hwnd_p;
3131
content_type = cont_type;
3232
hovered = false;
@@ -125,7 +125,7 @@ void cve::Button::draw_edge()
125125
bitmap_buffer.brush->SetOpacity(1);
126126
}
127127

128-
bitmap_buffer.draw_rounded_edge(edge_flag, CVE_ROUND_RADIUS);
128+
bitmap_buffer.draw_rounded_edge(flag_edge, CVE_ROUND_RADIUS);
129129

130130
g_render_target->EndDraw();
131131
}
@@ -159,10 +159,10 @@ void cve::Button::set_font(int font_height, LPTSTR font_name)
159159
//---------------------------------------------------------------------
160160
void cve::Button::set_status(int flags)
161161
{
162-
if (flags & CVE_BUTTON_ENABLED)
163-
disabled = false;
164-
else if (flags & CVE_BUTTON_DISABLED)
162+
if (flags & FLAG_DISABLED)
165163
disabled = true;
164+
else
165+
disabled = false;
166166

167167
::SendMessage(hwnd, WM_COMMAND, aului::Window::COMMAND_REDRAW, 0);
168168
}
@@ -201,7 +201,7 @@ LRESULT cve::Button::wndproc(HWND hw, UINT msg, WPARAM wparam, LPARAM lparam)
201201
tool_info.uFlags = TTF_SUBCLASS;
202202
tool_info.hwnd = hw;
203203
tool_info.uId = id;
204-
tool_info.lpszText = (LPTSTR)description;
204+
tool_info.lpszText = (LPTSTR)text_tooltip;
205205
::SendMessage(hwnd_tooltip, TTM_ADDTOOL, 0, (LPARAM)&tool_info);
206206
}
207207

@@ -212,10 +212,6 @@ LRESULT cve::Button::wndproc(HWND hw, UINT msg, WPARAM wparam, LPARAM lparam)
212212
set_font(CVE_CT_FONT_H, CVE_FONT_SEMIBOLD);
213213
return 0;
214214

215-
case WM_CLOSE:
216-
bitmap_buffer.exit();
217-
return 0;
218-
219215
case WM_SIZE:
220216
bitmap_buffer.set_size(rect_wnd);
221217

curve_editor/cve_class.hpp

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ namespace cve {
3939

4040
public:
4141
HDC hdc_memory;
42-
ID2D1SolidColorBrush* brush = nullptr;
42+
ID2D1SolidColorBrush* brush;
4343
RECT rect;
4444

45+
Bitmap_Buffer();
46+
~Bitmap_Buffer();
47+
4548
void init(HWND hw);
46-
void exit() const;
4749
void transfer() const;
4850
bool d2d_setup(COLORREF cr);
4951
void set_size(const RECT& rect_wnd);
@@ -53,6 +55,32 @@ namespace cve {
5355
void draw_panel_editor();
5456

5557
void draw_rounded_edge(int flag, float radius);
58+
59+
template <class Interface>
60+
void release(Interface** object)
61+
{
62+
if (*object != nullptr) {
63+
(*object)->Release();
64+
(*object) = nullptr;
65+
}
66+
}
67+
};
68+
69+
70+
71+
//---------------------------------------------------------------------
72+
// Direct2D描画オブジェクト(継承)
73+
//---------------------------------------------------------------------
74+
class My_D2D_Paint_Object : public aului::Direct2d_Paint_Object {
75+
private:
76+
void draw_grid();
77+
78+
public:
79+
void draw_panel();
80+
void draw_panel_main(const RECT& rect_sepr);
81+
void draw_panel_editor();
82+
83+
void draw_rounded_edge(int flag, float radius);
5684
};
5785

5886

@@ -143,6 +171,8 @@ namespace cve {
143171
int create_number();
144172
double create_result(int number, double ratio, double st, double ed);
145173
std::string create_parameters();
174+
bool read_parameters(LPCTSTR param, Static_Array<Curve_Points, CVE_POINT_MAX>& points);
175+
bool read_parameters(LPCTSTR param) { return read_parameters(param, ctpts); }
146176
};
147177

148178

@@ -239,13 +269,16 @@ namespace cve {
239269
//---------------------------------------------------------------------
240270
class Button : public aului::Window {
241271
public:
272+
static constexpr int FLAG_DISABLED = 1 << 0;
273+
static constexpr int FLAG_USE_ICON = 1 << 1;
242274
enum Content_Type {
243275
Null,
244276
Icon,
245277
String
246278
};
247279

248280
int id;
281+
int status;
249282

250283
virtual BOOL init(
251284
HWND hwnd_p,
@@ -275,8 +308,8 @@ namespace cve {
275308
HICON icon_dark;
276309
HICON icon_light;
277310
HFONT font;
278-
LPTSTR description;
279-
int edge_flag;
311+
LPTSTR text_tooltip;
312+
int flag_edge;
280313

281314
void draw_content(COLORREF bg, RECT* rect_content, LPCTSTR content, bool change_color);
282315
void draw_edge();

0 commit comments

Comments
 (0)