Skip to content

Commit aae568e

Browse files
fix: remove hacky reset_fons_cache (桌面上 Shift + 鼠标右键 崩溃
Fixes #289)
1 parent 4a78677 commit aae568e

File tree

3 files changed

+2
-52
lines changed

3 files changed

+2
-52
lines changed

src/shell/contextmenu/hooks.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ mb_shell::track_popup_menu(mb_shell::menu menu, int x, int y,
3333
menu_render.rt->last_time = menu_render.rt->clock.now();
3434
perf.end("menu_render::create");
3535

36-
// If holds Shift key when opening the menu, refresh the font cache
37-
if (GetKeyState(VK_SHIFT) & 0x8000) {
38-
std::println("Refreshing font cache...");
39-
menu_render.reset_fons_cache();
40-
}
41-
4236
static HWND window = nullptr;
4337
window = (HWND)menu_render.rt->hwnd();
4438
// set keyboard hook to handle keyboard input

src/shell/contextmenu/menu_render.cc

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ menu_render menu_render::create(int x, int y, menu menu, bool run_js) {
9999
js::menu_info_basic_js menu_info{
100100
.menu = std::make_shared<js::menu_controller>(menu_wid->menu_wid),
101101
.context = current_js_context,
102-
.screenside_button = std::make_shared<js::screenside_button_controller>(menu_wid),
102+
.screenside_button =
103+
std::make_shared<js::screenside_button_controller>(menu_wid),
103104
};
104105

105106
if (run_js) {
@@ -142,48 +143,4 @@ menu_render &menu_render::operator=(menu_render &&t) {
142143
selected_menu = std::move(t.selected_menu);
143144
return *this;
144145
}
145-
// struct NVGcontext {
146-
// NVGparams params;
147-
// float* commands;
148-
// int ccommands;
149-
// int ncommands;
150-
// float commandx, commandy;
151-
// NVGstate states[NVG_MAX_STATES];
152-
// int nstates;
153-
// NVGpathCache* cache;
154-
// float tessTol;
155-
// float distTol;
156-
// float fringeWidth;
157-
// float devicePxRatio;
158-
// struct FONScontext* fs;
159-
// int fontImages[NVG_MAX_FONTIMAGES];
160-
// int fontImageIdx;
161-
// int drawCallCount;
162-
// int fillTriCount;
163-
// int strokeTriCount;
164-
// int textTriCount;
165-
// };
166-
// HACK: By finding the third readable pointer from NVGcontext, we can get the FONScontext
167-
struct FONScontext;
168-
extern "C" int fonsResetAtlas(FONScontext* stash, int width, int height);
169-
void menu_render::reset_fons_cache() {
170-
if (!rt)
171-
return;
172-
auto nvg = rt->nvg;
173-
char* ptr = reinterpret_cast<char *>(nvg);
174-
size_t offset = sizeof(NVGparams) + sizeof(float *);
175-
int ptr_count = 0;
176-
for (size_t i = 0; i < 1024; i += 4) {
177-
void **p = reinterpret_cast<void **>(ptr + offset + i);
178-
if (is_memory_readable(*p)) {
179-
ptr_count++;
180-
if (ptr_count == 2) {
181-
auto fons = reinterpret_cast<struct FONScontext *>(*p);
182-
fonsResetAtlas(fons, 512, 512);
183-
return;
184-
}
185-
}
186-
}
187-
188-
}
189146
}; // namespace mb_shell

src/shell/contextmenu/menu_render.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ struct menu_render {
2020
const menu_render &operator=(const menu_render &) = delete;
2121
menu_render(menu_render &&t);
2222
menu_render &operator=(menu_render &&t);
23-
void reset_fons_cache();
2423
static menu_render create(int x, int y, menu menu, bool run_js = true);
2524
};
2625
} // namespace mb_shell

0 commit comments

Comments
 (0)