Skip to content

Commit

Permalink
fix oh some crash on 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
oahcy committed Sep 6, 2022
1 parent 0a58f4b commit 197824b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
12 changes: 12 additions & 0 deletions native/cocos/bindings/jswrapper/napi/Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ Class *Class::create(const std::string &clsName, se::Object *parent, Object *par
return cls;
}

Class* Class::create(const std::initializer_list<const char *> &classPath, se::Object *parent, Object *parentProto, napi_callback ctor) {
se::AutoHandleScope scope;
se::Object *currentParent = parent;
se::Value tmp;
for (auto i = 0; i < classPath.size() - 1; i++) {
bool ok = currentParent->getProperty(*(classPath.begin() + i), &tmp);
CC_ASSERT(ok); // class or namespace in path is not defined
currentParent = tmp.toObject();
}
return create(*(classPath.end() - 1), currentParent, parentProto, ctor);
}

bool Class::init(const std::string &clsName, Object *parent, Object *parentProto, napi_callback ctor) {
_name = clsName;
_parent = parent;
Expand Down
1 change: 1 addition & 0 deletions native/cocos/bindings/jswrapper/napi/Class.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace se {
class Class {
public:
static Class *create(const std::string &clsName, se::Object *parent, Object *parentProto, napi_callback ctor = nullptr);
static Class *create(const std::initializer_list<const char *> &classPath, se::Object *parent, Object *parentProto, napi_callback ctor = nullptr);
static napi_value _createJSObjectWithClass(Class *cls);
void defineProperty(const char* name, napi_callback g, napi_callback s);
void defineProperty(const std::initializer_list<const char *> &names, napi_callback g, napi_callback s);
Expand Down
4 changes: 2 additions & 2 deletions native/cocos/bindings/jswrapper/napi/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,10 @@ void Object::setPrivateObject(PrivateObjectBase* data) {
assert(NativePtrToObjectMap::find(data->getRaw()) == NativePtrToObjectMap::end());

napi_status status;
_privateData = data->getRaw();
if (data) {
_privateData = data->getRaw();
_privateObject = data;
NativePtrToObjectMap::emplace(_privateObject, this);
NativePtrToObjectMap::emplace(_privateData, this);
}

//issue https://github.com/nodejs/node/issues/23999
Expand Down
4 changes: 3 additions & 1 deletion native/cocos/platform/openharmony/FileUtils-OpenHarmony.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ FileUtils *createFileUtils() {
return ccnew FileUtilsOpenHarmony();
}

std::string FileUtilsOpenHarmony::_ohWritablePath;

bool FileUtilsOpenHarmony::initResourceManager(napi_env env, napi_value param) {
_nativeResourceManager = OH_ResourceManager_InitNativeResourceManager(env, param);
return true;
Expand Down Expand Up @@ -173,7 +175,7 @@ long FileUtilsOpenHarmony::getFileSize(const std::string &filepath) {
}

std::string FileUtilsOpenHarmony::getWritablePath() const {
return _writablePath;
return _ohWritablePath;
}

bool FileUtilsOpenHarmony::isFileExistInternal(const std::string &strFilePath) const {
Expand Down
3 changes: 3 additions & 0 deletions native/cocos/platform/openharmony/FileUtils-OpenHarmony.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class CC_DLL FileUtilsOpenHarmony : public FileUtils {
bool renameFile(const std::string &oldfullpath, const std::string &newfullpath) override;
bool removeFile(const std::string &filepath) override;
bool removeDirectory(const std::string &dirPath) override;

static std::string _ohWritablePath;

private:
bool isFileExistInternal(const std::string &strFilePath) const override;

Expand Down
2 changes: 1 addition & 1 deletion native/cocos/platform/openharmony/napi/NapiHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ napi_value NapiHelper::napiWritablePathInit(napi_env env, napi_callback_info inf
char buffer[kMaxStringLen];
size_t result = 0;
NODE_API_CALL(status, env, napi_get_value_string_utf8(env, args[0], buffer, kMaxStringLen, &result));
FileUtils::getInstance()->setWritablePath(std::string(buffer));
FileUtilsOpenHarmony::_ohWritablePath = std::string(buffer);
return nullptr;
}

Expand Down

0 comments on commit 197824b

Please sign in to comment.