Std::out_of_range exception in executeLaunch()

I’m developing an app that reads serial data that’s sent every frame by an Arduino, stores it, displays it and forwards some events via OSC.

Every few launches I get a crash that I haven’t been able to trace. It’s a vector std::out_of_range exception in this line of executeLaunch (this one in the implementation file).

I have no idea what vector is causing the crash and I haven’t been able to replicate it in a separate app yet. Any tips on debugging these kinds of things?

Try breaking on exceptions, with whatever IDE you’re using.

Thanks Rich. I’m doing that already, but I can’t really step in or out of executeLaunch(). The debugger drops me there even though I have my setup, update and draw surrounded by try/catch.

That catch in excecuteLaunch() will only be hit if the exception goes uncaught. Perhaps the exception is happening on a background thread?

In any event, make sure you are breaking on the throw, if that is working then it should break you right where the std::vector::at() was called with an out of bounds argument.

To break on exceptions, you will want to add a “symbolic breakpoint.” Depending on your platform, how you do this will vary (and the name might, too).

Apple has a tiny guide for setting these up in XCode.

Awesome, that worked. Never used that kind of breakpoints before, thanks. :+1:

EDIT: actually, my main error was writing ci::Exception in my catch statements, which wasn’t working in this case because this was an std::exception. Just in case it helps someone else in the future.

ci::Exception inherits from std::exception, so a properly-written catch block can catch either. Just make sure you are catching by const reference so polymorphism is possible.

try {
catch (const ci::Exception &exc) {
    CI_LOG_E("Caught some exception: " << exc.what());

Never mind the catch block I wrote previously. The type polymorphism only accepts downstream variants, so catching std::exception will work for ci::Exception, but not the other way around.