Skip to content

Commit

Permalink
Update imgui_memory_editor.h (fix memory editor preview crash) (#117)
Browse files Browse the repository at this point in the history
* Update imgui_memory_editor.h

* Fix memed usage

* Update window_display_buffer.cpp
  • Loading branch information
tiberiusbrown authored Sep 14, 2024
1 parent 6ff57bd commit c4d92c3
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 177 deletions.
336 changes: 203 additions & 133 deletions deps/imgui/imgui_memory_editor.h

Large diffs are not rendered by default.

35 changes: 13 additions & 22 deletions src/window_data_space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,42 +211,37 @@ uint32_t darker_color_for_index(size_t index)
return c;
}

static bool highlight_func(ImU8 const* data, size_t off, ImU32& color)
static ImU32 bgcolor_func(ImU8 const* data, size_t off, void* user)
{
bool r = false;
(void)user;
ImU32 r = 0;
if(off < 0x20)
{
color = IM_COL32(20, 20, 50, 255);
r = true;
r = IM_COL32(20, 20, 50, 255);
}
else if(off < 0x100)
{
color = absim::REG_INFO[off].name ?
r = absim::REG_INFO[off].name ?
IM_COL32(50, 50, 20, 255) :
IM_COL32(0, 0, 0, 255);
r = true;
}
else if(off >= arduboy.cpu.min_stack)
{
color = IM_COL32(70, 0, 90, 255);
r = true;
r = IM_COL32(70, 0, 90, 255);
}
else if(arduboy.cpu.stack_check > 0x100 && off >= arduboy.cpu.stack_check)
{
color = IM_COL32(45, 45, 45, 255);
r = true;
r = IM_COL32(45, 45, 45, 255);
}
else if(auto const* sym = arduboy.symbol_for_data_addr((uint16_t)off))
{
color = darker_color_for_index(sym->color_index);
r = true;
r = darker_color_for_index(sym->color_index);
}
if(off < arduboy.cpu.data.size() && (
arduboy.breakpoints_rd.test(off) ||
arduboy.breakpoints_wr.test(off)))
{
color = IM_COL32(150, 50, 50, 255);
r = true;
r = IM_COL32(150, 50, 50, 255);
}
return r;
}
Expand Down Expand Up @@ -305,12 +300,6 @@ void hover_data_space(uint16_t addr)
EndTooltip();
}

static void hover_func(ImU8 const* data, size_t off)
{
(void)data;
hover_data_space((uint16_t)off);
}

void window_data_space(bool& open)
{
using namespace ImGui;
Expand All @@ -322,8 +311,7 @@ void window_data_space(bool& open)
memed_data_space.OptShowDataPreview = true;
memed_data_space.PreviewDataType = ImGuiDataType_U8;
memed_data_space.OptFooterExtraHeight = GetFrameHeightWithSpacing();
memed_data_space.HighlightFn = highlight_func;
memed_data_space.HoverFn = hover_func;
memed_data_space.BgColorFn = bgcolor_func;
first = false;
}
}
Expand Down Expand Up @@ -367,6 +355,9 @@ void window_data_space(bool& open)

auto addr = memed_data_space.DataPreviewAddr;
draw_memory_breakpoints(addr);

if(memed_data_space.MouseHovered)
hover_data_space((uint16_t)memed_data_space.MouseHoveredAddr);
}
End();
}
Expand Down
1 change: 1 addition & 0 deletions src/window_display_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static void update_display_buffer_texture()
}

platform_update_texture(display_buffer_texture, pixels, sizeof(pixels));
platform_texture_scale_nearest(display_buffer_texture);
}

void window_display_buffer(bool& open)
Expand Down
14 changes: 6 additions & 8 deletions src/window_display_internals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ static char const* const MODES[] =
"INVALID"
};

static bool highlight_func(ImU8 const* data, size_t off, ImU32& color)
{
bool r = false;

static ImU32 bgcolor_func(ImU8 const* data, size_t off, void* user)
{
(void)user;
if(off == arduboy.display.data_page * 128 + arduboy.display.data_col)
{
color = IM_COL32(40, 160, 40, 255);
r = true;
return IM_COL32(40, 160, 40, 255);
}
return r;
return 0;
}

void window_display_internals(bool& open)
Expand Down Expand Up @@ -69,7 +67,7 @@ void window_display_internals(bool& open)
Text("Segment Remap %s", d.segment_remap ? "ON" : "OFF");
}
Separator();
memed_display_ram.HighlightFn = highlight_func;
memed_display_ram.BgColorFn = bgcolor_func;
memed_display_ram.DrawContents(
arduboy.display.ram.data(),
arduboy.display.ram.size());
Expand Down
17 changes: 9 additions & 8 deletions src/window_fx_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@ static int hex_value(char const* c)
return r;
}

static bool highlight_func(ImU8 const* data, size_t off, ImU32& color)
static ImU32 bgcolor_func(ImU8 const* data, size_t off, void* user)
{
bool r = false;
(void)user;
if(off + arduboy.fx.min_page * 256 == arduboy.fx.current_addr)
{
if(arduboy.fx.reading || arduboy.fx.programming)
{
color = IM_COL32(40, 160, 40, 255);
r = true;
return IM_COL32(40, 160, 40, 255);
}
}
return r;
return 0;
}

void window_fx_data(bool& open)
Expand Down Expand Up @@ -106,13 +105,15 @@ void window_fx_data(bool& open)
if(fx_data_scroll_addr >= 0)
memed_fx.GotoAddr = (size_t)(fx_data_scroll_addr - minpage * 256);
fx_data_scroll_addr = -1;
memed_fx.HighlightFn = highlight_func;
memed_fx.ReadFn = [](ImU8 const* data, size_t off) {
memed_fx.BgColorFn = bgcolor_func;
memed_fx.ReadFn = [](ImU8 const* data, size_t off, void* user) {
(void)data;
(void)user;
return arduboy.fx.read_byte(off + minpage * 256);
};
memed_fx.WriteFn = [](ImU8* data, size_t off, ImU8 d) {
memed_fx.WriteFn = [](ImU8* data, size_t off, ImU8 d, void* user) {
(void)data;
(void)user;
arduboy.fx.write_byte(off + minpage * 256, d);
};
memed_fx.ReadOnly = !arduboy.is_present_state();
Expand Down
12 changes: 6 additions & 6 deletions src/window_progmem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

static MemoryEditor memed;

static bool highlight_func(ImU8 const* data, size_t off, ImU32& color)
static ImU32 bgcolor_func(ImU8 const* data, size_t off, void* user)
{
(void)user;
if(auto const* sym = arduboy.symbol_for_prog_addr((uint16_t)off))
{
if(sym->object)
{
color = darker_color_for_index(sym->color_index);
return true;
return darker_color_for_index(sym->color_index);
}
}
return false;
return 0;
}

static void hover_func(ImU8 const* data, size_t off)
Expand All @@ -44,8 +44,8 @@ void window_progmem(bool& open)
{
memed.OptShowDataPreview = true;
memed.PreviewDataType = ImGuiDataType_U8;
memed.HighlightFn = highlight_func;
memed.HoverFn = hover_func;
memed.BgColorFn = bgcolor_func;
//memed.HoverFn = hover_func;
first = false;
}
}
Expand Down

0 comments on commit c4d92c3

Please sign in to comment.