Skip to content

Commit d2aa3b3

Browse files
authored
fix(📏): crash on initial view size request, avoid negative size values (#3359)
1 parent 9bc42b3 commit d2aa3b3

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

‎packages/skia/cpp/jsi/JsiHostObject.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
* Creates a JSI export function declaration
4848
*/
4949
#define JSI_EXPORT_FUNC(CLASS, FUNCTION) \
50-
{#FUNCTION, (jsi::Value(JsiHostObject::*)( \
50+
{#FUNCTION, (jsi::Value (JsiHostObject::*)( \
5151
jsi::Runtime & runtime, const jsi::Value &thisValue, \
5252
const jsi::Value *arguments, size_t)) & \
5353
CLASS::FUNCTION}
@@ -65,7 +65,7 @@
6565
* Creates a JSI export getter declaration
6666
*/
6767
#define JSI_EXPORT_PROP_GET(CLASS, FUNCTION) \
68-
{#FUNCTION, (jsi::Value(JsiHostObject::*)(jsi::Runtime & runtime)) & \
68+
{#FUNCTION, (jsi::Value (JsiHostObject::*)(jsi::Runtime & runtime)) & \
6969
CLASS::STR_CAT(STR_GET, FUNCTION)}
7070

7171
/**
@@ -83,7 +83,7 @@
8383
*/
8484
#define JSI_EXPORT_PROP_SET(CLASS, FUNCTION) \
8585
{#FUNCTION, \
86-
(void(JsiHostObject::*)(jsi::Runtime & runtime, const jsi::Value &)) & \
86+
(void (JsiHostObject::*)(jsi::Runtime & runtime, const jsi::Value &)) & \
8787
CLASS::STR_CAT(STR_SET, FUNCTION)}
8888

8989
/**

‎packages/skia/cpp/rnskia/RNSkJsiViewApi.h‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,15 @@ class RNSkJsiViewApi : public RNJsi::JsiHostObject,
105105
if (name == "onSize" && isSharedValue(runtime, arguments[2])) {
106106
jsi::Object size(runtime);
107107
auto pd = _platformContext->getPixelDensity();
108-
size.setProperty(runtime, "width",
109-
info->view->getScaledWidth() / pd);
110-
size.setProperty(runtime, "height",
111-
info->view->getScaledHeight() / pd);
108+
auto w = info->view != nullptr
109+
? std::max(info->view->getScaledWidth(), 0)
110+
: 0;
111+
auto h = info->view != nullptr
112+
? std::max(info->view->getScaledHeight(), 0)
113+
: 0;
114+
115+
size.setProperty(runtime, "width", w / pd);
116+
size.setProperty(runtime, "height", h / pd);
112117
arguments[2].asObject(runtime).setProperty(runtime, "value", size);
113118
} else {
114119
info->props.insert_or_assign(

0 commit comments

Comments
 (0)