From 59e620ccdfc853512edeb41b10ccec01c6ddafb0 Mon Sep 17 00:00:00 2001 From: Harini Malothu Date: Thu, 29 Jan 2026 20:56:18 +0530 Subject: [PATCH 1/7] Fix memoryStram getting unitialized --- .../Modules/ImageViewManagerModule.cpp | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp b/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp index bf403ea1e49..9877f53de9a 100644 --- a/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp +++ b/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp @@ -77,16 +77,18 @@ winrt::fire_and_forget GetImageSizeAsync( } #ifdef USE_FABRIC } else { - auto result = wicBitmapSourceFromStream(memoryStream); - if (!std::get>(result)) { - auto imagingFactory = std::get>(result); - auto wicBmpSource = std::get>(result); - UINT width, height; - if (SUCCEEDED(wicBmpSource->GetSize(&width, &height))) { - successCallback(width, height); - succeeded = true; + if (memoryStream) { // Added nullcheck to prevent app from crashing if value is uninitialized + auto result = wicBitmapSourceFromStream(memoryStream); + if (!std::get>(result)) { + auto imagingFactory = std::get>(result); + auto wicBmpSource = std::get>(result); + UINT width, height; + if (SUCCEEDED(wicBmpSource->GetSize(&width, &height))) { + successCallback(width, height); + succeeded = true; + } } - } + } } #endif // USE_FABRIC } catch (winrt::hresult_error const &) { From 7f72e7585a6ac590426d83978a48d8e297eaffa0 Mon Sep 17 00:00:00 2001 From: Harini Malothu Date: Fri, 30 Jan 2026 11:54:02 +0530 Subject: [PATCH 2/7] Change files --- ...ative-windows-24985449-1e83-4a43-b2d6-7d80594087e8.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/react-native-windows-24985449-1e83-4a43-b2d6-7d80594087e8.json diff --git a/change/react-native-windows-24985449-1e83-4a43-b2d6-7d80594087e8.json b/change/react-native-windows-24985449-1e83-4a43-b2d6-7d80594087e8.json new file mode 100644 index 00000000000..9a4c949540b --- /dev/null +++ b/change/react-native-windows-24985449-1e83-4a43-b2d6-7d80594087e8.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "Fix memoryStram getting unitialized", + "packageName": "react-native-windows", + "email": "hmalothu@microsoft.com", + "dependentChangeType": "none" +} From 2d972235b012279e6d54e58ab008f46098d07038 Mon Sep 17 00:00:00 2001 From: Harini Malothu Date: Fri, 30 Jan 2026 14:10:21 +0530 Subject: [PATCH 3/7] Fix GetImageSize to fetch local files --- vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp b/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp index 9877f53de9a..ac9a8012f04 100644 --- a/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp +++ b/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp @@ -56,9 +56,10 @@ winrt::fire_and_forget GetImageSizeAsync( winrt::hstring scheme{uri.SchemeName()}; bool needsDownload = (scheme == L"http") || (scheme == L"https"); bool inlineData = scheme == L"data"; + bool isLocalFile = (scheme == L"file") || (scheme == L"ms-appx") || (scheme == L"ms-appdata"); winrt::IRandomAccessStream memoryStream; - if (needsDownload) { + if (needsDownload || isLocalFile) { memoryStream = co_await GetImageStreamAsync(properties, source); } else if (inlineData) { memoryStream = co_await GetImageInlineDataAsync(source); From dac17ad275b25cd8203c7acd033b4d6b6c7b779d Mon Sep 17 00:00:00 2001 From: Harini Malothu Date: Fri, 30 Jan 2026 15:07:06 +0530 Subject: [PATCH 4/7] yarn:format --- .../Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp b/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp index ac9a8012f04..ea5813a1b7a 100644 --- a/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp +++ b/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp @@ -78,7 +78,7 @@ winrt::fire_and_forget GetImageSizeAsync( } #ifdef USE_FABRIC } else { - if (memoryStream) { // Added nullcheck to prevent app from crashing if value is uninitialized + if (memoryStream) { // Added nullcheck to prevent app from crashing if value is uninitialized auto result = wicBitmapSourceFromStream(memoryStream); if (!std::get>(result)) { auto imagingFactory = std::get>(result); @@ -89,7 +89,7 @@ winrt::fire_and_forget GetImageSizeAsync( succeeded = true; } } - } + } } #endif // USE_FABRIC } catch (winrt::hresult_error const &) { From 47be1ea9a80f57cf01eb36510f5c02a896cc0aa9 Mon Sep 17 00:00:00 2001 From: Harini Malothu Date: Mon, 2 Feb 2026 15:26:35 +0530 Subject: [PATCH 5/7] Make error handling better --- .../Modules/ImageViewManagerModule.cpp | 47 ++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp b/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp index ea5813a1b7a..005340003d6 100644 --- a/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp +++ b/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp @@ -30,20 +30,33 @@ using namespace xaml::Media::Imaging; namespace Microsoft::ReactNative { +static const char *ERROR_INVALID_URI = "E_INVALID_URI"; +static const char *ERROR_GET_SIZE_FAILURE = "E_GET_SIZE_FAILURE"; + winrt::fire_and_forget GetImageSizeAsync( const winrt::Microsoft::ReactNative::IReactPropertyBag &properties, std::string uriString, winrt::Microsoft::ReactNative::JSValue &&headers, Mso::Functor successCallback, - Mso::Functor errorCallback + Mso::Functor errorCallback #ifdef USE_FABRIC , bool useFabric #endif // USE_FABRIC ) { bool succeeded{false}; + const char *errorCode = ERROR_GET_SIZE_FAILURE; + std::string errorMessage; try { + // Validate URI is not empty + if (uriString.empty()) { + errorCode = ERROR_INVALID_URI; + errorMessage = "Cannot get the size of an image for an empty URI"; + errorCallback(errorCode, errorMessage); + co_return; + } + ReactImageSource source; source.uri = uriString; if (!headers.IsNull()) { @@ -92,11 +105,17 @@ winrt::fire_and_forget GetImageSizeAsync( } } #endif // USE_FABRIC - } catch (winrt::hresult_error const &) { + } catch (winrt::hresult_error const &e) { + errorMessage = "Failed to get image size: " + + Microsoft::Common::Unicode::Utf16ToUtf8(std::wstring(e.message())) + " for URI: " + uriString; } - if (!succeeded) - errorCallback(); + if (!succeeded) { + if (errorMessage.empty()) { + errorMessage = "Failed to get image size for URI: " + uriString; + } + errorCallback(errorCode, errorMessage); + } co_return; } @@ -115,7 +134,15 @@ void ImageLoader::getSize(std::string uri, React::ReactPromise{width, height}); }, - [result]() noexcept { result.Reject("Failed"); } + [context, result](const char *errorCode, std::string errorMessage) noexcept { + // Log to Metro console so developers see the actual error + context.CallJSFunction( + L"RCTLog", + L"logToConsole", + L"error", + Microsoft::Common::Unicode::Utf8ToUtf16("[" + std::string(errorCode) + "] " + errorMessage)); + result.Reject(React::ReactError{errorCode, errorMessage}); + } #ifdef USE_FABRIC , IsFabricEnabled(context.Properties().Handle()) @@ -140,7 +167,15 @@ void ImageLoader::getSizeWithHeaders( [result](double width, double height) noexcept { result.Resolve(Microsoft::ReactNativeSpecs::ImageLoaderIOSSpec_getSizeWithHeaders_returnType{width, height}); }, - [result]() noexcept { result.Reject("Failed"); } + [context, result](const char *errorCode, std::string errorMessage) noexcept { + // Log to Metro console so developers see the actual error + context.CallJSFunction( + L"RCTLog", + L"logToConsole", + L"error", + Microsoft::Common::Unicode::Utf8ToUtf16("[" + std::string(errorCode) + "] " + errorMessage)); + result.Reject(React::ReactError{errorCode, errorMessage}); + } #ifdef USE_FABRIC , IsFabricEnabled(context.Properties().Handle()) From f27ce03d93319263062315ba070e8ee3756fc242 Mon Sep 17 00:00:00 2001 From: Harini Malothu Date: Tue, 3 Feb 2026 14:54:29 +0530 Subject: [PATCH 6/7] yarn:format --- .../Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp b/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp index 005340003d6..5938b9f0978 100644 --- a/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp +++ b/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp @@ -106,8 +106,8 @@ winrt::fire_and_forget GetImageSizeAsync( } #endif // USE_FABRIC } catch (winrt::hresult_error const &e) { - errorMessage = "Failed to get image size: " + - Microsoft::Common::Unicode::Utf16ToUtf8(std::wstring(e.message())) + " for URI: " + uriString; + errorMessage = "Failed to get image size: " + Microsoft::Common::Unicode::Utf16ToUtf8(std::wstring(e.message())) + + " for URI: " + uriString; } if (!succeeded) { From 5aa28ac807dfae67f17febf376d71ae4045961be Mon Sep 17 00:00:00 2001 From: Harini Malothu Date: Tue, 3 Feb 2026 19:53:24 +0530 Subject: [PATCH 7/7] Remover error handling in metro --- .../Modules/ImageViewManagerModule.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp b/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp index 5938b9f0978..54e3695406b 100644 --- a/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp +++ b/vnext/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp @@ -134,13 +134,7 @@ void ImageLoader::getSize(std::string uri, React::ReactPromise{width, height}); }, - [context, result](const char *errorCode, std::string errorMessage) noexcept { - // Log to Metro console so developers see the actual error - context.CallJSFunction( - L"RCTLog", - L"logToConsole", - L"error", - Microsoft::Common::Unicode::Utf8ToUtf16("[" + std::string(errorCode) + "] " + errorMessage)); + [result](const char *errorCode, std::string errorMessage) noexcept { result.Reject(React::ReactError{errorCode, errorMessage}); } #ifdef USE_FABRIC @@ -167,13 +161,7 @@ void ImageLoader::getSizeWithHeaders( [result](double width, double height) noexcept { result.Resolve(Microsoft::ReactNativeSpecs::ImageLoaderIOSSpec_getSizeWithHeaders_returnType{width, height}); }, - [context, result](const char *errorCode, std::string errorMessage) noexcept { - // Log to Metro console so developers see the actual error - context.CallJSFunction( - L"RCTLog", - L"logToConsole", - L"error", - Microsoft::Common::Unicode::Utf8ToUtf16("[" + std::string(errorCode) + "] " + errorMessage)); + [result](const char *errorCode, std::string errorMessage) noexcept { result.Reject(React::ReactError{errorCode, errorMessage}); } #ifdef USE_FABRIC