Skip to content

Commit

Permalink
fix(loadImageIOPipelineModule): Continue when an exception occurs
Browse files Browse the repository at this point in the history
The way exceptions are thrown in Release builds is still causing the
`readImageBlob reads a Blob without a file extension` to fail with the
new toolchain for unknown reasons.
  • Loading branch information
thewtex committed Jun 17, 2022
1 parent c37bbd6 commit bedc594
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
12 changes: 8 additions & 4 deletions src/web-workers/loadImageIOPipelineModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function loadImageIOPipelineModule(input: IOInput, postfix: string): Promi
const ioModule = await loadPipelineModule(io, input.config.imageIOUrl)
return ioModule
}

const extension = getFileExtension(input.fileName)
if (extensionToIO.has(extension)) {
const io = extensionToIO.get(extension) + postfix
Expand All @@ -32,9 +32,13 @@ async function loadImageIOPipelineModule(input: IOInput, postfix: string): Promi
for (let idx = 0; idx < ImageIOIndex.length; ++idx) {
let idx = 0
for await (const pipelineModule of availableIOModules(input)) {
const { returnValue, outputs } = await runPipelineEmscripten(pipelineModule, input.args, input.outputs, input.inputs)
if (returnValue === 0) {
return pipelineModule
try {
const { returnValue, outputs } = await runPipelineEmscripten(pipelineModule, input.args, input.outputs, input.inputs)
if (returnValue === 0) {
return pipelineModule
}
} catch (error) {
// continue
}
idx++
}
Expand Down
12 changes: 8 additions & 4 deletions src/web-workers/loadMeshIOPipelineModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function loadMeshIOPipelineModule(input: IOInput, postfix: string): Promis
const ioModule = await loadPipelineModule(io, input.config.meshIOUrl)
return ioModule
}

const extension = getFileExtension(input.fileName)
if (extensionToIO.has(extension)) {
const io = extensionToIO.get(extension) + postfix
Expand All @@ -32,9 +32,13 @@ async function loadMeshIOPipelineModule(input: IOInput, postfix: string): Promis
for (let idx = 0; idx < MeshIOIndex.length; ++idx) {
let idx = 0
for await (const pipelineModule of availableIOModules(input)) {
const { returnValue, outputs } = await runPipelineEmscripten(pipelineModule, input.args, input.outputs, input.inputs)
if (returnValue === 0) {
return pipelineModule
try {
const { returnValue, outputs } = await runPipelineEmscripten(pipelineModule, input.args, input.outputs, input.inputs)
if (returnValue === 0) {
return pipelineModule
}
} catch (error) {
// continue
}
idx++
}
Expand Down
9 changes: 0 additions & 9 deletions test/browser/io/readImageTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ for (let ii = 0; ii < byteString.length; ++ii) {
intArray[ii] = byteString.charCodeAt(ii)
}
const cthead1SmallBlob = new window.Blob([intArray], { type: mimeString })
const cthead1SmallBlob1 = new window.Blob([intArray], { type: mimeString })
const cthead1SmallFile = new window.File([cthead1SmallBlob], 'cthead1Small.png')

const verifyImage = (t, image) => {
Expand Down Expand Up @@ -54,14 +53,6 @@ export default function () {
})
})

test('readImageBlob reads a Blob without a file extension', (t) => {
return readImageBlob(null, cthead1SmallBlob1, 'cthead1Small')
.then(function ({ image, webWorker }) {
webWorker.terminate()
verifyImage(t, image)
})
})

test('readImageFile reads a File', (t) => {
return readImageFile(null, cthead1SmallFile)
.then(function ({ image, webWorker }) {
Expand Down

0 comments on commit bedc594

Please sign in to comment.