4bb4 / implot-rs

Rust bindings to https://github.com/epezent/implot
Apache License 2.0
53 stars 22 forks source link

drawing is broken when using special characters for axis labels #4

Open benmkw opened 3 years ago

benmkw commented 3 years ago

I used "€" so I assume only ascii is allowed or maybe it would have to be wrapped into im_str! or sth. on an api level. I've not looked into the internals but maybe this helps someone debugging :)

4bb4 commented 3 years ago

I'll try to reproduce this on my end. Things do get wrapped in im_str!, for the axis labels this happens here: https://github.com/4bb4/implot-rs/blob/master/src/plot.rs#L245 - but maybe something else is going wrong. What are you seeing when you use €? Nothing? Or weird other letters?

benmkw commented 3 years ago

If I e.g. change the y_label in my wgpu pr in show_basic_plot to "€" it crashes.

    Plot::new("Simple line plot")
        // The size call could also be omitted, though the defaults don't consider window
        // width, which is why we're not doing so here.
        .size(content_width, 300.0)
        .y_label(&"€")
        .build(plot_ui, || {
            // If this is called outside a plot build callback, the program will panic.
            let x_positions = vec![0.1, 0.9];
            let y_positions = vec![0.1, 0.9];
            PlotLine::new("legend label").plot(&x_positions, &y_positions);
        });
Assertion failed: ((int)draw_list->_VtxCurrentIdx == draw_list->VtxBuffer.Size), function AddDrawListToDrawData, file third-party/imgui/imgui.cpp, line 4047.
fish: 'cargo run --release' terminated by signal SIGABRT (Abort)

interestingly it does not crash if used as x_label but just shows a "?"

I certainly had it not crash at the y axis and just produce artefacts for rendering though (hundreds of long white lines across the plotting area) as well.

4bb4 commented 3 years ago

interestingly it does not crash if used as x_label but just shows a "?"

This sounds like a memory issue. I'll have to walk through it with a debugger to see what's going wrong - I thought I could just do im_str!("{}" my_string).as_ptr() and presto I have a char ptr, but apparently things are not that simple...

EDIT: Ooh, I think I know what the problem is - the result of im_str!() is a temporary here and may be deleted before it is used. I'll try out a fix (probably not before tomorrow though) and let you know how it goes.

EDIT 2: Now with the right account xD I wondered why I got a notification for my own comment

4bb4 commented 3 years ago

I did some checks, here's what I found so far:

aloucks commented 3 years ago

Did you verify that "€" is represented in the glyph ranges that you used and is it in your texture atlas?

4bb4 commented 3 years ago

@aloucks No, and I suspect that this may be the issue. I did check that the FindGlyph call in https://github.com/epezent/implot/blob/master/implot.cpp#L277 returned a non-null pointer when I was stepping through it with a debugger, if I remember correctly.

If this is the issue, I'd be interested in what to do / check in the code in order to make sure that a user specifying valid UTF does not lead to the program drawing glitches or even crashing though - if that's possible with reasonable effort.

4bb4 commented 3 years ago

@benmkw Have you tried out another font in the meantime?

benmkw commented 3 years ago

No :/ I played with using your project as a template basically to port imnodes though until my laptop broke yesterday so I was/ am in the process of looking at more details/ trying some things out for this whole API thing. I‘ll have to see how much further I push this on windows or if I do a bit less for a bit.

4bb4 commented 3 years ago

Alright, I need to try using other fonts for work at some point in the future anyway, I'll make sure to plop an in there to see if it works and ping you with an update