Skip to content

Commit

Permalink
handle undefined behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
keiya01 committed Jun 28, 2023
1 parent bd2fd59 commit 03746b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 4 additions & 4 deletions web/src/beta/lib/core/engines/Cesium/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import type { Cesium3DTileFeature, Cesium3DTilePointFeature, Globe, Model } from
export type InternalCesium3DTileFeature = Cesium3DTileFeature | Cesium3DTilePointFeature | Model;

export type PrivateCesiumGlobe = Globe & {
_surface: {
_tileProvider: {
_surface?: {
_tileProvider?: {
materialUniformMap?: Record<string, () => unknown>;
};
};
_surfaceShaderSet: {
baseFragmentShaderSource: ShaderSource;
_surfaceShaderSet?: {
baseFragmentShaderSource?: ShaderSource;
};
};
16 changes: 15 additions & 1 deletion web/src/beta/lib/core/engines/Cesium/useOverrideGlobeShader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,16 @@ export const useOverrideGlobeShader = ({
const globe = cesium.current.cesiumElement.scene.globe as PrivateCesiumGlobe;

const surfaceShaderSet = globe._surfaceShaderSet;
if (!surfaceShaderSet) {
if (import.meta.env.DEV) {
throw new Error("`globe._surfaceShaderSet` could not found");
}
return;
}

const baseFragmentShaderSource = surfaceShaderSet.baseFragmentShaderSource;

const GlobeFS = baseFragmentShaderSource.sources[baseFragmentShaderSource.sources.length - 1];
const GlobeFS = baseFragmentShaderSource?.sources[baseFragmentShaderSource.sources.length - 1];

if (!GlobeFS) {
if (import.meta.env.DEV) {
Expand All @@ -90,6 +97,13 @@ export const useOverrideGlobeShader = ({
return;
}

if (!globe?._surface?._tileProvider?.materialUniformMap) {
if (import.meta.env.DEV) {
throw new Error("`globe._surface._tileProvider.materialUniformMap` could not found");
}
return;
}

makeGlobeShadersDirty(globe);

globe._surface._tileProvider.materialUniformMap = {
Expand Down

0 comments on commit 03746b6

Please sign in to comment.