mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add a way to simulate memory access to ImageProps in LayoutAnimations
Summary: changelog: [internal] I'm chasing down a crash in LayoutAnimations, it would help me to simulate the memory access which causes the crash to learn where the bad memory is coming from. Reviewed By: RSNara Differential Revision: D30776840 fbshipit-source-id: 1e97fac28ba2df37ba3e47ec2c110043c3823e70
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c6e203bdb0
commit
d2cc91bcc3
@@ -130,6 +130,9 @@ class LayoutAnimationDelegateProxy : public LayoutAnimationStatusDelegate, publi
|
||||
if (reactNativeConfig->getBool("react_fabric:enable_crash_on_missing_component_descriptor")) {
|
||||
_animationDriver->enableCrashOnMissingComponentDescriptor();
|
||||
}
|
||||
if (reactNativeConfig->getBool("react_fabric:enable_simulate_image_props_memory_access")) {
|
||||
_animationDriver->enableSimulateImagePropsMemoryAccess();
|
||||
}
|
||||
_uiRunLoopObserver =
|
||||
toolbox.mainRunLoopObserverFactory(RunLoopObserver::Activity::BeforeWaiting, _layoutAnimationDelegateProxy);
|
||||
_uiRunLoopObserver->setDelegate(_layoutAnimationDelegateProxy.get());
|
||||
|
||||
@@ -62,6 +62,7 @@ rn_xplat_cxx_library(
|
||||
react_native_xplat_target("react/debug:debug"),
|
||||
react_native_xplat_target("react/renderer/componentregistry:componentregistry"),
|
||||
react_native_xplat_target("react/renderer/components/view:view"),
|
||||
react_native_xplat_target("react/renderer/components/image:image"),
|
||||
react_native_xplat_target("react/renderer/core:core"),
|
||||
react_native_xplat_target("react/renderer/debug:debug"),
|
||||
react_native_xplat_target("react/renderer/mounting:mounting"),
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <react/renderer/animations/conversions.h>
|
||||
#include <react/renderer/animations/utils.h>
|
||||
#include <react/renderer/componentregistry/ComponentDescriptorFactory.h>
|
||||
#include <react/renderer/components/image/ImageProps.h>
|
||||
#include <react/renderer/components/view/ViewProps.h>
|
||||
#include <react/renderer/core/ComponentDescriptor.h>
|
||||
#include <react/renderer/core/LayoutMetrics.h>
|
||||
@@ -174,6 +175,7 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
||||
MountingTransaction::Number transactionNumber,
|
||||
TransactionTelemetry const &telemetry,
|
||||
ShadowViewMutationList mutations) const {
|
||||
simulateImagePropsMemoryAccess(mutations);
|
||||
// Current time in milliseconds
|
||||
uint64_t now = now_();
|
||||
|
||||
@@ -1058,6 +1060,8 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
||||
}
|
||||
}
|
||||
|
||||
simulateImagePropsMemoryAccess(mutations);
|
||||
|
||||
return MountingTransaction{
|
||||
surfaceId, transactionNumber, std::move(mutations), telemetry};
|
||||
}
|
||||
@@ -1086,6 +1090,10 @@ void LayoutAnimationKeyFrameManager::enableCrashOnMissingComponentDescriptor() {
|
||||
crashOnMissingComponentDescriptor_ = true;
|
||||
}
|
||||
|
||||
void LayoutAnimationKeyFrameManager::enableSimulateImagePropsMemoryAccess() {
|
||||
simulateImagePropsMemoryAccess_ = true;
|
||||
}
|
||||
|
||||
#pragma mark - Protected
|
||||
|
||||
bool LayoutAnimationKeyFrameManager::hasComponentDescriptorForShadowView(
|
||||
@@ -1696,5 +1704,40 @@ void LayoutAnimationKeyFrameManager::deleteAnimationsForStoppedSurfaces()
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutAnimationKeyFrameManager::simulateImagePropsMemoryAccess(
|
||||
ShadowViewMutationList const &mutations) const {
|
||||
if (!simulateImagePropsMemoryAccess_) {
|
||||
return;
|
||||
}
|
||||
for (auto const &mutation : mutations) {
|
||||
if (mutation.type != ShadowViewMutation::Type::Insert) {
|
||||
continue;
|
||||
}
|
||||
if (strcmp(mutation.newChildShadowView.componentName, "Image") == 0) {
|
||||
auto const &imageProps = *std::static_pointer_cast<ImageProps const>(
|
||||
mutation.newChildShadowView.props);
|
||||
int temp = 0;
|
||||
switch (imageProps.resizeMode) {
|
||||
case ImageResizeMode::Cover:
|
||||
temp = 1;
|
||||
break;
|
||||
case ImageResizeMode::Contain:
|
||||
temp = 2;
|
||||
break;
|
||||
case ImageResizeMode::Stretch:
|
||||
temp = 3;
|
||||
break;
|
||||
case ImageResizeMode::Center:
|
||||
temp = 4;
|
||||
break;
|
||||
case ImageResizeMode::Repeat:
|
||||
temp = 5;
|
||||
break;
|
||||
}
|
||||
(void)temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
@@ -90,6 +90,8 @@ class LayoutAnimationKeyFrameManager : public UIManagerAnimationDelegate,
|
||||
|
||||
void enableCrashOnMissingComponentDescriptor();
|
||||
|
||||
void enableSimulateImagePropsMemoryAccess();
|
||||
|
||||
protected:
|
||||
SharedComponentDescriptorRegistry componentDescriptorRegistry_;
|
||||
mutable better::optional<LayoutAnimation> currentAnimation_{};
|
||||
@@ -157,6 +159,12 @@ class LayoutAnimationKeyFrameManager : public UIManagerAnimationDelegate,
|
||||
*/
|
||||
bool crashOnMissingComponentDescriptor_{false};
|
||||
|
||||
/*
|
||||
* Feature flag that enables simulation of memory access. This is a temporary
|
||||
* flag to diagnose where crashes are coming from in LayoutAnimations on iOS.
|
||||
*/
|
||||
bool simulateImagePropsMemoryAccess_{false};
|
||||
|
||||
// Function that returns current time in milliseconds
|
||||
std::function<uint64_t()> now_;
|
||||
|
||||
@@ -180,6 +188,9 @@ class LayoutAnimationKeyFrameManager : public UIManagerAnimationDelegate,
|
||||
* Removes animations from `inflightAnimations_` for stopped surfaces.
|
||||
*/
|
||||
void deleteAnimationsForStoppedSurfaces() const;
|
||||
|
||||
void simulateImagePropsMemoryAccess(
|
||||
ShadowViewMutationList const &mutations) const;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
|
||||
Reference in New Issue
Block a user