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

Flutter windows app crashes randomly on start #46

Open
kostadin24 opened this issue Jun 30, 2023 · 8 comments
Open

Flutter windows app crashes randomly on start #46

kostadin24 opened this issue Jun 30, 2023 · 8 comments
Labels
bug Something isn't working

Comments

@kostadin24
Copy link

Version of plugin: nsd: ^2.3.0
Same code works on iOs and Android without problem.
Here is what Windows event viewer reporst:

Faulting application name: hn_app_flutter.exe, version: 1.0.0.0, time stamp: 0x649e81df
Faulting module name: nsd_windows_plugin.dll, version: 0.0.0.0, time stamp: 0x64914406
Exception code: 0xc000041d
Fault offset: 0x0000000000025069
Faulting process id: 0x41c0
Faulting application start time: 0x01d9ab2322902b48
Faulting application path: C:\Projects\hn-app-flutter\build\windows\runner\Debug\hn_app_flutter.exe
Faulting module path: C:\Projects\hn-app-flutter\build\windows\runner\Debug\nsd_windows_plugin.dll
Report Id: cf6b7327-95b1-4fff-9388-9634dc8d49e5
Faulting package full name:
Faulting package-relative application ID:

@sebastianhaberey
Copy link
Owner

Sadly I don't have time to work on this now, but just out of interest, is this Windows 11?

@kostadin24
Copy link
Author

Windows 10

@JulienDev
Copy link

Hello!
I'm not sure if it's the same problem, but I also experience crashes daily. About 14% of users encounter at least one crash every day. I don't have extensive details regarding the issue, but the Microsoft Partner Center has provided this stack trace:

Frame Image Function Offset
0 flutter_windows.dll - 0x0000000000001F5E
1 flutter_windows.dll - 0x0000000000000014
2 nsd_windows_plugin.dll - 0x0000000000013ABD
3 nsd_windows_plugin.dll - 0x0000000000005F8A
4 nsd_windows_plugin.dll - 0x0000000000006761
5 nsd_windows_plugin.dll - 0x00000000000056D6
6 dnsapi.dll BrowseContext::InvokeCallback 0x0000000000020410
7 dnsapi.dll WnfParams::StaticCallback 0x0000000000000141
8 ntdll.dll RtlpWnfWalkUserSubscriptionList 0x000000000000024E
9 ntdll.dll RtlpWnfProcessCurrentDescriptor 0x000000000000010A
10 ntdll.dll RtlpWnfNotificationThread 0x0000000000000084
11 ntdll.dll TppExecuteWaitCallback 0x00000000000000AE
12 ntdll.dll TppWorkerThread 0x000000000000072C
13 kernel32.dll BaseThreadInitThunk 0x000000000000001D
14 ntdll.dll RtlUserThreadStart 0x0000000000000028

I can also provide a minidump if necessary. Please let me know how I can assist further. :)

@sebastianhaberey
Copy link
Owner

It's a shame the "Function" column is empty for the plugin stack frames, that would definitely help a lot. Does your minidump contain any information about that?

@JulienDev
Copy link

JulienDev commented Sep 5, 2023

I've never used minidump before today, so I'm not sure if I'm using it correctly. I also generated a pdb file (though I'm uncertain if I did it correctly as well) and injected it into WinDbg. Here's the stack trace I obtained:

0:022> kb
 # RetAddr               : Args to Child                                                           : Call Site
00 00007ffc`137ffcc9     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!NtWaitForMultipleObjects+0x14
01 00007ffc`137ffbce     : 00000000`00000628 00000000`00000096 00000000`d000022d 00000000`d000022d : KERNELBASE!WaitForMultipleObjectsEx+0xe9
02 00007ffc`157627f7     : 00000000`00000000 00000000`00000001 00000009`27dfda50 00000000`00000096 : KERNELBASE!WaitForMultipleObjects+0xe
03 00007ffc`15762236     : 00000000`00000000 00000000`00000000 00000000`00000003 00007ffc`156f0000 : kernel32!WerpReportFaultInternal+0x587
04 00007ffc`138fc90b     : 00000000`00000000 00000009`27dff4c0 00000000`00000001 00000000`00000000 : kernel32!WerpReportFault+0xbe
05 00007ffc`1639625b     : 00000000`00000000 00007ffc`138fc530 00000009`27dff4fc 00000000`00000000 : KERNELBASE!UnhandledExceptionFilter+0x3db
06 00007ffc`16396d72     : 00007ffc`163cff10 00000009`27dff4c0 00000000`0000072c 00000009`27dfdbe8 : ntdll!TppExceptionFilter+0x7f
07 00007ffc`16317780     : 00007ffc`163cff10 00000000`00000008 00000000`00000000 00000000`00000000 : ntdll!TppWorkerpInnerExceptionFilter+0x1a
08 00007ffc`162ff027     : 00007ffc`162a57ac 00007ffc`16290b4a 00007ffc`16270000 00007ffc`162a57ac : ntdll!TppWorkerThread$filt$2+0x19
09 00007ffc`1630ece6     : 00007ffc`163cfff0 00000009`27dfe730 00000009`27dff4c0 00007ffc`121b8000 : ntdll!_C_specific_handler+0x97
0a 00007ffc`1631426f     : 00000000`00000000 00000009`27dfe050 00000009`27dfe730 00000000`00000000 : ntdll!_GSHandlerCheck_SEH+0x6a
0b 00007ffc`1628e456     : 00000009`27dfe730 00007ffc`16270000 00007ffc`162a57ac 00007ffc`163fca10 : ntdll!RtlpExecuteHandlerForException+0xf
0c 00007ffc`1631325e     : 00000000`00000002 008000a0`000dee72 000001b2`df94a240 000001b2`e6fe6220 : ntdll!RtlDispatchException+0x286
0d 00007ffb`85f9261a     : 000001b2`dcb8614f 00007ffb`ef0e4235 00000000`0000009a 00007ffc`00000000 : ntdll!KiUserExceptionDispatch+0x2e
0e 00007ffb`85f90512     : 00000009`27dfec18 00007ffb`ef0f1000 000001b2`00000003 00007ffb`ef0e9cb0 : flutter_windows!FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable+0x1f5e
0f 00007ffb`ef0e521d     : 00000000`0000001f 00000000`0000000f 00000009`27dfed28 00007ffb`ef0d5184 : flutter_windows!FlutterDesktopMessengerSend+0x14
10 00000000`0000001f     : 00000000`0000000f 00000009`27dfed28 00007ffb`ef0d5184 00000000`00000020 : nsd_windows_plugin!std::vector<flutter::EncodableValue,std::allocator<flutter::EncodableValue> >::_Emplace_one_at_back<flutter::EncodableValue>+0x5d
11 00000000`0000000f     : 00000009`27dfed28 00007ffb`ef0d5184 00000000`00000020 00000000`00000005 : 0x1f
12 00000009`27dfed28     : 00007ffb`ef0d5184 00000000`00000020 00000000`00000005 000001b2`d98f8760 : 0xf
13 00007ffb`ef0d5184     : 00000000`00000020 00000000`00000005 000001b2`d98f8760 00000000`00000000 : 0x00000009`27dfed28
14 00000000`00000020     : 00000000`00000005 000001b2`d98f8760 00000000`00000000 000001b2`d7ff2e50 : nsd_windows_plugin!std::_Variant_raw_visit1<2>::_Visit<std::_Variant_construct_visitor<std::monostate,bool,int,__int64,double,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::vector<unsigned char,std::allocator<unsigned char> >,std::vector<int,std::allocator<int> >,std::vector<__int64,std::allocator<__int64> >,std::vector<double,std::allocator<double> >,std::vector<flutter::EncodableValue,std::allocator<flutter::EncodableValue> >,std::map<flutter::EncodableValue,flutter::EncodableValue,std::less<flutter::EncodableValue>,std::allocator<std::pair<flutter::EncodableValue const ,flutter::EncodableValue> > >,flutter::CustomEncodableValue,std::vector<float,std::allocator<float> > >,std::_Variant_storage_<0,std::monostate,bool,int,__int64,double,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::vector<unsigned char,std::allocator<unsigned char> >,std::vector<int,std::allocator<int> >,std::vector<__int64,std::allocator<__int64> >,std::vector<double,std::allocator<double> >,std::vector<flutter::EncodableValue,std::allocator<flutter::EncodableValue> >,std::map<flutter::EncodableValue,flutter::EncodableValue,std::less<flutter::EncodableValue>,std::allocator<std::pair<flutter::EncodableValue const ,flutter::EncodableValue> > >,flutter::CustomEncodableValue,std::vector<float,std::allocator<float> > > const & __ptr64>+0x1b4
15 00000000`00000005     : 000001b2`d98f8760 00000000`00000000 000001b2`d7ff2e50 00007ffb`ef0d76ea : 0x20
16 000001b2`d98f8760     : 00000000`00000000 000001b2`d7ff2e50 00007ffb`ef0d76ea 00000000`00000000 : 0x5
17 00000000`00000000     : 000001b2`d7ff2e50 00007ffb`ef0d76ea 00000000`00000000 00000009`27dfecd0 : 0x000001b2`d98f8760

Minidump attached
8dc6aa84-36e5-4d7d-9762-8308b0de8952.ext.zip

@gomaze0906
Copy link

gomaze0906 commented Sep 6, 2023

I got this when I run my app on Windows after importing nsd package
Not sure it's useful

[ERROR:flutter/shell/common/shell.cc(1004)] The 'com.haberey/nsd' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel.

@sebastianhaberey
Copy link
Owner

@gomaze0906 ok that might actually help, I'll at least have a glance over the Windows platform code this weekend, see if anything looks suspicious!

@sebastianhaberey
Copy link
Owner

I've looked at the Windows code and it seems that it might indeed be necessary to invoke the method channel functions from the main thread. Currently it's done in the callback handler:

void NsdWindows::OnServiceDiscovered(const std::string handle, const DWORD status, PDNS_RECORD records)
{
  // invoke this on the main thread instead
  methodChannel->InvokeMethod("onServiceDiscovered", CreateMethodResult(...)
}

The bad news is, while there is an example of how to do this on Android and iOS in the Flutter documentation, there's nothing on how to do this on windows.

There's an issue by the flutter team about adding functionality to Flutter that would help developers do this on Windows. Until then, the way to go would probably be the hidden message loop mentioned in the issue. There's a link to code in the Flutter engine that could be used as a template, but it's not just copying two lines of code and wrapping some calls, as I had hoped.

Since I don't have much time on my hands right now, I'm afraid we'd need someone with Windows / C++ experience to try their hands on a PR, or we'll have to wait until Flutter provides an API to do this.

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

No branches or pull requests

4 participants