Fix uninitialized member state in IKSolverVR causing erratic elbow/arm IK#8
Draft
Copilot wants to merge 2 commits into
Draft
Fix uninitialized member state in IKSolverVR causing erratic elbow/arm IK#8Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
Agent-Logs-Url: https://github.com/BSQ-VRM/VRM-Qavatars/sessions/70de94b6-d9a8-45b2-9a06-3e59663c427c Co-authored-by: Futuremappermydud <54294576+Futuremappermydud@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix uninitialized member state in IKSolverVR
Fix uninitialized member state in IKSolverVR causing erratic elbow/arm IK
May 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Several
IKSolverVRmembers were declared without default values, leading to nondeterministic solver initialization and potential junk-pointer dereferences that manifested as unstable elbow/arm positioning.Changes —
include/customTypes/FinalIK/IKSolverVR.hppbool initiated→= false: gatesFixTransforms(),Update(), andRead(); garbage value allows solver to run before initbool firstInitiation→= true:Update()uses this to triggerInitiate(root)on first call; must starttrueUnityEngine::Transform* root→= nullptr: passed intoInitiate()on first update; uninitialized = crash riskVirtualBone* rootBone→= nullptr:Read()branches onrootBone == nullptrto construct vs. update the bone; a garbage non-null pointer would invokeRead()on invalid memory, corrupting the entire arm chainint supportLegIndex→= -1(was0): code explicitly resets to-1at the start of each solve cycle before recomputing; starting at0falsely marks leg 0 as the support leg on the first frame, biasing root/shoulder spaceOriginal prompt
Create a PR for repo BSQ-VRM/VRM-Qavatars (base: main) to address buggy elbow/arm IK behavior likely caused by uninitialized member state in IKSolverVR.
Context:
Required changes:
Notes:
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: There's an issue with the elbow positioning being buggy, i'm thinking uninitialized float. any ideas?
Assistant: Most likely, yes: you have uninitialized state, but it’s not a float—it's multiple member variables/pointers in
IKSolverVRthat are never initialized (and can directly manifest as “random elbow” / arm-solver instability).1)
initiatedandfirstInitiationare never initializedIn
IKSolverVR.hppthese are declared but have no default values:Yet they gate important behavior:
FixTransforms()early-outs on!initiatedUpdate()callsInitiate(root)iffirstInitiationis trueRead()has special one-time init logic underif (!initiated)If either bool starts as garbage, you can get:
That kind of “sometimes the elbow explodes / jitters” is classic.
Fix: default-initialize them in the header:
2)
rootBoneis also never initializedIn the header:
In
Read()you do:But if
rootBoneis uninitialized garbage, it may be non-null and you’ll callrootBone->Read(...)on a junk pointer. That can corrupt anything, including arm chain data used for elbows.So
rootBone = nullptr;is critical.3)
supportLegIndexdefault is suspiciousYou set:
But later in
Solve()you pass it into locomotion:locomotion->Solve(..., supportLegIndex, ...);And only after a full solve do you recompute it, and you also sometimes set it to
-1:supportLegIndex = -1; ... supportLegIndex = m;If locomotion expects
-1initially (or validates it), starting at0might bias locomotion/root offsets for the first frame(s). That can indirectly disturb arm/shoulder space and show up as elbow weirdness. Not as strong as the uninitialized pointers/bools, but worth fixing.What I’d do first (minimal changes, high impact)
IKSolverVR.hpp:initiated = falsefirstInitiation = true(if you rely on it to auto-init)root = nullptrrootBone = nullptrsupportLegIndex = -1as the safer default.Quick verification
If you can add logging for one run, print at solver construction / first
Update():initiated,firstInitiation,rootBone,rootIf any look non-deterministic between runs, that confirms it.
If you want, paste
VR/Arm.*(especially where elbow bend plane / pole vector is derived) and I can point to the next most likely culprit after initialization (often a zero-length axis or invalid shoulder/chest reference feeding the elbow plane).User: can you make a pr with those changes?
Assistant: I’ve queued up the pull request creation with the member-initialization fixes, and I’m currently waiting for your approval in the confirmation dialo...
This pull request was created from Copilot chat.