Skip to content

Fixes InvalidOperation Exceptions, and other race conditions#581

Closed
Toys0125 wants to merge 2 commits intoBasisVR:developerfrom
Toys0125:Job-sync-fix
Closed

Fixes InvalidOperation Exceptions, and other race conditions#581
Toys0125 wants to merge 2 commits intoBasisVR:developerfrom
Toys0125:Job-sync-fix

Conversation

@Toys0125
Copy link
Contributor

@Toys0125 Toys0125 commented Mar 7, 2026

  • Always complete/apply remote face jobs in render callback, even when local player isn’t ready: BasisEventDriver.cs:231, BasisEventDriver.cs:234
  • Chain remote face scheduling to prior handle: BasisRemoteFaceManagement.cs:93
    • Remote players' face animations should update independently of local player readiness.
  • Chain SteamAudio gather jobs to prior frame and complete pending gather jobs before early returns/resizes/dispose: SteamAudioManager.cs:552, SteamAudioManager.cs:580, SteamAudioManager.cs:1016, SteamAudioManager.cs:1032, SteamAudioManager.cs:1055
  • Harden uLipSync buffer/job sequencing (complete stale job before reschedule, lock buffer swap/write): BasisUlipSync.cs:55, BasisUlipSync.cs:144, BasisUlipSync.cs:164, BasisUlipSync.cs:451, BasisUlipSync.cs:460

* Always complete/apply remote face jobs in render callback, even when local player isn’t ready: BasisEventDriver.cs:231, BasisEventDriver.cs:234
* Chain remote face scheduling to prior handle: BasisRemoteFaceManagement.cs:93
* Chain SteamAudio gather jobs to prior frame and complete pending gather jobs before early returns/resizes/dispose: SteamAudioManager.cs:552, SteamAudioManager.cs:580, SteamAudioManager.cs:1016, SteamAudioManager.cs:1032, SteamAudioManager.cs:1055
* Harden uLipSync buffer/job sequencing (complete stale job before reschedule, lock buffer swap/write): BasisUlipSync.cs:55, BasisUlipSync.cs:144, BasisUlipSync.cs:164, BasisUlipSync.cs:451, BasisUlipSync.cs:460
@dooly123
Copy link
Collaborator

dooly123 commented Mar 7, 2026

There is some fundamental we dont need todo it like this,

just complete it if its not completed early next frame, does not require all of this pain.

@Toys0125
Copy link
Contributor Author

Toys0125 commented Mar 8, 2026

Here's the errors that this pull request fixes, and seems to only show in scene view of editor

InvalidOperationException: The previously scheduled job BasisRemoteFaceManagement:RemoteAnimJob writes to the Unity.Collections.NativeArray`1[BasisRemoteFaceManagement+EyeState] RemoteAnimJob.eyeStates. You are trying to schedule a new job BasisRemoteFaceManagement:RemoteAnimJob, which writes to the same Unity.Collections.NativeArray`1[BasisRemoteFaceManagement+EyeState] (via RemoteAnimJob.eyeStates). To guarantee safety, you must include BasisRemoteFaceManagement:RemoteAnimJob as a dependency of the newly scheduled job.
Unity.Jobs.LowLevel.Unsafe.JobsUtility.ScheduleParallelFor (Unity.Jobs.LowLevel.Unsafe.JobsUtility+JobScheduleParameters& parameters, System.Int32 arrayLength, System.Int32 innerloopBatchCount) (at <dc764b59c049482b93bebc78a7e33a04>:0)
Unity.Jobs.IJobParallelForExtensions.Schedule[T] (T jobData, System.Int32 arrayLength, System.Int32 innerloopBatchCount, Unity.Jobs.JobHandle dependsOn) (at <dc764b59c049482b93bebc78a7e33a04>:0)
BasisRemoteFaceManagement.Simulate (System.Double t, System.Single dt) (at ./Packages/com.basis.framework/Networking/BasisRemoteFaceManagement.cs:93)
BasisEventDriver.LateUpdate () (at ./Packages/com.basis.eventdriver/BasisEventDriver.cs:177)
InvalidOperationException: The previously scheduled job BasisLipSyncJob writes to the Unity.Collections.NativeArray`1[System.Single] BasisLipSyncJob.mfcc. You are trying to schedule a new job BasisLipSyncJob, which writes to the same Unity.Collections.NativeArray`1[System.Single] (via BasisLipSyncJob.mfcc). To guarantee safety, you must include BasisLipSyncJob as a dependency of the newly scheduled job.
Unity.Jobs.LowLevel.Unsafe.JobsUtility.Schedule (Unity.Jobs.LowLevel.Unsafe.JobsUtility+JobScheduleParameters& parameters) (at <dc764b59c049482b93bebc78a7e33a04>:0)
Unity.Jobs.IJobExtensions.Schedule[T] (T jobData, Unity.Jobs.JobHandle dependsOn) (at <dc764b59c049482b93bebc78a7e33a04>:0)
BasisUlipSync.Simulate (System.Single DeltaTime) (at ./Packages/com.hecomi.ulipsync/BasisUlipSync.cs:196)
Basis.Scripts.Drivers.BasisAudioAndVisemeDriver.Simulate (System.Single DeltaTime) (at ./Packages/com.basis.framework/Drivers/Common/BasisAudioAndVisemeDriver.cs:181)
Basis.Scripts.Drivers.BasisRemoteAudioDriver.Simulate (System.Single DeltaTime) (at ./Packages/com.basis.framework/Drivers/Remote/BasisRemoteAudioDriver.cs:77)
BasisEventDriver.LateUpdate () (at ./Packages/com.basis.eventdriver/BasisEventDriver.cs:163)
InvalidOperationException: The previously scheduled job SteamAudioManager:GatherPoseJob writes to the Unity.Collections.NativeArray`1[SteamAudio.SteamAudioManager+GatheredData] GatherPoseJob.PoseData. You are trying to schedule a new job SteamAudioManager:GatherPoseJob, which writes to the same Unity.Collections.NativeArray`1[SteamAudio.SteamAudioManager+GatheredData] (via GatherPoseJob.PoseData). To guarantee safety, you must include SteamAudioManager:GatherPoseJob as a dependency of the newly scheduled job.
Unity.Jobs.LowLevel.Unsafe.JobsUtility.ScheduleParallelForTransform (Unity.Jobs.LowLevel.Unsafe.JobsUtility+JobScheduleParameters& parameters, System.IntPtr transfromAccesssArray) (at <dc764b59c049482b93bebc78a7e33a04>:0)
UnityEngine.Jobs.IJobParallelForTransformExtensions.Schedule[T] (T jobData, UnityEngine.Jobs.TransformAccessArray transforms, Unity.Jobs.JobHandle dependsOn) (at <dc764b59c049482b93bebc78a7e33a04>:0)
SteamAudio.SteamAudioManager.ScheduleInstance () (at ./Packages/com.steam.steamaudio/Runtime/SteamAudioManager.cs:561)
SteamAudio.SteamAudioManager.Schedule () (at ./Packages/com.steam.steamaudio/Runtime/SteamAudioManager.cs:522)
BasisEventDriver.LateUpdate () (at ./Packages/com.basis.eventdriver/BasisEventDriver.cs:176)
InvalidOperationException: The previously scheduled job BasisLipSyncJob reads from the Unity.Collections.NativeArray`1[System.Single] BasisLipSyncJob.input. You must call JobHandle.Complete() on the job BasisLipSyncJob, before you can write to the Unity.Collections.NativeArray`1[System.Single] safely.
Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckWriteAndThrowNoEarlyOut (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <dc764b59c049482b93bebc78a7e33a04>:0)
Unity.Collections.LowLevel.Unsafe.NativeArrayUnsafeUtility.GetUnsafePtr[T] (Unity.Collections.NativeArray`1[T] nativeArray) (at <dc764b59c049482b93bebc78a7e33a04>:0)
BasisUlipSync.OnDataReceived (System.Single[] input, System.Int32 channels, System.Int32 length) (at ./Packages/com.hecomi.ulipsync/BasisUlipSync.cs:447)
Basis.Scripts.Drivers.BasisAudioAndVisemeDriver.ProcessAudioSamples (System.Single[] data, System.Int32 channels, System.Int32 Length) (at ./Packages/com.basis.framework/Drivers/Common/BasisAudioAndVisemeDriver.cs:246)
Basis.Scripts.Drivers.BasisRemoteAudioDriver.OnAudioFilterRead (System.Single[] data, System.Int32 channels) (at ./Packages/com.basis.framework/Drivers/Remote/BasisRemoteAudioDriver.cs:49)

@dooly123
Copy link
Collaborator

dooly123 commented Mar 8, 2026

those issues are all related to us just not finishing the work in update through a check to see if the tasks where completed last frame, (they get skipped since onrenderbefore never fires)

the fixes your suggestion would stack

so each frame * total work that frame = queued work

this will explode badly.

@dooly123
Copy link
Collaborator

dooly123 commented Mar 8, 2026

fixed with commit a99291b

@dooly123 dooly123 closed this Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants