parro-it / libui-node

Node bindings for libui, an awesome native UI library for Unix, OSX and Windows
MIT License
1.88k stars 85 forks source link

Reimplements setTimeout & setInterval on top of uiTimer #93

Open parro-it opened 6 years ago

parro-it commented 6 years ago

Dependent on / fixed by #92

cztomsik commented 6 years ago

Not sure if it's related but if you do setInterval(() => console.log('tick'), 1000) after startLoop() the whole app goes down:

2018-06-11 12:49:03.566 node[97792:13847215] get 0x0
cons
2018-06-11 12:49:03.599 node[97792:13847215] +[NSTimer scheduledTimerWithTimeInterval:repeats:block:]: unrecognized selector sent to class 0x7fff76761a88
2018-06-11 12:49:03.601 node[97792:13847215] An uncaught exception was raised
2018-06-11 12:49:03.601 node[97792:13847215] +[NSTimer scheduledTimerWithTimeInterval:repeats:block:]: unrecognized selector sent to class 0x7fff76761a88
2018-06-11 12:49:03.601 node[97792:13847215] (
    0   CoreFoundation                      0x00007fff937fa4f2 __exceptionPreprocess + 178
    1   libobjc.A.dylib                     0x00007fff9019af7e objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff938640ad +[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x00007fff9376a571 ___forwarding___ + 1009
    4   CoreFoundation                      0x00007fff9376a0f8 _CF_forwarding_prep_0 + 120
    5   nbind.node                          0x0000000104d5861d _Z11setIntervalRN5nbind9cbWrapperIvEEj + 176
    6   nbind.node                          0x0000000104d1829e _ZN5nbind6CallerIP13TimeoutHandleNS_8TypeListIJNS_11ArgFromWireINS_14PolicyListTypeIJEEELm0ERNS_9cbWrapperIvEEEENS4_IS6_Lm1EjEEEEEE12callFunctionIPFS2_S9_jEKN3Nan20FunctionCallbackInfoIN2v85ValueEEEEENSJ_5LocalISK_EET_RT0_ + 70
    7   nbind.node                          0x0000000104d18106 _ZN5nbind22TemplatedBaseSignatureINS_17FunctionSignatureIPFP13TimeoutHandleRNS_9cbWrapperIvEEjEDnNS_14PolicyListTypeIJEEES3_JS6_jEEESA_S3_JS6_jEE15callInnerSafelyIvKN3Nan20FunctionCallbackInfoIN2v85ValueEEESJ_EEvRT0_RT1_j + 260
    8   nbind.node                          0x0000000104d59a41 _ZN3Nan3impL23FunctionCallbackWrapperERKN2v820FunctionCallbackInfoINS1_5ValueEEE + 137
    9   node                                0x0000000100196d32 _ZN2v88internal25FunctionCallbackArguments4CallEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEE + 466
    10  node                                0x00000001001f7530 _ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS0_6HandleINS0_10HeapObjectEEESA_NS8_INS0_20FunctionTemplateInfoEEENS8_IS4_EENS0_16BuiltinArgumentsE + 816
    11  node                                0x00000001001f6b70 _ZN2v88internalL26Builtin_Impl_HandleApiCallENS0_16BuiltinArgumentsEPNS0_7IsolateE + 288
    12  ???                                 0x000018f61f9842fd 0x0 + 27445371093757
    13  ???                                 0x000018f61fa3d196 0x0 + 27445371851158
    14  ???                                 0x000018f61fa3d196 0x0 + 27445371851158
    15  ???                                 0x000018f61fa3d196 0x0 + 27445371851158
    16  ???                                 0x000018f61fa3d196 0x0 + 27445371851158
    17  ???                                 0x000018f61f98535f 0x0 + 27445371097951
    18  ???                                 0x000018f61fa3d196 0x0 + 27445371851158
    19  ???                                 0x000018f61fa3d196 0x0 + 27445371851158
)
2018-06-11 12:49:03.601 node[97792:13847215] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSTimer scheduledTimerWithTimeInterval:repeats:block:]: unrecognized selector sent to class 0x7fff76761a88'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff937fa4f2 __exceptionPreprocess + 178
    1   libobjc.A.dylib                     0x00007fff9019af7e objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff938640ad +[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x00007fff9376a571 ___forwarding___ + 1009
    4   CoreFoundation                      0x00007fff9376a0f8 _CF_forwarding_prep_0 + 120
    5   nbind.node                          0x0000000104d5861d _Z11setIntervalRN5nbind9cbWrapperIvEEj + 176
    6   nbind.node                          0x0000000104d1829e _ZN5nbind6CallerIP13TimeoutHandleNS_8TypeListIJNS_11ArgFromWireINS_14PolicyListTypeIJEEELm0ERNS_9cbWrapperIvEEEENS4_IS6_Lm1EjEEEEEE12callFunctionIPFS2_S9_jEKN3Nan20FunctionCallbackInfoIN2v85ValueEEEEENSJ_5LocalISK_EET_RT0_ + 70
    7   nbind.node                          0x0000000104d18106 _ZN5nbind22TemplatedBaseSignatureINS_17FunctionSignatureIPFP13TimeoutHandleRNS_9cbWrapperIvEEjEDnNS_14PolicyListTypeIJEEES3_JS6_jEEESA_S3_JS6_jEE15callInnerSafelyIvKN3Nan20FunctionCallbackInfoIN2v85ValueEEESJ_EEvRT0_RT1_j + 260
    8   nbind.node                          0x0000000104d59a41 _ZN3Nan3impL23FunctionCallbackWrapperERKN2v820FunctionCallbackInfoINS1_5ValueEEE + 137
    9   node                                0x0000000100196d32 _ZN2v88internal25FunctionCallbackArguments4CallEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEE + 466
    10  node                                0x00000001001f7530 _ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS0_6HandleINS0_10HeapObjectEEESA_NS8_INS0_20FunctionTemplateInfoEEENS8_IS4_EENS0_16BuiltinArgumentsE + 816
    11  node                                0x00000001001f6b70 _ZN2v88internalL26Builtin_Impl_HandleApiCallENS0_16BuiltinArgumentsEPNS0_7IsolateE + 288
    12  ???                                 0x000018f61f9842fd 0x0 + 27445371093757
    13  ???                                 0x000018f61fa3d196 0x0 + 27445371851158
    14  ???                                 0x000018f61fa3d196 0x0 + 27445371851158
    15  ???                                 0x000018f61fa3d196 0x0 + 27445371851158
    16  ???                                 0x000018f61fa3d196 0x0 + 27445371851158
    17  ???                                 0x000018f61f98535f 0x0 + 27445371097951
    18  ???                                 0x000018f61fa3d196 0x0 + 27445371851158
    19  ???                                 0x000018f61fa3d196 0x0 + 27445371851158
)
libc++abi.dylib: terminating with uncaught exception of type NSException
mischnic commented 6 years ago

@cztomsik Can you please post a code example and your macOS version?

This works fine for me:

const libui = require("libui-node");

libui.startLoop();
setInterval(() => console.log('tick'), 1000)
cztomsik commented 6 years ago

10.11.6 (El Capitan)

libui-node-test-timeout$ node test.js 
2018-06-19 13:29:21.321 node[25449:14052047] get 0x0
2018-06-19 13:29:21.328 node[25449:14052047] +[NSTimer scheduledTimerWithTimeInterval:repeats:block:]: unrecognized selector sent to class 0x7fff76761a88
2018-06-19 13:29:21.330 node[25449:14052047] An uncaught exception was raised
2018-06-19 13:29:21.330 node[25449:14052047] +[NSTimer scheduledTimerWithTimeInterval:repeats:block:]: unrecognized selector sent to class 0x7fff76761a88
2018-06-19 13:29:21.330 node[25449:14052047] (
    0   CoreFoundation                      0x00007fff937fa4f2 __exceptionPreprocess + 178
    1   libobjc.A.dylib                     0x00007fff9019af7e objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff938640ad +[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x00007fff9376a571 ___forwarding___ + 1009
    4   CoreFoundation                      0x00007fff9376a0f8 _CF_forwarding_prep_0 + 120
    5   nbind.node                          0x0000000104ba661d _Z11setIntervalRN5nbind9cbWrapperIvEEj + 176
    6   nbind.node                          0x0000000104b6629e _ZN5nbind6CallerIP13TimeoutHandleNS_8TypeListIJNS_11ArgFromWireINS_14PolicyListTypeIJEEELm0ERNS_9cbWrapperIvEEEENS4_IS6_Lm1EjEEEEEE12callFunctionIPFS2_S9_jEKN3Nan20FunctionCallbackInfoIN2v85ValueEEEEENSJ_5LocalISK_EET_RT0_ + 70
    7   nbind.node                          0x0000000104b66106 _ZN5nbind22TemplatedBaseSignatureINS_17FunctionSignatureIPFP13TimeoutHandleRNS_9cbWrapperIvEEjEDnNS_14PolicyListTypeIJEEES3_JS6_jEEESA_S3_JS6_jEE15callInnerSafelyIvKN3Nan20FunctionCallbackInfoIN2v85ValueEEESJ_EEvRT0_RT1_j + 260
    8   nbind.node                          0x0000000104ba7a41 _ZN3Nan3impL23FunctionCallbackWrapperERKN2v820FunctionCallbackInfoINS1_5ValueEEE + 137
    9   node                                0x0000000100196d32 _ZN2v88internal25FunctionCallbackArguments4CallEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEE + 466
    10  node                                0x00000001001f7530 _ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS0_6HandleINS0_10HeapObjectEEESA_NS8_INS0_20FunctionTemplateInfoEEENS8_IS4_EENS0_16BuiltinArgumentsE + 816
    11  node                                0x00000001001f6b70 _ZN2v88internalL26Builtin_Impl_HandleApiCallENS0_16BuiltinArgumentsEPNS0_7IsolateE + 288
    12  ???                                 0x00001fbfa28842fd 0x0 + 34907926053629
    13  ???                                 0x00001fbfa293d196 0x0 + 34907926811030
    14  ???                                 0x00001fbfa293d196 0x0 + 34907926811030
)
2018-06-19 13:29:21.331 node[25449:14052047] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSTimer scheduledTimerWithTimeInterval:repeats:block:]: unrecognized selector sent to class 0x7fff76761a88'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff937fa4f2 __exceptionPreprocess + 178
    1   libobjc.A.dylib                     0x00007fff9019af7e objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff938640ad +[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x00007fff9376a571 ___forwarding___ + 1009
    4   CoreFoundation                      0x00007fff9376a0f8 _CF_forwarding_prep_0 + 120
    5   nbind.node                          0x0000000104ba661d _Z11setIntervalRN5nbind9cbWrapperIvEEj + 176
    6   nbind.node                          0x0000000104b6629e _ZN5nbind6CallerIP13TimeoutHandleNS_8TypeListIJNS_11ArgFromWireINS_14PolicyListTypeIJEEELm0ERNS_9cbWrapperIvEEEENS4_IS6_Lm1EjEEEEEE12callFunctionIPFS2_S9_jEKN3Nan20FunctionCallbackInfoIN2v85ValueEEEEENSJ_5LocalISK_EET_RT0_ + 70
    7   nbind.node                          0x0000000104b66106 _ZN5nbind22TemplatedBaseSignatureINS_17FunctionSignatureIPFP13TimeoutHandleRNS_9cbWrapperIvEEjEDnNS_14PolicyListTypeIJEEES3_JS6_jEEESA_S3_JS6_jEE15callInnerSafelyIvKN3Nan20FunctionCallbackInfoIN2v85ValueEEESJ_EEvRT0_RT1_j + 260
    8   nbind.node                          0x0000000104ba7a41 _ZN3Nan3impL23FunctionCallbackWrapperERKN2v820FunctionCallbackInfoINS1_5ValueEEE + 137
    9   node                                0x0000000100196d32 _ZN2v88internal25FunctionCallbackArguments4CallEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEE + 466
    10  node                                0x00000001001f7530 _ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS0_6HandleINS0_10HeapObjectEEESA_NS8_INS0_20FunctionTemplateInfoEEENS8_IS4_EENS0_16BuiltinArgumentsE + 816
    11  node                                0x00000001001f6b70 _ZN2v88internalL26Builtin_Impl_HandleApiCallENS0_16BuiltinArgumentsEPNS0_7IsolateE + 288
    12  ???                                 0x00001fbfa28842fd 0x0 + 34907926053629
    13  ???                                 0x00001fbfa293d196 0x0 + 34907926811030
    14  ???                                 0x00001fbfa293d196 0x0 + 34907926811030
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6

Code is here

mischnic commented 6 years ago

Oh, I missed the text "macOS 10.12+" on Apples API documentation 😄 . This wil be fixed with the 0.3.0 release.

cztomsik commented 6 years ago

Cool, thx :)