waitingsong / node-win32-api

win32 api
MIT License
430 stars 55 forks source link

Demo crashes after some callbacks called, without any error output #13

Closed tinyAdapter closed 5 years ago

tinyAdapter commented 5 years ago

After WndProc callback being called about 200 times, the whole process crashed without any error output.

The last several callback messages seems no exception:

WndProc callback:  32 661470 33554433
Sending LRESULT: 0

WndProc callback:  512 0 5505193
Sending LRESULT: 0

WndProc callback:  132 0 9240778
Sending LRESULT: 1

WndProc callback:  32 661470 33554433
Sending LRESULT: 0

WndProc callback:  512 0 5505192
Sending LRESULT: 0

WndProc callback:  132 0 9306312
Sending LRESULT: 1

WndProc callback:  32 661470 33554433
Sending LRESULT: 0

WndProc callback:  512 0 5570726
Sending LRESULT: 0

WndProc callback:  132 0 9371848
Sending LRESULT: 1

X:\path\to\the\project>

BTW, this is not the first time I've faced such a problem, any win32 APIs with callback have this weird behavior after some calls.

I've tried holding the reference of callback function with process.on('exit', function() { WndProc; }), but nothing worked at all.

waitingsong commented 5 years ago

Which your platform and 32/64?

tinyAdapter commented 5 years ago

win10 x64 build 17763 (1809) with node.js v8.15.0-x86

tinyAdapter commented 5 years ago

UPDATE: upgrade node to v10.15.1, back to package ffi and ref solve the problem.

Conclusion (under my test):

node version ffi / ffi-napi work
8 ffi No
8 ffi-napi No
10 ffi Yes
10 ffi-napi No

Cannot figure out whether it's bug of node or ffi-napi, maybe both. 🤔

waitingsong commented 5 years ago

I found ffi-napi not stable yet. https://github.com/node-ffi-napi/node-ffi-napi/issues/33

ffi should work fine under nodejs v8.x.

waitingsong commented 5 years ago

pls try version v33 with updated version of ffi

npm i win32-api@^3.7.0

Test for Node.js v8, v10, v11: https://ci.appveyor.com/project/waitingsong/node-win32-api/builds/22538193

waitingsong commented 5 years ago

@tinyAdapter It works with 1k loops. demo: https://github.com/waitingsong/node-win32-api/blob/v3/test/90_loop_callback.test.ts

tinyAdapter commented 5 years ago

I've switched to node v10 and cannot test it right now. But seems it worked. I'm closing this issue. If someone still got the similar problem, comment here.