ITADN

USB cameras connected to a windows PC take longer to start, which results in an exception when trying to access data that hasn't been initialized, causing the program to crash.

#29Closedcrose72 创建于 2024-11-24
bug
C
crose72commented
@sbow Had a USB camera connected to a laptop. After compiling the program it would crash on the first loop due to an exception being thrown about arrays being accessed out of bounds in the track_target.cpp file. A breakpoint showed that the issue occured at the line where the `target_height` was being determined. The solution for this was to add a small delay at the beginning of the program as shown below: ``` Video::in_loop(); if (first_loop_after_start) { std::this_thread::sleep_for(std::chrono::seconds(3)); } Detection::loop(); ``` This is a good temporary solution if this issue is being faced by anyone, but a long term solution is needed to avoid having a delay in the code. Maybe better checks to ensure that array indices are not out of range, or that data is only access after properly initialized and if available.
关闭于 2025-11-09 1 条评论