Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destroying focused object breaks Client sim (Works fine in VRChat) #59

Open
iffn opened this issue Dec 4, 2022 · 0 comments · Fixed by #80
Open

Destroying focused object breaks Client sim (Works fine in VRChat) #59

iffn opened this issue Dec 4, 2022 · 0 comments · Fixed by #80
Assignees
Labels
bug Something isn't working

Comments

@iffn
Copy link

iffn commented Dec 4, 2022

Destroying objects that the Client sim is currently looking at seems to break the Client sim.
This seems to be a Client sim issue and does not occur in VRChat.

Test:

I added a script to a cube which destroys the attached gameObject in the Interact() function. When looking at the cube and interacting with it, the Client sim breaks. Note: This also seems to happen when the GameObject is destroyed through other means such as the Editor or the Update function.

Video: https://www.youtube.com/watch?v=v583uamE2_c

Ugly hotfix:

I followed the error messages and I was able to avoid the issue by modifying 2 files.
Note: I have not looked into the architecture of the code. So this is probably neither nice nor reliable.

ClientSimTooltip.cs

public void UpdateTooltip(Vector3 playerPos, Vector3 up)
{
    // Added try catch block since Interactable.GetInteractTextPlacement() fails when the GameObject has been destroyed
    Vector3 position = Vector3.zero;

    try
    {
        position = Interactable.GetInteractTextPlacement();
    }
    catch (MissingReferenceException e)
    {
        Debug.LogWarning($"Avoided exception: {e}");
    }
            
    // Rotate to look towards the player while keeping the proper up direction.
    // VRChatBug: Build 1160 has this broken again so that rotating the player through stations does not properly rotate tooltips.
    Quaternion rotation = Quaternion.LookRotation(Vector3.ProjectOnPlane(playerPos - position, up), up);
    transform.SetPositionAndRotation(position, rotation);
}

ClientSimHighlightManager.cs:

private List<Renderer> GatherRenderers(GameObject obj, bool findDisabled)
{
    List<Renderer> results = new List<Renderer>();

    // Added null pointer check
    if (obj == null)
    {
        Debug.LogWarning($"Avoided null pointer exception in {nameof(GatherRenderers)}");
        return results;
    }

    foreach (var rend in obj.GetComponentsInChildren<Renderer>(findDisabled))
    {
        if (!rend.enabled || rend.isPartOfStaticBatch)
        {
            continue;
        }
        MeshFilter filter = rend.GetComponent<MeshFilter>();
        if (filter == null || filter.sharedMesh == null)
        {
            continue;
        }
                
        results.Add(rend);
    }

    return results;
}
@KhopeshActual KhopeshActual added the bug Something isn't working label Apr 28, 2023
@momo-the-monster momo-the-monster linked a pull request May 3, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants