Skip to content

Commit

Permalink
Fix editor warp crash (#442)
Browse files Browse the repository at this point in the history
* reset errored worker

* catch non-finite warp errors
  • Loading branch information
elalish authored May 27, 2023
1 parent eb41b9d commit 9dac47a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
5 changes: 5 additions & 0 deletions bindings/wasm/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ Module.setup = function() {
}, 'vi');
const out = this._Warp(wasmFuncPtr);
removeFunction(wasmFuncPtr);

const status = out.status();
if (status.value !== 0) {
throw new Module.ManifoldError(status.value);
}
return out;
};

Expand Down
4 changes: 3 additions & 1 deletion bindings/wasm/examples/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,16 @@ function createWorker() {

finishRun();
runButton.disabled = true;
setScript('safe', 'true');

URL.revokeObjectURL(objectURL);
objectURL = e.data.objectURL;
mv.src = objectURL;
if (objectURL == null) {
mv.showPoster();
poster.textContent = 'Error';
createWorker();
} else {
setScript('safe', 'true');
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions bindings/wasm/examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
}
}
</script>
<script>
self.ModelViewerElement = self.ModelViewerElement || {};
self.ModelViewerElement.modelCacheSize = 0;
</script>
<script type="module" src="/examples.js"></script>
</head>

Expand Down
16 changes: 16 additions & 0 deletions src/manifold/src/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,22 @@ void Manifold::Impl::MarkFailure(Error status) {
status_ = status;
}

void Manifold::Impl::Warp(std::function<void(glm::vec3&)> warpFunc) {
thrust::for_each_n(thrust::host, vertPos_.begin(), NumVert(), warpFunc);
CalculateBBox();
if (!IsFinite()) {
MarkFailure(Error::NonFiniteVertex);
return;
}
Update();
faceNormal_.resize(0); // force recalculation of triNormal
CalculateNormals();
SetPrecision();
CreateFaces();
SimplifyTopology();
Finish();
}

Manifold::Impl Manifold::Impl::Transform(const glm::mat4x3& transform_) const {
if (transform_ == glm::mat4x3(1.0f)) return *this;
auto policy = autoPolicy(NumVert());
Expand Down
1 change: 1 addition & 0 deletions src/manifold/src/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ struct Manifold::Impl {

void Update();
void MarkFailure(Error status);
void Warp(std::function<void(glm::vec3&)> warpFunc);
Impl Transform(const glm::mat4x3& transform) const;
SparseIndices EdgeCollisions(const Impl& B) const;
SparseIndices VertexCollisionsZ(const VecDH<glm::vec3>& vertsIn) const;
Expand Down
10 changes: 1 addition & 9 deletions src/manifold/src/manifold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,15 +563,7 @@ Manifold Manifold::Mirror(glm::vec3 normal) const {
*/
Manifold Manifold::Warp(std::function<void(glm::vec3&)> warpFunc) const {
auto pImpl = std::make_shared<Impl>(*GetCsgLeafNode().GetImpl());
thrust::for_each_n(thrust::host, pImpl->vertPos_.begin(), NumVert(),
warpFunc);
pImpl->Update();
pImpl->faceNormal_.resize(0); // force recalculation of triNormal
pImpl->CalculateNormals();
pImpl->SetPrecision();
pImpl->CreateFaces();
pImpl->SimplifyTopology();
pImpl->Finish();
pImpl->Warp(warpFunc);
return Manifold(std::make_shared<CsgLeafNode>(pImpl));
}

Expand Down

0 comments on commit 9dac47a

Please sign in to comment.