Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions source/network_decoder/network_downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ std::vector<u8> NetworkStream::get_data(u64 start, u64 size) {
downloaded_data_lock.unlock();
return res;
}
void NetworkStream::set_data(u64 block, const std::vector<u8> &data) {

void NetworkStream::set_data(u64 block, std::vector<u8> data) {
downloaded_data_lock.lock();
downloaded_data[block] = data;

// if you move it, it doesn't perform a copy which means you will never get a std::bad_alloc which used to happen before
downloaded_data[block] = std::move(data);

if (downloaded_data.size() > MAX_CACHE_BLOCKS) { // ensure it doesn't cache too much and run out of memory
u64 read_head_block = read_head / BLOCK_SIZE;
if (std::next(downloaded_data.begin())->first < read_head_block) {
Expand Down Expand Up @@ -348,7 +352,7 @@ void NetworkStreamDownloader::downloader_thread() {
continue;
}
cur_stream->retry_cnt_left = NetworkStream::RETRY_CNT_MAX;
cur_stream->set_data(block_reading, result.data);
cur_stream->set_data(block_reading, std::move(result.data)); // data isn't accessed further down so we can move it
cur_stream->ready = true;
} else if (!result.fail) {
logger.error("net/dl", "stream returned: " + std::to_string(result.status_code));
Expand Down
2 changes: 1 addition & 1 deletion source/network_decoder/network_downloader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct NetworkStream {
std::vector<u8> get_data(u64 start, u64 size);

// this function is supposed to be called from NetworkStreamDownloader::*
void set_data(u64 block, const std::vector<u8> &data);
void set_data(u64 block, std::vector<u8> data);
};

// each instance of this class is paired with one downloader thread
Expand Down
4 changes: 2 additions & 2 deletions source/ui/draw/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ Result_with_string Draw_c2d_image_init(Image_data *c2d_image, int tex_size_x, in
GPU_TEXCOLOR color_format) {
Result_with_string result;

c2d_image->subtex = (Tex3DS_SubTexture *)linearAlloc_concurrent(sizeof(Tex3DS_SubTexture *));
c2d_image->c2d.tex = (C3D_Tex *)linearAlloc_concurrent(sizeof(C3D_Tex *));
c2d_image->subtex = (Tex3DS_SubTexture *)linearAlloc_concurrent(sizeof(Tex3DS_SubTexture));
c2d_image->c2d.tex = (C3D_Tex *)linearAlloc_concurrent(sizeof(C3D_Tex));
if (c2d_image->subtex == NULL || c2d_image->c2d.tex == NULL) {
linearFree_concurrent(c2d_image->subtex);
linearFree_concurrent(c2d_image->c2d.tex);
Expand Down