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

Scalebar - unexpected exception #802

Open
mmoosbac94 opened this issue Jul 11, 2024 · 15 comments · Fixed by #827
Open

Scalebar - unexpected exception #802

mmoosbac94 opened this issue Jul 11, 2024 · 15 comments · Fixed by #827
Assignees
Labels
bug Something isn't working

Comments

@mmoosbac94
Copy link

mmoosbac94 commented Jul 11, 2024

Hello everybody,

we currently have the issue, that there often occurs an exception when using Scalebar:

"onChange(of: Optional) action tried to update multiple times per frame."

In stacktrace we can see that the exception is thrown in Scalebar.swift:

Scalebar.swift

.onChange(of: spatialReference) { viewModel.update($0) }
.onChange(of: unitsPerPoint) { viewModel.update($0) }
.onChange(of: viewpoint) {
    viewModel.update($0) --> Issue here
    viewModel.updateScale()
    if settings.autoHide {
        withAnimation {
            opacity = 1
        }
        withAnimation(.default.delay(settings.autoHideDelay)) {
            opacity = .zero
        }
    }
}

ScalebarViewModel.swift

func update(_ viewpoint: Viewpoint?) {
    self.viewpoint = viewpoint
    if !initialScaleWasCalculated { updateScale() } --> Issue here
}

Generally its working correctly, and we have implemented it as shown in the example. But this exception occurs. Do you know this behaviour or do you have any idea why this happens?

Thank you
Marvin

@mmoosbac94 mmoosbac94 changed the title Scalebar - Exception Scalebar - unexpected exception Jul 11, 2024
@dfeinzimer dfeinzimer added the bug Something isn't working label Jul 11, 2024
@dfeinzimer
Copy link
Collaborator

dfeinzimer commented Jul 11, 2024

Hi @mmoosbac94, thank you for reporting. We'll take a look into the issue.

In the meantime, are there any steps/user-interactions you've found that reliably reproduce the exception?

Edit: I've slightly refactored the indentation in your code snippets for readability.

@dfeinzimer
Copy link
Collaborator

@mmoosbac94 I've also noticed that from the code you've included, it looks like you may be using version 200.3.0 or possibly even earlier.

The problematic area you've indicated above was refactored as of release 200.4.0. If you're in a position to test 200.4.0 - please check to see if you're still able to reproduce this issue. Thank you!

@mmoosbac94
Copy link
Author

@dfeinzimer Thanks for the quick reply!

We are using the newest release 200.4.0. But the issue still persist.

@dfeinzimer dfeinzimer self-assigned this Jul 23, 2024
@dfeinzimer
Copy link
Collaborator

@mmoosbac94 I haven't had luck reproducing the issue so far. Would you please provide a few additional details, including:

  • Xcode version
  • iOS version
  • Simulator or device type
  • What values you're passing to the initializer
  • Any touch gestures or patterns that trigger it

Thanks!

@mhdostal
Copy link
Member

.onChange(of: viewpoint) contains viewModel.updateScale() as does the func update(_ viewpoint: Viewpoint?) method (updateScale()). I wonder if it's getting called twice and that's causing the issue. Also, is there just one "onChange(of: Optional) action tried to update multiple times per frame." in the log or multiple?

@mmoosbac94
Copy link
Author

mmoosbac94 commented Jul 24, 2024

@dfeinzimer Thanks for trying it out. The details are:

  • XCode 15.4
  • iOS 17.5.1
  • Physical iPhone 13
                Scalebar(
                    maxWidth: maxWidth,
                    spatialReference: spatialReference,
                    unitsPerPoint: unitsPerPoint,
                    viewpoint: mapContentViewModel.viewpoint
                )
                .padding(30)
            }

spatialReference + unitsPerPoint are @State
viewpoint is @published

But it sounds interesting what @mhdostal said. Could that be possible and causing the issue? Every third try or so I get the exception: onChange(of: Optional) action tried to update multiple times per frame. once. And I can see in stacktrace that the exception is thrown in viewModel.update($0) and update(_ viewpoint: Viewpoint?) -> updateScale() from scalebar.

@dfeinzimer
Copy link
Collaborator

Hi @mmoosbac94, even when testing with an iOS 17.5.1 device, I'm not able to reproduce the issue. That said, there are a few things I'd like to try.

I've prepared two separate branches. If possible, please try both to see if either of them resolve the issue:

  • bug/802/a
  • bug/802/b

@mmoosbac94
Copy link
Author

Hi @dfeinzimer, I tried both of your branches.

  • In our case without any of your changes the exception is thrown every second attempt more or less
  • With branch "bug/802/b" its pretty much the same behaviour
  • But with branch "bug/802/a" I first thought it was working, but then after more or less 15 attempts the exception was thrown. But of course its an improvement.

dfeinzimer added a commit that referenced this issue Jul 25, 2024
@dfeinzimer
Copy link
Collaborator

Hi @mmoosbac94, thank you for your feedback. I've identified a potential crashing condition. Please test once more with a third branch: "bug/802/c".

If that branch still presents the issue, please consider providing a minimum reproducible example, including the definition of mapContentViewModel which holds viewpoint.

Thanks!

@mmoosbac94
Copy link
Author

Hi @dfeinzimer. Thanks for your changes. It seems that with these changes the app does not crash anymore!

But sometimes I can still see the exception "onChange(of: Optional) action tried to update multiple times per frame.", but without a crash.

@dfeinzimer
Copy link
Collaborator

@mmoosbac94 Great to hear this fixes the crash. This patch will likely make it into 200.5 which should be available very soon.

As for the "onChange" warning you're still seeing; is there any clear indication which onChange modifier is emitting it? Is it definitely also coming out of onChange(of: viewpoint) in Scalebar.swift, or possibly somewhere else?

@mmoosbac94
Copy link
Author

@dfeinzimer Sounds good. Thank you very much again for your effort!

As I could see in stacktrace its definitely coming out of onChange(of: viewpoint) in Scalebar.swift.

@dfeinzimer
Copy link
Collaborator

@mmoosbac94 Thank you for that information. We'll continue to investigate the warning.

In the meantime, the crash fix is available in 200.5.0 as of today.

@dfeinzimer
Copy link
Collaborator

Hi @mmoosbac94, can you please report whether this issue is still reproducible for you?

Note that 200.6.0 is available as of today.

@mmoosbac94
Copy link
Author

Hi @dfeinzimer, for me the issue is not reproducible anymore since the fix in version 200.5.0. But sometimes I still get the warning mentioned above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants