HarmonyOS 鸿蒙Next RN涉及到Scroll相关的操作报NULL pointer dereference
HarmonyOS 鸿蒙Next RN涉及到Scroll相关的操作报NULL pointer dereference
涉及到Scroll相关的操作都会报错,具体原因是什么
比如FlatList组件的ScorllToIndex
错误日志如下:
#00 pc 00000000000fe9d4 /data/storage/el1/bundle/libs/arm64/libreact_render_core.so(std::__n1::weak_ptr<facebook::react::EventDispatcher const>::lock() const+68)(b5aec214b1a7d0ef0d56b4e33d168497c23e4504)
#01 pc 00000000000fe644 /data/storage/el1/bundle/libs/arm64/libreact_render_core.so(facebook::react::EventEmitter::dispatchUniqueEvent(std::__n1::basic_string<char, std::__n1::char_traits<char>, std::__n1::allocator<char>>, std::__n1::function<facebook::jsi::Value (facebook::jsi::Runtime&)> const&) const+84)(b5aec214b1a7d0ef0d56b4e33d168497c23e4504)
#02 pc 00000000000bc2a8 /data/storage/el1/bundle/libs/arm64/librrc_scrollview.so(facebook::react::ScrollViewEventEmitter::onScroll(facebook::react::ScrollViewMetrics const&) const+108)(05f74819c4fec560b178fb3e300b62d7f2747108)
#03 pc 00000000008defc8 /data/storage/el1/bundle/libs/arm64/librnoh.so(rnoh::ScrollViewComponentInstance::onScroll()+1012)(f00c547df8972f250e12a8f65dc68022edaa3522)
#04 pc 000000000088345c /data/storage/el1/bundle/libs/arm64/librnoh.so(rnoh::ScrollNode::onNodeEvent(ArkUI_NodeEventType, ArkUI_NumberValue (&) [12])+100)(f00c547df8972f250e12a8f65dc68022edaa3522)
#05 pc 0000000000874740 /data/storage/el1/bundle/libs/arm64/librnoh.so(rnoh::ArkUINodeRegistry::receiveEvent(ArkUI_NodeEvent*)+956)(f00c547df8972f250e12a8f65dc68022edaa3522)
#06 pc 0000000000874910 /data/storage/el1/bundle/libs/arm64/librnoh.so(f00c547df8972f250e12a8f65dc68022edaa3522)
#07 pc 00000000008748e4 /data/storage/el1/bundle/libs/arm64/librnoh.so(f00c547df8972f250e12a8f65dc68022edaa3522)
#08 pc 000000000003c9e4 /system/lib64/libace_ndk.z.so(OHOS::Ace::NodeModel::HandleInnerNodeEvent(ArkUINodeEvent*)+540)(cb1df2f8b80607b8837ba83303ed5e40)
#09 pc 0000000002443410 /system/lib64/platformsdk/libace_compatible.z.so(4b8356ffcdcab8d44a2498a848a16004)
#10 pc 0000000000933320 /system/lib64/platformsdk/libace_compatible.z.so(OHOS::Ace::NG::ScrollPattern::HandleScrollPosition(float)+792)(4b8356ffcdcab8d44a2498a848a16004)
#11 pc 000000000093271c /system/lib64/platformsdk/libace_compatible.z.so(OHOS::Ace::NG::ScrollPattern::UpdateCurrentOffset(float, int)+516)(4b8356ffcdcab8d44a2498a848a16004)
#12 pc 0000000000bd2878 /system/lib64/platformsdk/libace_compatible.z.so(OHOS::Ace::NG::ScrollPattern::JumpToPosition(float, int)+72)(4b8356ffcdcab8d44a2498a848a16004)
#13 pc 0000000000e5d8b0 /system/lib64/platformsdk/libace_compatible.z.so(OHOS::Ace::NG::ScrollableController::AnimateTo(OHOS::Ace::Dimension const&, float, OHOS::Ace::RefPtr<OHOS::Ace::Curve> const&, bool, bool)+292)(4b8356ffcdcab8d44a2498a848a16004)
#14 pc 0000000000ca9ba4 /system/lib64/platformsdk/libace_compatible.z.so(OHOS::Ace::NG::(anonymous namespace)::SetScrollTo(_ArkUINode*, float const (*) [8])+324)(4b8356ffcdcab8d44a2498a848a16004)
#15 pc 000000000006131c /system/lib64/libace_ndk.z.so(OHOS::Ace::NodeModel::(anonymous namespace)::SetScrollTo(ArkUI_Node*, ArkUI_AttributeItem const*)+212)(cb1df2f8b80607b8837ba83303ed5e40)
#16 pc 0000000000041cfc /system/lib64/libace_ndk.z.so(OHOS::Ace::NodeModel::SetNodeAttribute(ArkUI_Node*, ArkUI_NodeAttributeType, ArkUI_AttributeItem const*)+336)(cb1df2f8b80607b8837ba83303ed5e40)
#17 pc 0000000000883fdc /data/storage/el1/bundle/libs/arm64/librnoh.so(rnoh::ScrollNode::scrollTo(float, float, bool, bool)+208)(f00c547df8972f250e12a8f65dc68022edaa3522)
#18 pc 00000000008ddfc0 /data/storage/el1/bundle/libs/arm64/librnoh.so(rnoh::ScrollViewComponentInstance::onCommandReceived(std::__n1::basic_string<char, std::__n1::char_traits<char>, std::__n1::allocator<char>> const&, folly::dynamic const&)+248)(f00c547df8972f250e12a8f65dc68022edaa3522)
#19 pc 0000000000075da4 /data/storage/el1/bundle/libs/arm64/librnoh_safe_area.so(rnoh::ComponentInstance::handleCommand(std::__n1::basic_string<char, std::__n1::char_traits<char>, std::__n1::allocator<char>> const&, folly::dynamic const&)+44)(4d1d339fd31ae10dac33e58ff805755fd206e9f0)
#20 pc 000000000074555c /data/storage/el1/bundle/libs/arm64/librnoh.so(rnoh::MountingManagerCAPI::dispatchCommand(facebook::react::ShadowView const&, std::__n1::basic_string<char, std::__n1::char_traits<char>, std::__n1::allocator<char>> const&, folly::dynamic const&)+272)(f00c547df8972f250e12a8f65dc68022edaa3522)
#21 pc 000000000070eb80 /data/storage/el1/bundle/libs/arm64/librnoh.so(f00c547df8972f250e12a8f65dc68022edaa3522)
#22 pc 000000000070eadc /data/storage/el1/bundle/libs/arm64/librnoh.so(f00c547df8972f250e12a8f65dc68022edaa3522)
#23 pc 000000000070ea7c /data/storage/el1/bundle/libs/arm64/librnoh.so(f00c547df8972f250e12a8f65dc68022edaa3522)
#24 pc 000000000070ea34 /data/storage/el1/bundle/libs/arm64/librnoh.so(f00c547df8972f250e12a8f65dc68022edaa3522)
#25 pc 000000000070ea10 /data/storage/el1/bundle/libs/arm64/librnoh.so(f00c547df8972f250e12a8f65dc68022edaa3522)
#26 pc 000000000070d954 /data/storage/el1/bundle/libs/arm64/librnoh.so(f00c547df8972f250e12a8f65dc68022edaa3522)
#27 pc 0000000000693fac /data/storage/el1/bundle/libs/arm64/librnoh.so(f00c547df8972f250e12a8f65dc68022edaa3522)
#28 pc 0000000000693ab4 /data/storage/el1/bundle/libs/arm64/librnoh.so(std::__n1::function<void ()>::operator()() const+20)(f00c547df8972f250e12a8f65dc68022edaa3522)
#29 pc 00000000007d23e0 /data/storage/el1/bundle/libs/arm64/librnoh.so(f00c547df8972f250e12a8f65dc68022edaa3522)
#30 pc 00000000007d2288 /data/storage/el1/bundle/libs/arm64/librnoh.so(f00c547df8972f250e12a8f65dc68022edaa3522)
#31 pc 0000000000018604 /system/lib64/platformsdk/libuv.so(uv__async_io+352)(5f790fb316eb9bac96ca66d8eca48d30)
#32 pc 0000000000017c50 /system/lib64/platformsdk/libuv.so(uv__io_poll+1268)(5f790fb316eb9bac96ca66d8eca48d30)
#33 pc 0000000000018b08 /system/lib64/platformsdk/libuv.so(uv_run+376)(5f790fb316eb9bac96ca66d8eca48d30)
#34 pc 000000000007c29c /system/lib64/platformsdk/libruntime.z.so(OHOS::AbilityRuntime::OHOSLoopHandler::OnTriggered()+148)(a4be54e800873da29696cd72b0505773)
#35 pc 000000000001ef14 /system/lib64/chipset-pub-sdk/libeventhandler.z.so(5b610a33e39b58ae2ccb96b0fed12b99)
#36 pc 000000000001ad8c /system/lib64/chipset-pub-sdk/libeventhandler.z.so(OHOS::AppExecFwk::EventHandler::DistributeEvent(std::__h::unique_ptr<OHOS::AppExecFwk::InnerEvent, void ()(OHOS::AppExecFwk::InnerEvent)> const&)+1164)(5b610a33e39b58ae2ccb96b0fed12b99)
#37 pc 000000000002b580 /system/lib64/chipset-pub-sdk/libeventhandler.z.so(OHOS::AppExecFwk::(anonymous namespace)::EventRunnerImpl::ExecuteEventHandler(std::__h::unique_ptr<OHOS::AppExecFwk::InnerEvent, void ()(OHOS::AppExecFwk::InnerEvent)>&)+348)(5b610a33e39b58ae2ccb96b0fed12b99)
#38 pc 000000000002ae58 /system/lib64/chipset-pub-sdk/libeventhandler.z.so(OHOS::AppExecFwk::(anonymous namespace)::EventRunnerImpl::Run()+880)(5b610a33e39b58ae2ccb96b0fed12b99)
#39 pc 000000000002e1f8 /system/lib64/chipset-pub-sdk/libeventhandler.z.so(OHOS::AppExecFwk::EventRunner::Run()+524)(5b610a33e39b58ae2ccb96b0fed12b99)
#40 pc 00000000000b1f30 /system/lib64/platformsdk/libappkit_native.z.so(OHOS::AppExecFwk::MainThread::Start()+408)(dd3bcc89404170f10e8912c11fce2aea)
#41 pc 0000000000004d18 /system/lib64/appspawn/appspawn/libappspawn_ace.z.so(RunChildProcessor(AppSpawnContent, AppSpawnClient)+560)(02c332fa9d20d29ca437e316b2f319ab)
#42 pc 000000000000a4a4 /system/bin/appspawn(AppSpawnChild+484)(edb108369d5d48874ff5088abd82af61)
#43 pc 000000000000a194 /system/bin/appspawn(AppSpawnProcessMsg+688)(edb108369d5
更多关于HarmonyOS 鸿蒙Next RN涉及到Scroll相关的操作报NULL pointer dereference的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
因为某些组件在渲染或操作时未能正确获取到所需的引用或数据。根据提供的错误日志和上下文,以下是一些可能的原因和解决方案:
1.如果你在FlatList中使用了scrollToIndex,确保在调用此方法之前,数据源(data)已经完全加载并且存在。
2.确保你在调用scrollToIndex前,FlatList和相关的Scroll组件已经正确初始化。
3.检查ScrollView或FlatList的事件监听设置,确保所有回调函数都能正常工作。
参考以下demo:
const flatListRef = useRef(null);
const data = []; // 确保这里是加载好的数据
useEffect(() => {
if (data.length > 0) {
flatListRef.current.scrollToIndex({ index: 0, animated: true });
}
}, [data]);
return (
<FlatList
ref={flatListRef}
data={data}
renderItem={({ item }) => <ItemComponent item={item} />}
keyExtractor={item => item.id}
/>
);
更多关于HarmonyOS 鸿蒙Next RN涉及到Scroll相关的操作报NULL pointer dereference的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
HarmonyOS 鸿蒙Next RN在涉及到Scroll相关的操作时报告NULL pointer dereference错误,通常是因为尝试访问或操作了一个未初始化或已被释放的指针。在鸿蒙系统中,RN(React Native)框架的Scroll组件若未正确初始化或绑定,可能引发此类异常。
具体原因可能包括但不限于:
- Scroll组件的引用在使用前未正确设置或已被置空。
- 传递给Scroll组件的回调函数或参数中存在空指针。
- 在组件的生命周期中,Scroll相关操作(如设置滚动位置)在组件未完全挂载或已卸载时执行。
解决方法通常涉及检查Scroll组件及其相关操作的生命周期管理,确保所有操作都在组件有效且已正确初始化的情况下进行。同时,验证所有传递给Scroll组件的回调和数据均为非空且有效。
此外,确保在组件销毁前清理所有相关资源,避免悬挂指针。检查相关代码,确保Scroll组件的使用遵循鸿蒙RN框架的最佳实践。
如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html