Skip to content

Commit

Permalink
fix sevalue_to_native function support JSBNativeDataHolder convert (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
xbpiao authored Nov 15, 2023
1 parent e50f378 commit 330b92a
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions native/cocos/bindings/manual/jsb_conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "bindings/jswrapper/SeApi.h"
#include "bindings/manual/jsb_classtype.h"
#include "jsb_conversions_spec.h"
#include "core/data/JSBNativeDataHolder.h"

#if CC_USE_SPINE
#include "cocos/editor-support/spine-creator-support/spine-cocos2dx.h"
Expand Down Expand Up @@ -723,6 +724,10 @@ sevalue_to_native(const se::Value &from, T **to, se::Object * /*ctx*/) { // NOLI
return true;
}

// duplicate extern to resolve the circular reference jsb_cocos_auto.h
// see jsb_cocos_auto.h
extern se::Class *__jsb_cc_JSBNativeDataHolder_class; // NOLINT

template <typename T>
typename std::enable_if_t<!std::is_pointer<T>::value && std::is_arithmetic<T>::value, bool>
sevalue_to_native(const se::Value &from, T **to, se::Object * /*ctx*/) { // NOLINT(readability-identifier-naming)
Expand All @@ -733,8 +738,19 @@ sevalue_to_native(const se::Value &from, T **to, se::Object * /*ctx*/) { // NOLI
} else if (data->isTypedArray()) {
data->getTypedArrayData(&tmp, nullptr);
} else {
CC_ABORT(); // bad type
return false;
void *privateData = data->getPrivateData();
if (privateData != nullptr && data->_getClass() == __jsb_cc_JSBNativeDataHolder_class) {
auto *dataHolder = static_cast<cc::JSBNativeDataHolder *>(privateData);
if (dataHolder != nullptr) {
tmp = dataHolder->getData();
} else {
CC_ABORT(); // bad type
return false;
}
} else {
CC_ABORT(); // bad type
return false;
}
}
*to = reinterpret_cast<T *>(tmp);
return true;
Expand Down

0 comments on commit 330b92a

Please sign in to comment.