Skip to content

Commit

Permalink
Fix issues on native platforms. (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar authored and shrinktofit committed Aug 1, 2023
1 parent 2041cdf commit 13ea8d7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 22 deletions.
7 changes: 7 additions & 0 deletions cocos/asset/assets/buffer-asset.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ declare const jsb: any;
export type BufferAsset = JsbBufferAsset;
export const BufferAsset: typeof JsbBufferAsset = jsb.BufferAsset;

BufferAsset.prototype.buffer = function() {
if (!this._bufferLegacy) {
this._bufferLegacy = new Uint8Array(this.view);
}
return this._bufferLegacy;
};

cclegacy.BufferAsset = jsb.BufferAsset;

// handle meta data, it is generated automatically
Expand Down
3 changes: 1 addition & 2 deletions cocos/native-binding/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ interface cc_BufferAsset_Context_Args {
}
export function patch_cc_BufferAsset(ctx: cc_BufferAsset_Context_Args, apply = defaultExec) {
const { BufferAsset } = { ...ctx };
const _nativeAssetDescriptor = Object.getOwnPropertyDescriptor(BufferAsset.prototype, '_nativeAsset');
apply(() => { $.override(BufferAsset.prototype, '_nativeAsset', _nativeAssetDescriptor); }, 'override', '_nativeAsset');
apply(() => { $.serializable(BufferAsset.prototype, 'view', () => { return new Uint8Array(); }); }, 'serializable', 'view');
apply(() => { $.ccclass('cc.BufferAsset')(BufferAsset); }, 'ccclass', null);
} // end of patch_cc_BufferAsset

Expand Down
7 changes: 0 additions & 7 deletions native/cocos/core/assets/BufferAsset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,5 @@

namespace cc {

ccstd::any BufferAsset::getNativeAsset() const {
return _buffer;
}

void BufferAsset::setNativeAsset(const ccstd::any &obj) {
_buffer = ccstd::any_cast<ArrayBuffer *>(obj);
}

} // namespace cc
14 changes: 4 additions & 10 deletions native/cocos/core/assets/BufferAsset.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#pragma once

#include "core/ArrayBuffer.h"
#include "core/TypedArray.h"
#include "core/assets/Asset.h"

namespace cc {
Expand All @@ -34,17 +34,11 @@ class BufferAsset final : public Asset {
BufferAsset() = default;
~BufferAsset() override = default;

inline ArrayBuffer *getBuffer() const { return _buffer; }

inline void setNativeAssetForJS(ArrayBuffer *buffer) { _buffer = buffer; }
inline ArrayBuffer *getNativeAssetForJS() const { return _buffer; }

ccstd::any getNativeAsset() const override;
void setNativeAsset(const ccstd::any &obj) override;
bool validate() const override { return _buffer != nullptr; }
const Uint8Array &getView() { return _view; }
void setView(const Uint8Array &view) { _view = view; }

private:
ArrayBuffer::Ptr _buffer;
Uint8Array _view;

CC_DISALLOW_COPY_MOVE_ASSIGN(BufferAsset);
};
Expand Down
4 changes: 1 addition & 3 deletions native/tools/swig-config/assets.i
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@
%rename(_getBindposes) cc::Skeleton::getBindposes;
%rename(_setBindposes) cc::Skeleton::setBindposes;

%rename(buffer) cc::BufferAsset::getBuffer;



// ----- Module Macro Section ------
Expand Down Expand Up @@ -134,7 +132,7 @@
%attribute(cc::ImageAsset, cc::PixelFormat, format, getFormat, setFormat);
%attribute(cc::ImageAsset, ccstd::string&, url, getUrl, setUrl);

%attribute(cc::BufferAsset, cc::ArrayBuffer*, _nativeAsset, getNativeAssetForJS, setNativeAssetForJS);
%attribute(cc::BufferAsset, cc::Uint8Array&, view, getView, setView);

%attribute(cc::TextureBase, bool, isCompressed, isCompressed);
%attribute(cc::TextureBase, uint32_t, _width, getWidth, setWidth);
Expand Down

0 comments on commit 13ea8d7

Please sign in to comment.