reearth / resium

React components for 🌏 Cesium
https://resium.reearth.io
MIT License
727 stars 134 forks source link

polyline component adds material property, error occurs #602

Open computeone opened 1 year ago

computeone commented 1 year ago
import { Cartesian3, Color, Material, Transforms } from 'cesium';
import { CameraFlyTo, Polyline, PolylineCollection, Viewer } from 'resium';

export const Scene3D: React.FC = (): JSX.Element => {
    const center = Cartesian3.fromDegrees(-75.59777, 40.03883);
    const positions = [new Cartesian3(-75, 35, 0), new Cartesian3(-125, 35, 0), new Cartesian3(-125, 135, 0)];
    return (
        <Viewer full>
            <PolylineCollection modelMatrix={Transforms.eastNorthUpToFixedFrame(center)}>
                <Polyline
                    positions={positions}
                    material={Material.fromType(Material.ColorType, {
                        color: new Color(1, 0, 0, 1),
                    })}
                />
            </PolylineCollection>
            <CameraFlyTo duration={0} destination={Cartesian3.fromDegrees(-75.6, 40.04, 1000)} />
        </Viewer>
    );
};
DeveloperError: This object was destroyed, i.e., destroy() was called.

Error
    at new DeveloperError (http://localhost:3000/cesium/Cesium.js:12583:13)
    at Material.throwOnDestroyed (http://localhost:3000/cesium/Cesium.js:28943:13)
    at createCommandLists (http://localhost:3000/cesium/Cesium.js:117007:29)
    at PolylineCollection.update (http://localhost:3000/cesium/Cesium.js:116937:7)
    at PrimitiveCollection.update (http://localhost:3000/cesium/Cesium.js:150713:22)
    at updateAndRenderPrimitives (http://localhost:3000/cesium/Cesium.js:212549:23)
    at executeCommandsInViewport (http://localhost:3000/cesium/Cesium.js:212401:5)
    at Scene4.updateAndExecuteCommands (http://localhost:3000/cesium/Cesium.js:212219:7)
    at render (http://localhost:3000/cesium/Cesium.js:212855:11)
    at tryAndCatchError (http://localhost:3000/cesium/Cesium.js:212869:7)
rot1024 commented 1 year ago

How about this?

const material = useMemo(() => Material.fromType(Material.ColorType, { ... }), []);

// ...

<Polyline material={material} />
computeone commented 1 year ago

This will still report an error because the material was destroyed when removed

computeone commented 1 year ago

using useMemo doesn't work, it still reports an error

computeone commented 1 year ago

This is a bug not a question!

eksant commented 9 months ago

Any update for this issue ? I have same error like screenshot below: image image