Skip to content

Prevent access on null CesiumPointCloudShading #605

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

j9liu
Copy link
Contributor

@j9liu j9liu commented Aug 22, 2025

Description

This addresses a bug with point cloud tilesets that are created at runtime. Since CesiumPointCloudShading is a class, not a struct, it's possible for a Cesium3DTileset to be missing one, which is exactly what happens when it is created at runtime. This PR adds checks for a null reference, and also explicitly initializes CesiumPointCloudShading inline for good measure.

Ideally, CesiumPointCloudShading would just be a struct to avoid this, but C# 9.0 does not like structs with non-zero default values. :)

Issue number or link

Fixes #602.

Author checklist

  • I have done a full self-review of my code.
  • I have updated CHANGES.md with a short summary of my change (for user-facing changes).
  • [ ] I have added or updated unit tests to ensure consistent code coverage as necessary.
  • [] I have updated the documentation as necessary.

Testing plan

  1. Start from 02_CesiumMelbourne in the Cesium samples.
  2. Create a new script called PointCloudLoader with the contents below.
  3. Add the component to any arbitrary GameObject. I just tacked it onto the Getting Started object.
  4. Press Play. Ensure that the console is not spammed with errors as the points load in.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using CesiumForUnity;

public class PointCloudLoader : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        var go = new GameObject("PointCloud");
        go.transform.SetParent(FindObjectOfType<CesiumGeoreference>().transform);
        Cesium3DTileset tileset = go.AddComponent<Cesium3DTileset>();
        tileset.ionAssetID = 43978;
    }
}

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.

Cesium3DTileset.pointCloudShading at runtime error
1 participant