diff --git a/src/store/datasets-layers.ts b/src/store/datasets-layers.ts index 75b4b33a..d4954637 100644 --- a/src/store/datasets-layers.ts +++ b/src/store/datasets-layers.ts @@ -1,4 +1,5 @@ -import { ref } from 'vue'; +import { computed, ref, unref } from 'vue'; +import { until } from '@vueuse/core'; import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData'; import vtkBoundingBox from '@kitware/vtk.js/Common/DataModel/BoundingBox'; import { defineStore } from 'pinia'; @@ -7,6 +8,7 @@ import { Maybe } from '@/src/types'; import { ensureSameSpace } from '@/src/io/resample/resample'; import { useErrorMessage } from '../composables/useErrorMessage'; import { Manifest, StateFile } from '../io/state-file/schema'; +import useChunkStore from './chunks'; // differ from Image/Volume IDs with a branded type export type LayerID = string & { __type: 'LayerID' }; @@ -66,6 +68,12 @@ export const useLayersStore = defineStore('layer', () => { parent: DataSelection, source: DataSelection ) { + // ensureSameSpace need final image array to resample, so wait for all chunks + const doneLoading = computed( + () => !unref(useChunkStore().chunkImageById[source].isLoading) + ); + await until(doneLoading).toBe(true); + return useErrorMessage('Failed to build layer', async () => { try { await this._addLayer(parent, source);