CesiumGS / CesiumGS/cesium-unity

Setting CesiumGeoJsonDocument in WebGL causes MemoryAcessOutOfBounds

Open
#690 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
C#
Stars
535
Forks
132
Avg merge
6h 45m
Merged PRs (30d)
1

Description

### What happened?

Heya everyone,

as the title describes setting `CesiumGeoJsonDocument` for `CesiumGeoJsonDocumentRasterOverlay.document` during runtime, causes a _Uncaught RuntimeError: memory access out of bounds_ in the Browser for WebGL builds.

The same is true when using `CesiumGeoJsonDocumentRasterOverlay.source = CesiumGeoJsonDocumentRasterOverlaySource.FromUrl`.

Furthermore, adding a `CesiumGeoJsonDocumentRasterOverlay` Component to the GameObject of the 3D Tileset and setting `CesiumGeoJsonDocumentRasterOverlaySource.FromUrl` in the editor (and leaving away all runtime logic) does **NOT** mitigate this issue.

I have tested this behaviour in multiple Browsers in a fresh Unity Project.

Here is a minimal script that can be added to an empty GameObject in a minimal scene to trigger the bug:

```C#
using CesiumForUnity;
using UnityEngine;

public class TestScript : MonoBehaviour
{
private const string ClippingKey = "Clipping";

// Test GeoJson authored in QGis
private string geoJson = @"
{
""type"": ""FeatureCollection"",
""name"": ""sm_beach_test"",
""crs"": { ""type"": ""name"", ""properties"": { ""name"": ""urn:ogc:def:crs:OGC:1.3:CRS84"" } },
""features"": [
{ ""type"": ""Feature"", ""properties"": { ""id"": null }, ""geometry"": { ""type"": ""MultiPolygon"", ""coordinates"": [ [ [ [ -118.502622339460956, 34.016051530590985 ], [ -118.502846531725368, 34.015883123181212 ], [ -118.503161802097196, 34.016161866299022 ], [ -118.503498090493878, 34.015917966120988 ], [ -118.503168808105499, 34.015662450897175 ], [ -118.503631204650844, 34.015337248590988 ], [ -118.504640069840818, 34.016219937666698 ], [ -118.504275757411122, 34.01648706544637 ], [ -118.504002523088829, 34.016643857447306 ], [ -118.50360318061783, 34.016678700074841 ], [ -118.503308928270769, 34.016655471658069 ], [ -118.502622339460956, 34.016051530590985 ] ] ] ] } }]
}
";

// A place somehwere at Santa Monica Beach
private double lat = 34.0132d;
private double lon = -118.5d;
private double alt = 25d;

public CesiumGeoreference geoRef;
public Cesium3DTileset googleTileset;

void Start()
{
geoRef.latitude = lat;
geoRef.longitude = lon;
geoRef.height = alt;

CesiumGeoJsonDocument document = CesiumGeoJsonDocument.Parse(geoJson);

CesiumGeoJsonDocumentRasterOverlay overlay = googleTileset.gameObject.AddComponent();
overlay.source = CesiumGeoJsonDocumentRasterOverlaySource.FromDocument;
overlay.materialKey = ClippingKey;

overlay.document = document; // <--- Crash occurs when setting the document!
}
}
```

### Environment

Cesium for Unity version: 1.23.2
Unity Editor Version: 6000.4.4f1
Operating System: Win11
Browser: Chromium, Firefox

### Reproduction steps

1. Setup Cesium for Unity (for Web) following the [official guideline](https://cesium.com/learn/cesium-unity/ref-doc/supported-platforms.html)
2. Setup a scene with Light, Camera, CesiumGeoReference and Google Photorealistic 3D Tiles.
3. Add the script above as a Component to an empty GameObject and wire up the necessary references in the Editor.
4. Build for WebGL (using _Build & Run_ OR by _building & self-hosting_)
5. Launch Website and witness the crash.

### Supporting evidence

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.