From 678f1c449048ac96558f112d8cb62fcc925a1a1f Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Tue, 17 Mar 2020 13:53:21 -0700 Subject: [PATCH] Fix crash in slider with custom image Summary: Changelog: [Internal] # Why was it crashing? Crash was caused by `data.getTrackImageRequest()` returning NULL. The crash happened inside `getCoordinator` method. If you look at the implementation of the method below ``` if (request) { return &request->getObserverCoordinator(); } else { return nullptr; } ``` you might notice that we check for NULL, why is it crashing then? And why is it only crashing in production? The reason is compiler's optimiser, which looks at `data.getTrackImageRequest()`, this method returns `ImageRequest const &` and sees that this method will always return a value, never NULL. Compiler then looks at our `getCoordinator` function, sees that we check there for nullity but since it can never be null, removes that branch. # Solution Create new SliderState with non null image observer. Reviewed By: shergin Differential Revision: D20491367 fbshipit-source-id: 17b7cf31feabbe6f8ece324a3d329902b2ef6a2d --- .../fabric/components/slider/SliderShadowNode.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ReactCommon/fabric/components/slider/SliderShadowNode.h b/ReactCommon/fabric/components/slider/SliderShadowNode.h index dc44d5c96b1..f4b9c334fad 100644 --- a/ReactCommon/fabric/components/slider/SliderShadowNode.h +++ b/ReactCommon/fabric/components/slider/SliderShadowNode.h @@ -38,6 +38,21 @@ class SliderShadowNode final : public ConcreteViewShadowNode< void setSliderMeasurementsManager( const std::shared_ptr &measurementsManager); + static SliderState initialStateData( + ShadowNodeFragment const &fragment, + SurfaceId const surfaceId, + ComponentDescriptor const &componentDescriptor) { + auto imageSource = ImageSource{ImageSource::Type::Invalid}; + return {imageSource, + {imageSource, nullptr}, + imageSource, + {imageSource, nullptr}, + imageSource, + {imageSource, nullptr}, + imageSource, + {imageSource, nullptr}}; + } + #pragma mark - LayoutableShadowNode Size measure(LayoutConstraints layoutConstraints) const override;