Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

引擎Native代码中 , Node.h 文件 里 的 _padding 从未被使用. #18116

Closed
finscn opened this issue Jan 3, 2025 · 3 comments
Closed
Labels
Bug Needs Triage Needs to be assigned by the team

Comments

@finscn
Copy link
Contributor

finscn commented Jan 3, 2025

Cocos Creator version

3.8.4

System information

all

Issue description

uint8_t _padding{0}; // Uint8: 3

这里定义的这个 _padding, 无论是 原生c++ 环境, 还是 jsb ,还是js 中, 都没有被使用过.
应该是从 2.x 里遗留的老代码.

Relevant error log output

No response

Steps to reproduce

.

Minimal reproduction project

No response

@finscn finscn added Bug Needs Triage Needs to be assigned by the team labels Jan 3, 2025
@finscn
Copy link
Contributor Author

finscn commented Jan 3, 2025

它在 Node.cpp 中,

#define NODE_SHARED_MEMORY_BYTE_LENGTH (20)

里面被用来校验 共享内存的大小, 但是完全可以把它删掉, 然后用 _isStatic 来校验, 同时长度改为 19.

我看了 nodejsb.ts 中的代码

    // Uint8Array with 3 elements: activeInHierarchy, active, static
    this._sharedUint8Arr = new Uint8Array(sharedArrayBuffer, 16, 3);

它也没有去读取 _padding .

@finscn
Copy link
Contributor Author

finscn commented Jan 3, 2025

突然想起来 , 这个是不是本身就是 故意添加的冗余变量? 用来占位, 填补内存空白 , 从而确保共享内存是 偶数 ?

@minggo
Copy link
Contributor

minggo commented Jan 7, 2025

占位用的,确保 js 和 c++ 的内存布局一样。注释里有写。

@minggo minggo closed this as completed Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Needs to be assigned by the team
Projects
None yet
Development

No branches or pull requests

2 participants