node addon回调引发的crash
发布于 5 年前 作者 pipi32167 2783 次浏览 最后一次编辑是 4 年前 来自 问答

将Function * 保存起来

	Function *cb = *Handle<Function>::Cast(args[1]);
	void *callback_data = (void *)(cb);
	info.callback_data_ = (unsigned char *)callback_data;
	info.callback_data_len_ = sizeof(callback_data);

回调获取Function * ,然后调用

	Function *cb = (Function *)result_info->callback_data_;
	Local<Value> argv[] = {
		*Undefined(),
	};
	const unsigned argc = sizeof(argv) / sizeof(argv[0]);
	assert(cb != NULL);
	cb->Call(Context::GetCurrent()->Global(), argc, argv);
	scope.Close(Undefined());

成功执行了一部分回调之后,crash了

PID 2008 received SIGSEGV for address: 0xb /vagrant/tx_1.0.9_tss_sdk/game-server/node_modules/segfault-handler/build/Release/segfault-handler.node(+0xfce)[0x7fc1e29bdfce] /lib/x86_64-linux-gnu/libpthread.so.0(+0xfcb0)[0x7fc1e2f8ecb0] node(_ZN2v88internal9Execution4CallENS0_6HandleINS0_6ObjectEEES4_iPS4_Pbb+0x114)[0x73cd14] node(_ZN2v88Function4CallENS_6HandleINS_6ObjectEEEiPNS1_INS_5ValueEEE+0x110)[0x6de340] /vagrant/tx_1.0.9_tss_sdk/game-server/app/addon/tss/build/Debug/tss.node(_Z34on_chat_judge_result_callback_procPK30TssSdkUicChatJudgeResultInfoV2+0x1d6)[0x7fc1e27b67f3] ./lib/libtss_sdk.so(_ZN12tss_sdk_impl20plugin_callback_procEPv+0x7a)[0x7fc1e22a289a] ./lib/libtss_sdk.so(_ZN12tss_sdk_impl19UicUserInputInfoMgr17expire_user_inputEv+0x184)[0x7fc1e22bd074] ./lib/libtss_sdk.so(_ZN12tss_sdk_impl15TssSdkUicPlugin4procEPv+0xe0)[0x7fc1e22ba550] ./lib/libtss_sdk.so(_ZN12tss_sdk_impl15TssSdkFramework4procEv+0x426)[0x7fc1e22a9376] /vagrant/tx_1.0.9_tss_sdk/game-server/app/addon/tss/build/Debug/tss.node(_ZN10TSSWrapper4ProcERKN2v89ArgumentsE+0x58)[0x7fc1e27b816c] [0x32d051ba2a57] [1] 2008 abort (core dumped) node test

目前排除了多线程的问题,所有的回调都是在主线程中被调用的。

2 回复

最近我也出现了这个问题,能请教下吗

@Alwayss 太久远了。。。后来发现还是自己代码写得有问题,指针越界导致的

回到顶部