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

Taking screenshot while app is in background crashes the app #1669

Closed
zuboje opened this issue Oct 8, 2023 · 2 comments · Fixed by #1700
Closed

Taking screenshot while app is in background crashes the app #1669

zuboje opened this issue Oct 8, 2023 · 2 comments · Fixed by #1700
Assignees

Comments

@zuboje
Copy link

zuboje commented Oct 8, 2023

Platform

Dart

Obfuscation

Disabled

Debug Info

Enabled

Doctor

[√] Flutter (Channel stable, 3.13.6, on Microsoft Windows [Version 10.0.22621.2283], locale en-US)
• Flutter version 3.13.6 on channel stable at C:\Users\Developer\source\repos\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ead455963c (12 days ago), 2023-09-26 18:28:17 -0700
• Engine revision a794cf2681
• Dart version 3.1.3
• DevTools version 2.25.0

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
• Android SDK at C:\Users\Developer\AppData\Local\Android\sdk
• Platform android-33, build-tools 33.0.1
• Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)
• All Android licenses accepted.

[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.4)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.7.34031.279
• Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2022.2)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)

[√] VS Code (version 1.83.0)
• VS Code at C:\Users\Developer\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.74.0

[√] Connected device (4 available)
• moto g power 2022 (mobile) • ZY22GHDDBB • android-arm64 • Android 12 (API 31)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22621.2283]
• Chrome (web) • chrome • web-javascript • Google Chrome 117.0.5938.149
• Edge (web) • edge • web-javascript • Microsoft Edge 117.0.2045.43

[√] Network resources
• All expected network resources are available.

• No issues found!

Version

7.9.0

Steps to Reproduce

in main.dart setup following

runApp(
    SentryScreenshotWidget(
        child: MyApp(),
    ),
);

Run your application put your application in background or lock your phone, and create a function that will trigger an exception and have something like this:

try {
    DoSometuing();
    throw Exception('Hey something is wrong');
} catch (exception, stackTrace) {
    await Sentry.captureException(
        exception,
        stackTrace: stackTrace,
    );
}

This will throw exception Null check operator used on a null value

Expected Result

If the mobile app is not in the foreground and you cannot capture the screenshot it should ignore it or allow developers to control this based on the application state.

Actual Result

If you have set the mobile application with SentryScreenshotWidget, and the application is in the background when you try to capture an exception using sentry it will throw an exception:

_TypeError
Null check operator used on a null value
painting.dart in _Image.toByteData.. at line 1959

So essentially I have to try/catch for capturing exceptions.

Are you willing to submit a PR?

None

@stefanosiano
Copy link
Member

hi @zuboje
thanks for your report! We are going to look into it

@denrase
Copy link
Collaborator

denrase commented Oct 24, 2023

@zuboje This is a flutter rendering issue and it looks like the fix will part of the Flutter 3.15 Release.

Here's the issue: flutter/flutter#135245

We did implement a workaround where users can disable taking screenshots in the background, but we'll need to discuss if this is even worth including when there is a fix in the Flutter SDK on the way.

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

Successfully merging a pull request may close this issue.

3 participants