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

Infinite Loop when Changing Mode in onStop with draw.create Event #1347

Open
cdeclerck opened this issue Jan 21, 2025 · 0 comments
Open

Infinite Loop when Changing Mode in onStop with draw.create Event #1347

cdeclerck opened this issue Jan 21, 2025 · 0 comments

Comments

@cdeclerck
Copy link

Title: Infinite Loop when Changing Mode in onStop with draw.create Event

Description:
I'm encountering an infinite loop issue when trying to switch to a custom mode after completing a drawing using mapbox-gl-draw.

When the drawing is finished, my onStop function is triggered, where I fire a draw.create event. After that, I attempt to change the mode to a custom mode using changeMode(). However, this results in a recursive loop with the following error:

mapbox-gl.js?v=40f4fdd7:1833 Uncaught RangeError: Maximum call stack size exceeded
    at Map.fire (mapbox-gl.js?v=40f4fdd7:1833:15)
    at CustomDrawRectangle.onStop (mono.ts:123:14)
    at Object.stop (@mapbox_mapbox-gl-dr…s?v=40f4fdd7:939:14)
    at Object.stop (@mapbox_mapbox-gl-dr…s?v=40f4fdd7:178:27)
    at Object.changeMode (@mapbox_mapbox-gl-dr…?v=40f4fdd7:1090:17)
    at api.changeMode (@mapbox_mapbox-gl-dr…?v=40f4fdd7:3425:16)
    at Map.<anonymous> (roof-zone.vue?t=1737448820365:79:16)
    at Map.fire (mapbox-gl.js?v=40f4fdd7:1838:39)
    at CustomDrawRectangle.onStop (mono.ts:123:14)
    at Object.stop (@mapbox_mapbox-gl-dr…s?v=40f4fdd7:939:14)

Steps to Reproduce:

  1. Start drawing using a custom mode (e.g., CustomDrawRectangle).
  2. When the drawing is completed, onStop is triggered.
  3. In onStop, I fire a draw.create event and immediately call changeMode() to switch to another mode.
  4. This results in an infinite recursive loop and the error above.

Expected Behavior:

I expect to be able to switch to another mode without triggering a recursive loop.

Actual Behavior:

Calling changeMode() inside onStop causes an infinite loop.

Code Snippet:

CustomDrawRectangle.onStop = function () {
    this.map.fire('draw.create', { features: [this.feature] });
    this.changeMode('custom-mode'); // Switching mode triggers an infinite loop
};

Environment:

  • mapbox-gl version: 3.9.3
  • mapbox-gl-draw version: 1.5.0

Possible Cause:

It seems like changeMode() internally calls stop(), which in turn calls onStop again, causing a loop. Perhaps an internal mechanism prevents mode changes inside onStop?

Suggested Fix:

Is there a recommended approach for switching modes after drawing is complete? Should there be a debounce or asynchronous delay before calling changeMode()?

Any insights or workarounds would be appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant