Hi Everyone
The ‘Type get() const noexcept { return cachedValue; }’ line causes a breakpoint error in my app, which could indicate that cachedValue is uninitialized or invalid.
I get the error when I try to calculate newX in the timerCallback which is calculated using timeToX function
int newX = editViewState.timeToX (edit.getTransport().getPosition(), getWidth());
if (newX != xPosition)
{
repaint (jmin (newX, xPosition) - 1, 0, jmax (newX, xPosition) - jmin (newX, xPosition) + 3, getHeight());
xPosition = newX;
}
I tried to debug the values involved to calculate this in timeToX
int timeToX(tracktion::TimePosition time, int width) const
{
// Debugging the values involved in the calculation
DBG("time: " << time.inSeconds() << "s, viewX1: " << viewX1.get().inSeconds() << "s, viewX2: " << viewX2.get().inSeconds() << "s, width: " << width);
int result = roundToInt(((time - viewX1) * width) / deltaX);
DBG("Calculated timeToX result: " << result);
return result;
}
This is what the console prints
time: 3.21596s, viewX1: 0s, viewX2: 60s, width: 797
time: 18.2068s, viewX1: 0s, viewX2: 60s, width: 797
time: 18.2068s, viewX1: 0s, viewX2: 60s, width: 797
time: 30.1199s, viewX1: 0s, viewX2: 60s, width: 797
time: -2.49993s, viewX1: 0s, viewX2: 60s, width: 797
time: 20.3242s, viewX1: 0s, viewX2: 60s, width: 797
time: 20.37s, viewX1: 0s, viewX2: 60s, width: 797
time: 30.8087s, viewX1: 0s, viewX2: 60s, width: 797
The debug output shows that viewX1 and viewX2 are correctly set to 0s and 60s, respectively, and the time values being passed to timeToX are within a reasonable range. However, there’s one notable issue: the time value can sometimes be negative (e.g., -2.49993s). I am thinking this negative value could potentially cause issues when performing the calculation.
What is causing time to be negative and how can I avoid this?