Address EXC_BAD_ACCESS - Tracktion Engine

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?

The playback time can be negative if there is a count-in. Is that what you’re seeing?

But more generally an Address EXC_BAD_ACCESS indicates some kind of memory error like a dangling object.

I would run with ASan (address sanitizer) on as it will probably tell you where the object was deleted.

Oh yeah the count-in! I did notice it becomes negative when recording and the current transport position is at 0. Thank you Dave, I will try debugging using address sanitizer as you suggested. My other issue on the MidiRecordingDemo is that my clips doesn’t show midi notes on the clip after recording, same thing with recording audio the clips are just blank no waveform but when I playback what I recorded I can hear the sound. Even if the show waveform button is toggled, i still trying to find my way around these tracktion engine examples I got so many errors compiling them.

They should just compile cleanly, they’re tested on our CI several times a day.

How are you building them? With cmake?

Sorry for late response Dave im using xcode, do i need cmake to build these?

You can use Xcode but you need to use cmake to generate the IDE files.
See the instructions here: