-
Notifications
You must be signed in to change notification settings - Fork 596
Description
I think there is a bug when striding data that happens to have the same size as a float
To reproduce:
- 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)
- Change this line to
int16_t x,y;
Line 48 in 6ee1559
float x, y; - 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)
Line 1680 in 6ee1559
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
Line 290 in 6ee1559
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()!