Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix editor warp crash #442

Merged
merged 2 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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