-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix TypedArray set #17817
fix TypedArray set #17817
Conversation
✅ Package size is not changedInterface Check ReportThis pull request does not change any public interfaces ! |
CC_ASSERT(_buffer); | ||
memcpy(_buffer->_data + offset, buffer->_data, buffer->byteLength()); | ||
memcpy(_buffer->_data + _byteOffset + offset * BYTES_PER_ELEMENT, buffer->_data, buffer->byteLength()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
In this case, I think another two set methods should also consider the current _byteOffset
while copying data.
template <typename T>
template <typename SrcType>
typename std::enable_if_t<std::is_same<T, SrcType>::value, void> TypedArrayTemp<T>::set(const TypedArrayTemp<SrcType> &array, uint32_t offset) {
CC_ASSERT(_buffer);
uint32_t dstByteOffset = offset * BYTES_PER_ELEMENT;
uint32_t srcByteOffset = array.byteOffset();
uint32_t srcCount = array.length();
CC_ASSERT(dstByteOffset + srcCount * TypedArrayTemp<SrcType>::BYTES_PER_ELEMENT <= _byteEndPos);
memcpy(_buffer->_data + dstByteOffset, array._buffer->_data + srcByteOffset, array.byteLength());
}
template <typename T>
template <typename SrcType>
typename std::enable_if_t<!std::is_same<T, SrcType>::value, void> TypedArrayTemp<T>::set(const TypedArrayTemp<SrcType> &array, uint32_t offset) {
CC_ASSERT(_buffer);
uint32_t dstByteOffset = offset * BYTES_PER_ELEMENT;
uint32_t srcByteOffset = array.byteOffset();
uint32_t srcCount = array.length();
uint32_t remainCount = (_byteEndPos - dstByteOffset) / BYTES_PER_ELEMENT;
CC_ASSERT_LE(srcCount, remainCount);
for (uint32_t i = 0; i < srcCount; ++i) {
(*this)[offset + i] = reinterpret_cast<T>(array[i]);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a commit to fix these function templates.
@cocos-robot run test cases |
@cocos-robot run test cases |
1 similar comment
@cocos-robot run test cases |
@sablib, Please check the result of
Task Details |
@sablib, Please check the result of
Task Details |
* fix TypedArray set * Fix TypedArrayTemp::set function templates
It should follow the spec and behave the same with TypedArray in Typescript.
Re: #
Changelog
Continuous Integration
This pull request:
Compatibility Check
This pull request: