Skip to content

Incorrect stride behaviour when sizeof(T) == sizeof(float) #303

@joshtyler

Description

@joshtyler

I think there is a bug when striding data that happens to have the same size as a float

To reproduce:

  1. Compile and run the demo, look at Custom->Custom Data Getters and Setters. The Vector2f line should be a line from (0,0), to (1,1)
  2. Change this line to int16_t x,y;
    float x, y;
  3. Compile and run the demo again. Look at the same plot. The Vector2f line now (incorrectly) goes from (0,0) to (1,0).

We would expect this change to have no effect, since where the structure is used, stride is passed in as sizeof(MyImPlot::Vector2f)

ImPlot::PlotLine("Vector2f", &vec2_data[0].x, &vec2_data[0].y, 2, 0, sizeof(MyImPlot::Vector2f) /* or sizeof(float) * 2 */);

Root cause:

A few months ago IndexData() was introduced to speed up rendering. The bug seems to be on this line

const int s = ((offset == 0) << 0) | ((stride == sizeof(float)) << 1);

On this line I think sizeof(float) should be sizeof(T). Where sizeof(T) == sizeof(float), but the data type contains multiple values (e.g. in this case T is {int16_t, int16_T}), The function will do the wrong thing

N.B. This fix should also speed up rendering for other data types, which are currently taking a pessimistic route through IndexData()!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions