From 6716fc8563aed57045fe92fd2ac242ae0d4e9cd4 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 6 Dec 2022 10:15:57 +0800 Subject: [PATCH] [native] Fix script errors if Material.getProperty returns null (#13665) --- cocos/asset/assets/material.jsb.ts | 7 ++----- native/cocos/bindings/manual/jsb_conversions.h | 6 +++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cocos/asset/assets/material.jsb.ts b/cocos/asset/assets/material.jsb.ts index 2a11660f37..3205fa8e5c 100644 --- a/cocos/asset/assets/material.jsb.ts +++ b/cocos/asset/assets/material.jsb.ts @@ -221,6 +221,8 @@ matProto.getProperty = function (name: string, passIdx?: number) { } return arr || val; + } else if (val === null || val === undefined) { + return null; } let ret; @@ -266,11 +268,6 @@ materialProto._ctor = function () { this._passes = []; this._registerPassesUpdatedListener(); - // _initializerDefineProperty(_this, "_effectAsset", _descriptor$d, _assertThisInitialized(_this)); - // _initializerDefineProperty(_this, "_techIdx", _descriptor2$9, _assertThisInitialized(_this)); - // _initializerDefineProperty(_this, "_defines", _descriptor3$7, _assertThisInitialized(_this)); - // _initializerDefineProperty(_this, "_states", _descriptor4$6, _assertThisInitialized(_this)); - // _initializerDefineProperty(_this, "_props", _descriptor5$4, _assertThisInitialized(_this)); this._isCtorCalled = true; }; diff --git a/native/cocos/bindings/manual/jsb_conversions.h b/native/cocos/bindings/manual/jsb_conversions.h index 62d0d21024..9663c39944 100644 --- a/native/cocos/bindings/manual/jsb_conversions.h +++ b/native/cocos/bindings/manual/jsb_conversions.h @@ -1075,7 +1075,11 @@ bool nativevalue_to_se(const ccstd::variant *from, se::Value &to, se::O template bool nativevalue_to_se(ccstd::variant *from, se::Value &to, se::Object *ctx) { // NOLINT - return nativevalue_to_se(*from, to, ctx); + if (from != nullptr) { + return nativevalue_to_se(*from, to, ctx); + } + to.setNull(); + return true; } template