From 9533ddefcf8af901ebc0ff0b2ac503b5af2523b8 Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Fri, 13 Apr 2018 14:45:16 -0600 Subject: Remove SurviveObject if they fail to configure; prevents issues calibrating with HMD when controllers are off --- src/survive.c | 25 +++++++++++++++++++++++++ src/survive_vive.c | 1 + 2 files changed, 26 insertions(+) (limited to 'src') diff --git a/src/survive.c b/src/survive.c index 362adbc..bb1179e 100644 --- a/src/survive.c +++ b/src/survive.c @@ -404,6 +404,31 @@ int survive_add_object(SurviveContext *ctx, SurviveObject *obj) { return 0; } +void survive_remove_object(SurviveContext *ctx, SurviveObject *obj) { + int obj_idx = 0; + for (obj_idx = 0; obj_idx < ctx->objs_ct; obj_idx++) { + if (ctx->objs[obj_idx] == obj) + break; + } + + if (obj_idx == ctx->objs_ct) { + SV_INFO("Warning: Tried to remove un-added object %p(%s)", obj, obj->codename); + return; + } + + // Swap the last item into this items slot; this assumes order doesn't matter in this list + if (obj_idx != ctx->objs_ct - 1) { + ctx->objs[obj_idx] = ctx->objs[ctx->objs_ct - 1]; + } + + ctx->objs_ct--; + + // Blank out the spot; but this is only really necessary for diagnostic reasons -- presumably no one will ever read + // past the end of the list + ctx->objs[ctx->objs_ct] = 0; + + free(obj); +} void survive_add_driver(SurviveContext *ctx, void *payload, DeviceDriverCb poll, DeviceDriverCb close, DeviceDriverMagicCb magic) { int oldct = ctx->driver_ct; diff --git a/src/survive_vive.c b/src/survive_vive.c index 0fae736..d9cbc3e 100755 --- a/src/survive_vive.c +++ b/src/survive_vive.c @@ -1660,6 +1660,7 @@ static int LoadConfig( SurviveViveData * sv, SurviveObject * so, int devno, int if( len < 0 ) { + survive_remove_object(ctx, so); return len; } -- cgit v1.2.3