aboutsummaryrefslogtreecommitdiff
path: root/core/client.cpp
diff options
context:
space:
mode:
authorPaul Oliver <contact@pauloliver.dev>2026-06-11 16:47:28 +0200
committerPaul Oliver <contact@pauloliver.dev>2026-06-11 16:47:28 +0200
commite35f39df2cc1570d33a45b98dff48184db023d08 (patch)
tree1a495c642859858caf49112f740e1bb95fe49b42 /core/client.cpp
parent5d46c96cd93460b4d00eadf3b0237824ca297284 (diff)
Fixes div. by 0 bug
Diffstat (limited to 'core/client.cpp')
-rw-r--r--core/client.cpp52
1 files changed, 32 insertions, 20 deletions
diff --git a/core/client.cpp b/core/client.cpp
index f24b2dd..ca2f878 100644
--- a/core/client.cpp
+++ b/core/client.cpp
@@ -699,14 +699,22 @@ void PlotHeatmap::render_internal(const ImVec2 &frame_size) {
m_tex_render.reserve((trace->size() - m_tex_rendered_last) * 3);
- for (size_t i = m_tex_rendered_last; i < trace->size(); i++) {
- ImS64 value = trace->operator[](i);
- float normal = std::min((float)value / m_tex_scale_high, 1.f);
- assert(normal >= 0.f && normal <= 1.f);
- ImVec4 color = ImPlot::SampleColormap(normal, g_hm_colormap_id);
- m_tex_render.push_back((uint8_t)(color.x * 255.f)); // red
- m_tex_render.push_back((uint8_t)(color.y * 255.f)); // green
- m_tex_render.push_back((uint8_t)(color.z * 255.f)); // blue
+ if (m_tex_scale_high != 0.f) {
+ for (size_t i = m_tex_rendered_last; i < trace->size(); i++) {
+ ImS64 value = trace->operator[](i);
+ float normal = std::min((float)value / m_tex_scale_high, 1.f);
+ assert(normal >= 0.f && normal <= 1.f);
+ ImVec4 color = ImPlot::SampleColormap(normal, g_hm_colormap_id);
+ m_tex_render.push_back((uint8_t)(color.x * 255.f)); // red
+ m_tex_render.push_back((uint8_t)(color.y * 255.f)); // green
+ m_tex_render.push_back((uint8_t)(color.z * 255.f)); // blue
+ }
+ } else {
+ for (size_t i = m_tex_rendered_last; i < trace->size(); i++) {
+ m_tex_render.push_back(0);
+ m_tex_render.push_back(0);
+ m_tex_render.push_back(0);
+ }
}
GLuint new_tex_id;
@@ -769,6 +777,16 @@ int64_t data_max_hm_pixel_pow(void) {
return (int64_t)floor(log2((double)(MVEC_SIZE - g_hm_left) / (double)g_hm_pixel_count));
}
+void data_flag_heatmaps_for_reset(void) {
+ for (auto &heatmap : g_core_plots_heatmaps) {
+ heatmap.flag_for_reset();
+ }
+
+ for (auto &heatmap : g_arch_plots_heatmaps) {
+ heatmap.flag_for_reset();
+ }
+}
+
void data_on_field_change(void) {
g_entries = std::clamp(g_entries, 1l, DEFVAL_ENTRIES);
g_nth = std::clamp(g_nth, DEFVAL_NTH, INT64_MAX);
@@ -1255,18 +1273,15 @@ void app_key_callback_plot_maximized(int key, int mods) {
break;
case GLFW_KEY_COMMA:
g_hm_scale_pow = std::max(g_hm_scale_pow - HM_SCALE_POW_INTERVAL, HM_SCALE_POW_MIN);
- for (auto &heatmap : g_core_plots_heatmaps) heatmap.flag_for_reset();
- for (auto &heatmap : g_arch_plots_heatmaps) heatmap.flag_for_reset();
+ data_flag_heatmaps_for_reset();
break;
case GLFW_KEY_PERIOD:
g_hm_scale_pow = std::min(g_hm_scale_pow + HM_SCALE_POW_INTERVAL, HM_SCALE_POW_MAX);
- for (auto &heatmap : g_core_plots_heatmaps) heatmap.flag_for_reset();
- for (auto &heatmap : g_arch_plots_heatmaps) heatmap.flag_for_reset();
+ data_flag_heatmaps_for_reset();
break;
case GLFW_KEY_0:
g_hm_scale_pow = HM_SCALE_POW_MIN;
- for (auto &heatmap : g_core_plots_heatmaps) heatmap.flag_for_reset();
- for (auto &heatmap : g_arch_plots_heatmaps) heatmap.flag_for_reset();
+ data_flag_heatmaps_for_reset();
break;
}
@@ -1330,18 +1345,15 @@ void app_key_callback(GLFWwindow* window, int key, int scancode, int action, int
break;
case GLFW_KEY_COMMA:
g_hm_scale_pow = std::max(g_hm_scale_pow - HM_SCALE_POW_INTERVAL, HM_SCALE_POW_MIN);
- for (auto &heatmap : g_core_plots_heatmaps) heatmap.flag_for_reset();
- for (auto &heatmap : g_arch_plots_heatmaps) heatmap.flag_for_reset();
+ data_flag_heatmaps_for_reset();
break;
case GLFW_KEY_PERIOD:
g_hm_scale_pow = std::min(g_hm_scale_pow + HM_SCALE_POW_INTERVAL, HM_SCALE_POW_MAX);
- for (auto &heatmap : g_core_plots_heatmaps) heatmap.flag_for_reset();
- for (auto &heatmap : g_arch_plots_heatmaps) heatmap.flag_for_reset();
+ data_flag_heatmaps_for_reset();
break;
case GLFW_KEY_0:
g_hm_scale_pow = HM_SCALE_POW_MIN;
- for (auto &heatmap : g_core_plots_heatmaps) heatmap.flag_for_reset();
- for (auto &heatmap : g_arch_plots_heatmaps) heatmap.flag_for_reset();
+ data_flag_heatmaps_for_reset();
break;
}