Jeff-Numix / mapbox-gl-draw-bezier-curve-mode

A custom mode for MapboxGL-Draw to draw and edit bezier curves.
48 stars 10 forks source link

Crash on delete polygon vertex - possible fix #5

Open czanbaka opened 1 year ago

czanbaka commented 1 year ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch mapbox-gl-draw-bezier-curve-mode@1.0.2 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/mapbox-gl-draw-bezier-curve-mode/src/lib/.DS_Store b/node_modules/mapbox-gl-draw-bezier-curve-mode/src/lib/.DS_Store
new file mode 100644
index 0000000..e69de29
diff --git a/node_modules/mapbox-gl-draw-bezier-curve-mode/src/lib/modes/directModeBezierOverride.js b/node_modules/mapbox-gl-draw-bezier-curve-mode/src/lib/modes/directModeBezierOverride.js
index d2e809f..33b325f 100644
--- a/node_modules/mapbox-gl-draw-bezier-curve-mode/src/lib/modes/directModeBezierOverride.js
+++ b/node_modules/mapbox-gl-draw-bezier-curve-mode/src/lib/modes/directModeBezierOverride.js
@@ -249,8 +249,11 @@ DirectModeBezierOverride.onKeyDown = function(state, e) {
 DirectModeBezierOverride.onTrash = function(state) {
   const bezierGroup = getBezierGroup(state);

+  // check for null, this happens when you are deleting a vertex on a polygon
+  if(!bezierGroup)  return;
   // Mark Nodes for deletion
   state.selectedCoordPaths.forEach(coordPath => {
     const result = bezierGroup.getBezierCurveAndNodeFromCoordPath(coordPath);
     const bezierCurve = result.bezierCurve;
     const node = result.node;

This issue body was partially generated by patch-package.

Jeff-Numix commented 1 year ago

Hi Czanbaka, Thank you for your contribution. I think its a good idea to check for null as it can cause a crash indeed. Can you make a pull request for this and i will merge it asap. thank you, Best