aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Berger <j.david.berger@gmail.com>2018-04-13 14:45:16 -0600
committerJustin Berger <j.david.berger@gmail.com>2018-04-13 14:45:16 -0600
commit9533ddefcf8af901ebc0ff0b2ac503b5af2523b8 (patch)
tree0129c6a456d3d3f838b6fc04a8ebfc678ddeb677 /src
parent7acbf4e2a2cf564b1792d0b67f483fdd20e19b3e (diff)
downloadlibsurvive-9533ddefcf8af901ebc0ff0b2ac503b5af2523b8.tar.gz
libsurvive-9533ddefcf8af901ebc0ff0b2ac503b5af2523b8.tar.bz2
Remove SurviveObject if they fail to configure; prevents issues calibrating with HMD when controllers are off
Diffstat (limited to 'src')
-rw-r--r--src/survive.c25
-rwxr-xr-xsrc/survive_vive.c1
2 files changed, 26 insertions, 0 deletions
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;
}