question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SteamVR 2.2 + nvidia Flex errors

See original GitHub issue

I am trying to use the SteamVR Plugin with the nvidia Flex fluid renderer. On their own, they all work fine. But when combined, there are runtime errors.

Setup:

  • Unity 2018.3.6f1 (latest at this time)
  • SteamVR Plugin 2.2 (latest from asset store)
  • nvidia Flex for Unity 1.0.5 (latest from asset store)

Steps to reproduce:

  • Create a new Unity project
  • Import the SteamVR Plugin from the store
  • Import nvidia Flex for Unity from the store
  • Turn on your VR system (HTC Vive in my case)
  • Open the flex no.9 Fluid Renderer sample scene, press Play and observe the fluid flow fine in VR
  • Now disable the Camera in that scene and drop in the [CameraRig] from the SteamVR prefabs
  • Press Play now and observe that the fluid stops flowing after a few seconds and the following errors appear:
ArgumentException: ComputeBuffer.SetData() : Accessing 35100 bytes at offset 0 for Compute Buffer of size 35000 bytes is not possible.
UnityEngine.ComputeBuffer.SetData (System.Array data) (at C:/buildslave/unity/build/Runtime/Export/ComputeShader.bindings.cs:124)
NVIDIA.Flex._auxFlexDrawFluid.UpdateMesh (NVIDIA.Flex.FlexContainer+ParticleData _particleData) (at Assets/NVIDIA/Flex/Auxiliary/_auxFlexDrawFluid.cs:247)
NVIDIA.Flex.FlexContainer.UpdateDrawFluid (NVIDIA.Flex.FlexContainer+ParticleData _particleData) (at Assets/NVIDIA/Flex/Assets/FlexContainer.cs:788)
NVIDIA.Flex.FlexContainer.UpdateSolver () (at Assets/NVIDIA/Flex/Assets/FlexContainer.cs:696)
NVIDIA.Flex.FlexContainer.FixedUpdate () (at Assets/NVIDIA/Flex/Assets/FlexContainer.cs:605)
NVIDIA.Flex.FlexScene.FixedUpdate () (at Assets/NVIDIA/Flex/Helpers/FlexScene.cs:68)
LogWarning - Mapping a buffer that was already mapped
File - ..\..\dx\utils.cpp (62)
UnityEngine.Debug:LogError(Object)
NVIDIA.Flex.FlexContainer:ErrorCallback(ErrorSeverity, IntPtr, IntPtr, Int32) (at Assets/NVIDIA/Flex/Assets/FlexContainer.cs:491)
NVIDIA.Flex.FlexExt:MapParticleData()
NVIDIA.Flex.FlexContainer:UpdateSolver() (at Assets/NVIDIA/Flex/Assets/FlexContainer.cs:688)
NVIDIA.Flex.FlexContainer:FixedUpdate() (at Assets/NVIDIA/Flex/Assets/FlexContainer.cs:605)
NVIDIA.Flex.FlexScene:FixedUpdate() (at Assets/NVIDIA/Flex/Helpers/FlexScene.cs:68)

I understand that it seems to be Flex “crashing” here and not SteamVR, which is why I first posted this issue on the nvidia forums, however as SteamVR is implicated (Flex works fine without it) I am here to see if SteamVR Plugin could be improved in some way to not affect other such systems.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

3reactions
rt974commented, Apr 16, 2019

Wow i managed to fix this :

//ORIGINAL
//m_indexBuffer.SetData(indices);
//ORIGINAL
//NEW
if(indices.Length != m_indexBuffer.count)
{
	m_indexBuffer = new ComputeBuffer(indices.Length, sizeof(int));
	m_indexBuffer.SetData(indices);
}
else
{
	m_indexBuffer.SetData(indices);
}
//NEW

The flicker happened because the SetData needs to be called in all cases, the code can be simplified by removing the else, and writing only one SetData at the end.

Now for me this works, i dont really know if this doesnt create side effects, i’ve read somewhere on unity forums that recreating ComputeBuffer every frame is not a good idea. Thats as far as my knowledge goes on this topic.

I hope this helps.

2reactions
oli414commented, Dec 18, 2019

The solution by @reforia keeps the number of drawn particles at the maximum. This becomes a problem when deactivating the fluid source, as the fluids will not despawn until every single one of them has reached the end of its lifetime. Instead I propose this workaround.

Start with a fresh (unmodified) _auxFlexDrawFluid.cs, and simply replace:

if (m_indexBuffer != null)
{
    m_indexBuffer.SetData(indices);
}

at line 245 with:

if (m_indexBuffer != null)
{
    m_indexBuffer.SetData(indices, 0, 0, m_indexBuffer.count);
}

The crash happened because indices doesn’t appear to dynamically change size. So if our max particles is 4000, then indices will have a length of 4000 as long as there’re any particles around. indexCount on the other hand directly reflects how many particles are alive, which may for instance be 3672. So when copying the indices we need to limit what we’re copying by the size of m_indexBuffer. Creating a new m_indexBuffer to match the maximum amount of particles on the other hand causes particles to visually stay in the scene.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flex Unity v1.0.5 + SteamVR: Fluid Error - XR – VR/AR/MR
I downloaded Flex v1.0.5 (latest as of Feb 2019), opened example no.9 Fluid Renderer, pressed Play and I can see the fluid work...
Read more >
Any fix for the constant crashing with SteamVR and Nvidia ...
Two weeks ago I started having the exact same issue on a GTX1070 and Acer WMR. Turning off Reprojection (Motion Smoothing) fixed it...
Read more >
My 3090 Settings for my G2 (2.7.11) - DCS Forum
I use fpsVR for measurement. This guide is aimed at Intel, Nvidia, SteamVR WMR users, others you will be able to get some...
Read more >
OpenComposite OpenXR | Page 7
So AMS2 still launches through Steam VR but OpenXR... ... A surprisingly common problem is the keyboard not working properly.
Read more >
ALVR
ALVR - Air Light VR. Stream VR games from your PC to your headset via Wi-Fi. This is the Oculus Quest app, that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found