survive_disambiguator::handle_lightcap: program breaks when `assert(_le->length > 0)` fails
Describe the bug
In rare occasions, libsurvive (running api_example.c) stops working in survive_disambiguator::handle_lightcap if _le->length == 0. I get this more often, when i move a controller while libsurvive is in the early initialization phase.
Data I'll provide a console log with the code shown below with the failing event highlighted by sunflowers :) . If desired, i can put together a recording soon.
TT/libsurvive/build$ /home/Throni/Schreibtisch/Arbeit/TT/libsurvive/build/api_example
( 0.001) SimpleApi: Loaded drivers: GlobalSceneSolver, HTCVive
Found 'LH0' (LHB-6BC52F44) (battery: 100)
( 0.028) SimpleApi: Adding tracked object WM0 from HTC
(1725379826.619368) Found 'LH0'
(1725379826.645531) Found 'WM0'
LH0 LHB-6BC52F44 (1725379826.846): POS: -0.002052 1.030374 0.888735 QUAT: 0.041567 0.073418 -0.576874 -0.812465
( 0.983) SimpleApi: Device WM0 has watchman FW version 1622109928 and FPGA version 538/7/2; named ' WMBUILD-W64$'. Hardware id 0x81020009 Board rev: 3 (len 56)
(1725379827.601261) WM0 received configuration of length 9311 type 3-3
( 1.019) SimpleApi: Read light data error -5 [Time:713D] [Payload: 51 40 02 3a 28 a0 20 cd 01 c2 34 07 ad 19 99 09 c9 04 c9 0d e0 03 86 c0 40 ]
( 1.025) SimpleApi: Read light data error -5 [Time:7142] [Payload: 80 e5 7a 09 a8 e9 cf f0 f8 09 aa e8 d2 aa ]
( 1.037) SimpleApi: Read light data error -5 [Time:714B] [Payload: d1 ac 67 fa a1 e9 e8 f1 bb 08 aa e8 36 ab 40 03 71 19 80 18 a8 a1 04 6e 23 4b ]
( 1.057) SimpleApi: Read light data error -5 [Time:7157] [Payload: 51 40 01 08 20 a0 78 82 13 9a 2d ed 16 f0 13 08 87 01 92 02 a0 01 31 01 5c ]
( 1.060) SimpleApi: Read light data error -5 [Time:715A] [Payload: 51 40 09 09 79 a0 30 e9 10 bb 17 8f 15 96 11 bf 07 b0 0d f3 05 4e 9c 5d ]
( 1.061) SimpleApi: Read light data error -5 [Time:715D] [Payload: 90 3a a1 c5 9e e3 2f 08 66 03 33 f8 76 b8 72 88 9e 03 c1 0d e8 05 9d b5 5d ]
( 1.079) SimpleApi: Read light data error -5 [Time:7168] [Payload: 51 40 09 a0 09 79 18 91 12 ac 08 a5 06 fd 0e 80 04 d7 01 da 12 c7 28 6c ]
( 1.097) SimpleApi: Read light data error -5 [Time:7177] [Payload: 90 8f ec a5 f3 ee a9 ff 9f 05 65 1a d4 0d a0 95 0d db 71 77 ]
( 1.102) SimpleApi: Read light data error -5 [Time:717A] [Payload: 90 7c 36 aa a2 f1 67 fd e9 01 73 14 62 16 68 b6 11 14 e7 7a ]
( 1.121) SimpleApi: Read light data error -5 [Time:7189] [Payload: 90 1d 82 d6 e5 f1 a7 f0 fd eb ec ff 08 38 09 79 c2 06 e0 0c 9b 0a df 7c 89 ]
( 1.142) SimpleApi: Read light data error -5 [Time:7197] [Payload: 80 be 82 f1 e9 e5 98 e9 b1 e0 04 09 ef 50 ]
( 1.162) SimpleApi: Read light data error -5 [Time:71A6] [Payload: 90 5f 56 f9 52 ea d4 f0 bc e3 b0 0b 5e 55 79 19 e9 1d fd 02 d0 05 10 65 a7 ]
( 1.174) SimpleApi: Read light data error -5 [Time:71AF] [Payload: 51 40 05 30 99 3a a1 e3 08 b6 0d cd c0 06 ca 03 98 0b 96 19 29 9c b1 ]
( 1.177) SimpleApi: LightcapElement has zero length [SensorId:8] [Timestamp:DC3A] 🌻🌻🌻
( 1.178) SimpleApi: Read light data error -5 [Time:71B2] [Payload: 90 13 16 0d f7 ec bf fd e4 ef 41 06 e7 4a 20 50 b8 01 e1 01 cd 01 4e e0 b3 ]
( 1.180) SimpleApi: Read light data error -5 [Time:71B2] [Payload: 51 40 05 30 39 99 a0 a8 25 98 10 ed 0c b9 03 bf 16 a5 39 a0 1f 54 5a b6 ]
( 1.201) SimpleApi: Read light data error -5 [Time:71C3] [Payload: d1 a2 7f 33 9d f5 9a 1e 1f 02 ce f7 32 1f 40 07 a0 40 dc 0d 9b f4 1c de f8 c4 ]
( 1.213) SimpleApi: Read light data error -5 [Time:71CC] [Payload: 90 69 3c 2c e1 e9 97 27 fe 06 92 fb ec f5 50 ba 01 fb f7 cb ]
( 1.217) SimpleApi: Read light data error -5 [Time:71CF] [Payload: d1 56 dd 2a 43 ea 30 24 ae 06 12 fc 96 e7 40 04 70 ec 20 07 56 cf ]
( 1.232) SimpleApi: Read light data error -5 [Time:71DB] [Payload: 90 0a 6c 21 78 f2 4c 06 a8 03 ad f7 2d be 50 c5 01 8f 99 da ]
( 1.237) SimpleApi: Read light data error -5 [Time:71DB] [Payload: 51 40 05 80 48 40 70 90 17 f6 51 07 cc 01 8f 05 cd 01 95 88 01 32 c3 df ]
( 1.240) SimpleApi: Read light data error -5 [Time:71DD] [Payload: 51 40 05 30 39 99 a0 bd 1c c3 19 82 04 91 01 c5 17 f5 34 d0 1b 06 23 e2 ]
( 1.255) SimpleApi: Read light data error -5 [Time:71E9] [Payload: 51 40 09 18 a1 39 28 be 0a db 15 cf 08 f8 0a ce 0b e0 1f a4 17 79 2b ec ]
( 1.279) SimpleApi: Read light data error -5 [Time:71FB] [Payload: 51 40 09 a0 38 20 38 e2 ac 0e a9 01 b9 56 05 f9 08 94 0f 88 14 50 7c fe ]
( 1.282) SimpleApi: Read light data error -5 [Time:71FE] [Payload: 90 26 9c cb 41 ec 92 f6 db 02 e7 f4 07 ac 11 71 b2 10 80 06 9e 0e 30 d2 fe ]
( 1.297) SimpleApi: Read light data error -5 [Time:7209] [Payload: 80 da 11 bf 26 df ff 06 8f ff 74 fc ad b3 ]
( 1.319) SimpleApi: Read light data error -5 [Time:7218] [Payload: 51 40 08 a0 09 79 18 9e 0f d6 08 d1 13 9f 01 93 10 a6 07 ab 10 bd b3 1b ]
( 1.345) SimpleApi: Read light data error -5 [Time:722C] [Payload: 80 f6 25 c4 e8 e9 7f f5 cf f8 a1 f9 2c 32 ]
( 1.355) SimpleApi: Read light data error -5 [Time:7232] [Payload: 51 40 08 a0 6a 7a 72 ae 03 e4 02 a5 0d cc 02 bf 8c 28 cf 11 f3 7a 35 ]
( 1.357) SimpleApi: Read light data error -5 [Time:7235] [Payload: d1 bd c5 e0 25 e4 9d eb 2b f0 c2 fb 88 45 40 01 08 20 a4 01 ad 02 c8 55 80 37 ]
( 1.361) SimpleApi: Read light data error -5 [Time:7238] [Payload: 90 aa 98 e6 a4 e4 ec e9 45 ee bb fe a7 4a 70 08 84 15 a2 13 de 15 b2 34 39 ]
( 1.378) SimpleApi: Read light data error -5 [Time:7244] [Payload: d1 5e 8d f3 49 e9 36 ea f4 ea 61 08 b9 56 40 02 a0 ce 16 6d eb 43 ]
( 1.379) SimpleApi: Read light data error -5 [Time:7244] [Payload: 51 40 09 a1 39 20 38 8f 01 94 0f c9 01 96 2a 06 c4 02 c7 0c e6 09 80 c9 47 ]
( 1.381) SimpleApi: Read light data error -5 [Time:7247] [Payload: 90 4b 67 f5 6d ea d3 ea 64 eb 15 09 90 57 30 28 84 11 c6 0a ed 17 52 e1 47 ]
( 1.390) SimpleApi: Detected LH gen 2 system.
( 1.393) SimpleApi: LightcapMode (WM0) 1 -> 2 (ff)
( 1.538) SimpleApi: OOTX not set for LH in channel 0; attaching ootx decoder using device WM0
WM0 LHR-6F8D0620 (1725379828.896): POS: -0.310518 0.278922 10.050676 QUAT: -0.455755 -0.752433 -0.315250 -0.356020
WM0 LHR-6F8D0620 (1725379828.904): POS: -0.312439 0.278964 10.047738 QUAT: -0.456215 -0.750995 -0.313182 -0.360267
WM0 LHR-6F8D0620 (1725379828.912): POS: -0.314317 0.278845 10.045086 QUAT: -0.456176 -0.750222 -0.310932 -0.363857
WM0 LHR-6F8D0620 (1725379828.920): POS: -0.314084 0.279566 10.044592 QUAT: -0.459222 -0.748813 -0.314751 -0.359620
Hardware setup HTC Vive Lighthouse generation 2 HTC Vive Controller HTC Vive dongle attached to a USB hub
Desktop (please complete the following information): Fedora 40, Wayland, KDE spin
Additional context
I am still getting into the realm of how the lightcap logics work. Any help is appreciated. From what i understand, not all kinds of lightcap signals are understood. From the context of handle_lightcap i got that the return value (bool) indicates success, so i put together a workaround as it seems that libsurvive can still go on with this errorneous LightcapElement once in a while. Here is my code for src/survive_disambiguator.c, modified from the current master:
bool handle_lightcap(SurviveObject *so, const LightcapElement *_le) {
// Gen2 devices can trigger this on startup; but later packets should
// reliably change to lh_version == 1. If we see 50+ lightcap packets
// without these gen2 packets we can just call it for gen1.
SurviveContext *ctx = so->ctx;
// this assert sometimes breaks the whole program, so instead just return success = false and go on
// assert(_le->length > 0);
uint16_t le_length = _le->length;
if (le_length == 0 ) {
SV_WARN("LightcapElement has zero length [SensorId:%d] [Timestamp:%04hX]", _le->sensor_id, _le->timestamp)
return false;
}
if (so->ctx->lh_version == -1) {
disambiguate_version *dv = so->disambiguator_data;
if (dv == 0) {
so->disambiguator_data = dv = SV_NEW(disambiguate_version);
}
dv->total_count++;
// SurviveContext *ctx = so->ctx; // moved up for SV_WARN