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

fix TypedArray set #17817

Merged
merged 2 commits into from
Nov 11, 2024
Merged

fix TypedArray set #17817

merged 2 commits into from
Nov 11, 2024

Conversation

sablib
Copy link
Contributor

@sablib sablib commented Nov 6, 2024

It should follow the spec and behave the same with TypedArray in Typescript.

Re: #

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

Copy link

github-actions bot commented Nov 6, 2024

✅ Package size is not changed

Interface Check Report

This pull request does not change any public interfaces !

@minggo minggo requested a review from dumganhar November 7, 2024 01:24
CC_ASSERT(_buffer);
memcpy(_buffer->_data + offset, buffer->_data, buffer->byteLength());
memcpy(_buffer->_data + _byteOffset + offset * BYTES_PER_ELEMENT, buffer->_data, buffer->byteLength());
Copy link
Contributor

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]);
    }
}

Copy link
Contributor Author

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.

@dumganhar
Copy link
Contributor

@cocos-robot run test cases

@dumganhar
Copy link
Contributor

@cocos-robot run test cases

1 similar comment
@dumganhar
Copy link
Contributor

@cocos-robot run test cases

Copy link

@sablib, Please check the result of run test cases:

Task Details

Copy link

@sablib, Please check the result of run test cases:

Task Details

@minggo minggo merged commit 8339a8f into cocos:v3.8.5 Nov 11, 2024
25 checks passed
qiuguohua pushed a commit to qiuguohua/cocos-engine that referenced this pull request Nov 26, 2024
* fix TypedArray set

* Fix TypedArrayTemp::set function templates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants