diff --git a/src/document.cpp b/src/document.cpp index 1b8aed8..d31144f 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -1,5 +1,6 @@ #include "document.hpp" +#include #include #include @@ -86,28 +87,8 @@ namespace anm2ed Document& Document::operator=(Document&& other) noexcept { if (this != &other) - { - path = std::move(other.path); - snapshots = std::move(other.snapshots); - previewZoom = other.previewZoom; - previewPan = other.previewPan; - editorPan = other.editorPan; - editorZoom = other.editorZoom; - overlayIndex = other.overlayIndex; - regionBySpritesheet = std::move(other.regionBySpritesheet); - changeAllFramePropertiesRegionId = other.changeAllFramePropertiesRegionId; - hash = other.hash; - saveHash = other.saveHash; - autosaveHash = other.autosaveHash; - lastAutosaveTime = other.lastAutosaveTime; - isValid = other.isValid; - isOpen = other.isOpen; - isForceDirty = other.isForceDirty; - spritesheetHashes = std::move(other.spritesheetHashes); - spritesheetSaveHashes = std::move(other.spritesheetSaveHashes); - isAnimationPreviewSet = other.isAnimationPreviewSet; - isSpritesheetEditorSet = other.isSpritesheetEditorSet; - } + this->~Document(); + new (this) Document(std::move(other)); return *this; } diff --git a/src/imgui/window/frame_properties.cpp b/src/imgui/window/frame_properties.cpp index c0e1798..0758251 100644 --- a/src/imgui/window/frame_properties.cpp +++ b/src/imgui/window/frame_properties.cpp @@ -39,13 +39,17 @@ namespace anm2ed::imgui if (type == anm2::LAYER && document.reference.itemID != -1) { - auto spritesheetID = document.anm2.content.layers.at(document.reference.itemID).spritesheetID; - auto regionIt = document.regionBySpritesheet.find(spritesheetID); - if (regionIt != document.regionBySpritesheet.end() && !regionIt->second.ids.empty() && - !regionIt->second.labels.empty()) + if (auto layerIt = document.anm2.content.layers.find(document.reference.itemID); + layerIt != document.anm2.content.layers.end()) { - regionLabels = regionIt->second.labels; - regionIds = regionIt->second.ids; + auto spritesheetID = layerIt->second.spritesheetID; + auto regionIt = document.regionBySpritesheet.find(spritesheetID); + if (regionIt != document.regionBySpritesheet.end() && !regionIt->second.ids.empty() && + !regionIt->second.labels.empty()) + { + regionLabels = regionIt->second.labels; + regionIds = regionIt->second.ids; + } } } diff --git a/src/imgui/window/regions.cpp b/src/imgui/window/regions.cpp index e135684..e91b6d2 100644 --- a/src/imgui/window/regions.cpp +++ b/src/imgui/window/regions.cpp @@ -482,6 +482,13 @@ namespace anm2ed::imgui if (ImGui::BeginPopupModal(propertiesPopup.label(), &propertiesPopup.isOpen, ImGuiWindowFlags_NoResize)) { + if (!spritesheet || (reference != -1 && !spritesheet->regions.contains(reference))) + { + propertiesPopup.close(); + ImGui::EndPopup(); + return; + } + auto childSize = child_size_get(5); auto& region = reference == -1 ? editRegion : spritesheet->regions.at(reference); diff --git a/src/imgui/window/spritesheet_editor.cpp b/src/imgui/window/spritesheet_editor.cpp index 0801b25..0defad8 100644 --- a/src/imgui/window/spritesheet_editor.cpp +++ b/src/imgui/window/spritesheet_editor.cpp @@ -227,10 +227,13 @@ namespace anm2ed::imgui } } + auto layerIt = anm2.content.layers.find(reference.itemID); + bool isReferenceLayerOnSpritesheet = + frame && reference.itemID > -1 && layerIt != anm2.content.layers.end() && + layerIt->second.spritesheetID == referenceSpritesheet; + int highlightedRegionId = -1; - if (frame && reference.itemID > -1 && - anm2.content.layers.at(reference.itemID).spritesheetID == referenceSpritesheet && frame->regionID != -1 && - spritesheet->regions.contains(frame->regionID)) + if (isReferenceLayerOnSpritesheet && frame->regionID != -1 && spritesheet->regions.contains(frame->regionID)) { highlightedRegionId = frame->regionID; } @@ -271,8 +274,7 @@ namespace anm2ed::imgui } } - bool isFrameOnSpritesheet = - frame && reference.itemID > -1 && anm2.content.layers.at(reference.itemID).spritesheetID == referenceSpritesheet; + bool isFrameOnSpritesheet = isReferenceLayerOnSpritesheet; if (isFrameOnSpritesheet && frame->regionID == -1) { auto frameModel = math::quad_model_get(frame->size, frame->crop); @@ -338,6 +340,10 @@ namespace anm2ed::imgui auto isMod = ImGui::IsKeyDown(ImGuiMod_Shift); auto frame = document.frame_get(); + auto layerIt = anm2.content.layers.find(reference.itemID); + bool isReferenceLayerOnSpritesheet = + frame && reference.itemID > -1 && layerIt != anm2.content.layers.end() && + layerIt->second.spritesheetID == referenceSpritesheet; auto useTool = tool; auto step = isMod ? STEP_FAST : STEP; auto stepX = isGridSnap ? step * gridSize.x : step; @@ -440,8 +446,7 @@ namespace anm2ed::imgui { regionReference = hoveredRegionId; regionSelection = {hoveredRegionId}; - if (frame && reference.itemID > -1 && - anm2.content.layers.at(reference.itemID).spritesheetID == referenceSpritesheet) + if (isReferenceLayerOnSpritesheet) { DOCUMENT_EDIT(document, localize.get(EDIT_FRAME_REGION), Document::FRAMES, { diff --git a/src/imgui/window/timeline.cpp b/src/imgui/window/timeline.cpp index d6cc570..1b4502c 100644 --- a/src/imgui/window/timeline.cpp +++ b/src/imgui/window/timeline.cpp @@ -653,17 +653,33 @@ namespace anm2ed::imgui ImGui::PushID(index); auto item = animation ? animation->item_get(type, id) : nullptr; + if (type != anm2::NONE && !item) + { + ImGui::PopID(); + return; + } auto isVisible = item ? item->isVisible : false; auto& isOnlyShowLayers = settings.timelineIsOnlyShowLayers; if (isOnlyShowLayers && type != anm2::LAYER) isVisible = false; auto isReferenced = reference.itemType == type && reference.itemID == id; - auto label = type == anm2::LAYER ? std::vformat(localize.get(FORMAT_LAYER), - std::make_format_args(id, anm2.content.layers[id].name, - anm2.content.layers[id].spritesheetID)) - : type == anm2::NULL_ - ? std::vformat(localize.get(FORMAT_NULL), std::make_format_args(id, anm2.content.nulls[id].name)) - : localize.get(anm2::TYPE_STRINGS[type]); + auto label = [&]() -> std::string + { + if (type == anm2::LAYER) + { + auto it = anm2.content.layers.find(id); + if (it == anm2.content.layers.end()) return localize.get(anm2::TYPE_STRINGS[type]); + return std::vformat(localize.get(FORMAT_LAYER), + std::make_format_args(id, it->second.name, it->second.spritesheetID)); + } + if (type == anm2::NULL_) + { + auto it = anm2.content.nulls.find(id); + if (it == anm2.content.nulls.end()) return localize.get(anm2::TYPE_STRINGS[type]); + return std::vformat(localize.get(FORMAT_NULL), std::make_format_args(id, it->second.name)); + } + return localize.get(anm2::TYPE_STRINGS[type]); + }(); auto icon = anm2::TYPE_ICONS[type]; auto iconTintCurrent = isLightTheme && type == anm2::NONE ? ImVec4(1.0f, 1.0f, 1.0f, 1.0f) : itemIconTint; auto baseColorVec = item_color_vec(type); @@ -699,7 +715,9 @@ namespace anm2ed::imgui ImGui::SetNextItemStorageID(id); if (ImGui::Selectable("##Item Button", isReferenced, ImGuiSelectableFlags_SelectOnClick, itemSize)) { - if (type == anm2::LAYER) document.spritesheet.reference = anm2.content.layers[id].spritesheetID; + if (type == anm2::LAYER) + if (auto it = anm2.content.layers.find(id); it != anm2.content.layers.end()) + document.spritesheet.reference = it->second.spritesheetID; reference_set_item(type, id); } ImGui::PopStyleColor(3); @@ -743,7 +761,9 @@ namespace anm2ed::imgui } case anm2::LAYER: { - auto& layer = anm2.content.layers[id]; + auto it = anm2.content.layers.find(id); + if (it == anm2.content.layers.end()) break; + auto& layer = it->second; ImGui::PushFont(resources.fonts[font::BOLD].get(), font::SIZE); ImGui::TextUnformatted(layer.name.c_str()); ImGui::PopFont(); @@ -760,7 +780,9 @@ namespace anm2ed::imgui } case anm2::NULL_: { - auto& nullInfo = anm2.content.nulls[id]; + auto it = anm2.content.nulls.find(id); + if (it == anm2.content.nulls.end()) break; + auto& nullInfo = it->second; ImGui::PushFont(resources.fonts[font::BOLD].get(), font::SIZE); ImGui::TextUnformatted(nullInfo.name.c_str()); ImGui::PopFont(); @@ -853,18 +875,21 @@ namespace anm2ed::imgui if (type == anm2::NULL_) { - auto& null = anm2.content.nulls.at(id); - auto& isShowRect = null.isShowRect; - auto rectIcon = isShowRect ? icon::SHOW_RECT : icon::HIDE_RECT; - ImGui::SetCursorPos( - ImVec2(itemSize.x - (ImGui::GetTextLineHeightWithSpacing() * 2) - ImGui::GetStyle().ItemSpacing.x, - (itemSize.y - ImGui::GetTextLineHeightWithSpacing()) / 2)); - if (ImGui::ImageButton("##Rect Toggle", resources.icons[rectIcon].id, icon_size_get())) - DOCUMENT_EDIT(document, localize.get(EDIT_TOGGLE_NULL_RECT), Document::FRAMES, - null.isShowRect = !null.isShowRect); - overlay_icon(resources.icons[rectIcon].id, iconTintCurrent); - ImGui::SetItemTooltip("%s", isShowRect ? localize.get(TOOLTIP_NULL_RECT_SHOWN) - : localize.get(TOOLTIP_NULL_RECT_HIDDEN)); + if (auto it = anm2.content.nulls.find(id); it != anm2.content.nulls.end()) + { + auto& null = it->second; + auto& isShowRect = null.isShowRect; + auto rectIcon = isShowRect ? icon::SHOW_RECT : icon::HIDE_RECT; + ImGui::SetCursorPos( + ImVec2(itemSize.x - (ImGui::GetTextLineHeightWithSpacing() * 2) - ImGui::GetStyle().ItemSpacing.x, + (itemSize.y - ImGui::GetTextLineHeightWithSpacing()) / 2)); + if (ImGui::ImageButton("##Rect Toggle", resources.icons[rectIcon].id, icon_size_get())) + DOCUMENT_EDIT(document, localize.get(EDIT_TOGGLE_NULL_RECT), Document::FRAMES, + null.isShowRect = !null.isShowRect); + overlay_icon(resources.icons[rectIcon].id, iconTintCurrent); + ImGui::SetItemTooltip("%s", isShowRect ? localize.get(TOOLTIP_NULL_RECT_SHOWN) + : localize.get(TOOLTIP_NULL_RECT_HIDDEN)); + } } ImGui::PopStyleVar(2); @@ -1229,7 +1254,9 @@ namespace anm2ed::imgui bool isDifferentItem = reference.itemType != type || reference.itemID != id; if (ImGui::Selectable("##Frame Button", isSelected, ImGuiSelectableFlags_None, buttonSize)) { - if (type == anm2::LAYER) document.spritesheet.reference = anm2.content.layers[id].spritesheetID; + if (type == anm2::LAYER) + if (auto it = anm2.content.layers.find(id); it != anm2.content.layers.end()) + document.spritesheet.reference = it->second.spritesheetID; if (type != anm2::TRIGGER) { @@ -1275,11 +1302,12 @@ namespace anm2ed::imgui frameDragDrop.type = type; frameDragDrop.itemID = id; frameDragDrop.animationIndex = reference.animationIndex; + frameSelectionLocked.clear(); auto append_valid_indices = [&](const auto& container) { for (auto idx : container) - if (idx >= 0 && idx < (int)item->frames.size()) frameDragDrop.selection.push_back(idx); + if (idx >= 0 && idx < (int)item->frames.size()) frameSelectionLocked.push_back(idx); }; if (isReferenced) append_valid_indices(frames.selection); @@ -1287,27 +1315,26 @@ namespace anm2ed::imgui auto contains_index = [&](const std::vector& container, int index) { return std::find(container.begin(), container.end(), index) != container.end(); }; - if ((!contains_index(frameDragDrop.selection, (int)i) || frameDragDrop.selection.size() <= 1) && + if ((!contains_index(frameSelectionLocked, (int)i) || frameSelectionLocked.size() <= 1) && frameSelectionSnapshotReference.animationIndex == reference.animationIndex && frameSelectionSnapshotReference.itemType == type && frameSelectionSnapshotReference.itemID == id && contains_index(frameSelectionSnapshot, (int)i)) { - frameDragDrop.selection = frameSelectionSnapshot; + frameSelectionLocked = frameSelectionSnapshot; frames.selection.clear(); for (int idx : frameSelectionSnapshot) if (idx >= 0 && idx < (int)item->frames.size()) frames.selection.insert(idx); - frameSelectionLocked = frameDragDrop.selection; isFrameSelectionLocked = true; } - if (frameDragDrop.selection.empty()) frameDragDrop.selection.push_back((int)i); + if (frameSelectionLocked.empty()) frameSelectionLocked.push_back((int)i); - std::sort(frameDragDrop.selection.begin(), frameDragDrop.selection.end()); - frameDragDrop.selection.erase( - std::unique(frameDragDrop.selection.begin(), frameDragDrop.selection.end()), - frameDragDrop.selection.end()); + std::sort(frameSelectionLocked.begin(), frameSelectionLocked.end()); + frameSelectionLocked.erase(std::unique(frameSelectionLocked.begin(), frameSelectionLocked.end()), + frameSelectionLocked.end()); - ImGui::SetDragDropPayload(FRAME_DRAG_PAYLOAD_ID, &frameDragDrop, sizeof(FrameDragDrop)); + frameDragDropPayload = {type, id, reference.animationIndex}; + ImGui::SetDragDropPayload(FRAME_DRAG_PAYLOAD_ID, &frameDragDropPayload, sizeof(frameDragDropPayload)); ImGui::EndDragDropSource(); } @@ -1315,7 +1342,7 @@ namespace anm2ed::imgui { if (auto payload = ImGui::AcceptDragDropPayload(FRAME_DRAG_PAYLOAD_ID)) { - auto source = static_cast(payload->Data); + auto source = static_cast(payload->Data); auto sameAnimation = source && source->animationIndex == reference.animationIndex; auto sourceItem = sameAnimation && animation ? animation->item_get(source->type, source->itemID) : nullptr; @@ -1333,7 +1360,7 @@ namespace anm2ed::imgui if (source && sourceItem && targetItem && source->type != anm2::TRIGGER && type != anm2::TRIGGER) { - std::vector indices = source->selection; + std::vector indices = frameSelectionLocked; if (indices.empty()) indices.push_back((int)i); std::sort(indices.begin(), indices.end()); indices.erase(std::unique(indices.begin(), indices.end()), indices.end()); @@ -1387,7 +1414,8 @@ namespace anm2ed::imgui document.frameTime = time_from_index(targetItem, reference.frameIndex); if (type == anm2::LAYER) { - document.spritesheet.reference = anm2.content.layers[id].spritesheetID; + if (auto it = anm2.content.layers.find(id); it != anm2.content.layers.end()) + document.spritesheet.reference = it->second.spritesheetID; } } } @@ -1496,6 +1524,7 @@ namespace anm2ed::imgui draggedFrameStart = -1; draggedFrameStartDuration = -1; isDraggedFrameSnapshot = false; + frameSelectionLocked.clear(); if (type == anm2::TRIGGER) item->frames_sort_by_at_frame(); } } @@ -1858,23 +1887,29 @@ namespace anm2ed::imgui if (type == anm2::LAYER) { - auto& layer = anm2.content.layers[id]; - auto label = - std::vformat(localize.get(FORMAT_LAYER), std::make_format_args(id, layer.name, layer.spritesheetID)); - if (ImGui::Selectable(label.c_str(), isSelected)) + if (auto it = anm2.content.layers.find(id); it != anm2.content.layers.end()) { - addItemID = id; - addItemSpritesheetID = layer.spritesheetID; + auto& layer = it->second; + auto label = std::vformat(localize.get(FORMAT_LAYER), + std::make_format_args(id, layer.name, layer.spritesheetID)); + if (ImGui::Selectable(label.c_str(), isSelected)) + { + addItemID = id; + addItemSpritesheetID = layer.spritesheetID; + } } } else if (type == anm2::NULL_) { - auto& null = anm2.content.nulls[id]; - auto label = std::vformat(localize.get(FORMAT_NULL), std::make_format_args(id, null.name)); - if (ImGui::Selectable(label.c_str(), isSelected)) + if (auto it = anm2.content.nulls.find(id); it != anm2.content.nulls.end()) { - addItemID = id; - addItemIsShowRect = null.isShowRect; + auto& null = it->second; + auto label = std::vformat(localize.get(FORMAT_NULL), std::make_format_args(id, null.name)); + if (ImGui::Selectable(label.c_str(), isSelected)) + { + addItemID = id; + addItemIsShowRect = null.isShowRect; + } } } @@ -2009,16 +2044,16 @@ namespace anm2ed::imgui auto isNextFrame = shortcut(manager.chords[SHORTCUT_NEXT_FRAME], shortcut::GLOBAL); if (isPreviousFrame) - if (auto item = document.item_get(); !item->frames.empty()) + if (auto item = document.item_get(); item && !item->frames.empty()) reference.frameIndex = glm::clamp(--reference.frameIndex, 0, (int)item->frames.size() - 1); if (isNextFrame) - if (auto item = document.item_get(); !item->frames.empty()) + if (auto item = document.item_get(); item && !item->frames.empty()) reference.frameIndex = glm::clamp(++reference.frameIndex, 0, (int)item->frames.size() - 1); if (isPreviousFrame || isNextFrame) { - if (auto item = document.item_get(); !item->frames.empty()) + if (auto item = document.item_get(); item && !item->frames.empty()) { frames_selection_set_reference(); document.frameTime = item->frame_time_from_index_get(reference.frameIndex); diff --git a/src/imgui/window/timeline.hpp b/src/imgui/window/timeline.hpp index d75910c..761f27c 100644 --- a/src/imgui/window/timeline.hpp +++ b/src/imgui/window/timeline.hpp @@ -15,7 +15,13 @@ namespace anm2ed::imgui anm2::Type type{anm2::NONE}; int itemID{-1}; int animationIndex{-1}; - std::vector selection{}; + }; + + struct FrameDragDropPayload + { + anm2::Type type{anm2::NONE}; + int itemID{-1}; + int animationIndex{-1}; }; class Timeline @@ -39,6 +45,7 @@ namespace anm2ed::imgui bool frameFocusRequested{}; int frameFocusIndex{-1}; FrameDragDrop frameDragDrop{}; + FrameDragDropPayload frameDragDropPayload{}; std::vector frameSelectionSnapshot{}; std::vector frameSelectionLocked{}; bool isFrameSelectionLocked{}; diff --git a/src/imgui/wizard/change_all_frame_properties.cpp b/src/imgui/wizard/change_all_frame_properties.cpp index e1af3d7..d861db6 100644 --- a/src/imgui/wizard/change_all_frame_properties.cpp +++ b/src/imgui/wizard/change_all_frame_properties.cpp @@ -234,9 +234,13 @@ namespace anm2ed::imgui::wizard const Storage* regionStorage = nullptr; if (itemType == anm2::LAYER && document.reference.itemID != -1) { - auto spritesheetID = document.anm2.content.layers.at(document.reference.itemID).spritesheetID; - auto regionIt = document.regionBySpritesheet.find(spritesheetID); - if (regionIt != document.regionBySpritesheet.end()) regionStorage = ®ionIt->second; + if (auto layerIt = document.anm2.content.layers.find(document.reference.itemID); + layerIt != document.anm2.content.layers.end()) + { + auto spritesheetID = layerIt->second.spritesheetID; + auto regionIt = document.regionBySpritesheet.find(spritesheetID); + if (regionIt != document.regionBySpritesheet.end()) regionStorage = ®ionIt->second; + } } auto regionIds = regionStorage && !regionStorage->ids.empty() ? regionStorage->ids : fallbackIds; auto regionLabels = regionStorage && !regionStorage->labels.empty() ? regionStorage->labels : fallbackLabels; @@ -289,10 +293,13 @@ namespace anm2ed::imgui::wizard if (isFlipXSet) frameChange.isFlipX = std::make_optional(isFlipX); if (isFlipYSet) frameChange.isFlipY = std::make_optional(isFlipY); - DOCUMENT_EDIT(document, localize.get(EDIT_CHANGE_FRAME_PROPERTIES), Document::FRAMES, - document.item_get()->frames_change(frameChange, itemType, changeType, frames)); + if (auto item = document.item_get()) + { + DOCUMENT_EDIT(document, localize.get(EDIT_CHANGE_FRAME_PROPERTIES), Document::FRAMES, + item->frames_change(frameChange, itemType, changeType, frames)); - isChanged = true; + isChanged = true; + } }; ImGui::Separator(); diff --git a/src/imgui/wizard/generate_animation_from_grid.cpp b/src/imgui/wizard/generate_animation_from_grid.cpp index 3c9ba64..6d8bec2 100644 --- a/src/imgui/wizard/generate_animation_from_grid.cpp +++ b/src/imgui/wizard/generate_animation_from_grid.cpp @@ -57,21 +57,27 @@ namespace anm2ed::imgui::wizard if (document.reference.itemType == anm2::LAYER) { - auto& texture = - document.anm2.content.spritesheets[document.anm2.content.layers[document.reference.itemID].spritesheetID] - .texture; + auto layerIt = document.anm2.content.layers.find(document.reference.itemID); + if (layerIt != document.anm2.content.layers.end()) + { + auto spritesheetIt = document.anm2.content.spritesheets.find(layerIt->second.spritesheetID); + if (spritesheetIt != document.anm2.content.spritesheets.end()) + { + auto& texture = spritesheetIt->second.texture; - auto index = std::clamp((int)(time * (count - 1)), 0, (count - 1)); - auto row = index / columns; - auto column = index % columns; - auto crop = startPosition + ivec2(size.x * column, size.y * row); - auto uvMin = (vec2(crop) + vec2(0.5f)) / vec2(texture.size); - auto uvMax = (vec2(crop) + vec2(size) - vec2(0.5f)) / vec2(texture.size); + auto index = std::clamp((int)(time * (count - 1)), 0, (count - 1)); + auto row = index / columns; + auto column = index % columns; + auto crop = startPosition + ivec2(size.x * column, size.y * row); + auto uvMin = (vec2(crop) + vec2(0.5f)) / vec2(texture.size); + auto uvMax = (vec2(crop) + vec2(size) - vec2(0.5f)) / vec2(texture.size); - mat4 transform = transform_get(zoom) * math::quad_model_get(size, {}, pivot); + mat4 transform = transform_get(zoom) * math::quad_model_get(size, {}, pivot); - texture_render(shaderTexture, texture.id, transform, vec4(1.0f), {}, - math::uv_vertices_get(uvMin, uvMax).data()); + texture_render(shaderTexture, texture.id, transform, vec4(1.0f), {}, + math::uv_vertices_get(uvMin, uvMax).data()); + } + } } unbind(); @@ -112,4 +118,4 @@ namespace anm2ed::imgui::wizard if (ImGui::Button(localize.get(BASIC_CANCEL), widgetSize)) isEnd = true; } -} \ No newline at end of file +} diff --git a/src/manager.cpp b/src/manager.cpp index 3a4a41a..0886b9a 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -199,8 +199,10 @@ namespace anm2ed { if (id == -1) editLayer = anm2::Layer(); + else if (auto it = document->anm2.content.layers.find(id); it != document->anm2.content.layers.end()) + editLayer = it->second; else - editLayer = document->anm2.content.layers.at(id); + return; document->layer.reference = id; @@ -224,8 +226,10 @@ namespace anm2ed { if (id == -1) editNull = anm2::Null(); + else if (auto it = document->anm2.content.nulls.find(id); it != document->anm2.content.nulls.end()) + editNull = it->second; else - editNull = document->anm2.content.nulls.at(id); + return; document->null.reference = id; diff --git a/src/socket.cpp b/src/socket.cpp index 33025c3..d35c753 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -1,6 +1,7 @@ #include "socket.hpp" #include +#include namespace anm2ed { @@ -203,7 +204,12 @@ namespace anm2ed while (totalSent < size) { - auto sent = ::send(handle, bytes + totalSent, static_cast(size - totalSent), 0); + auto chunkSize = static_cast(std::min(size - totalSent, static_cast(INT_MAX))); +#ifdef MSG_NOSIGNAL + auto sent = ::send(handle, bytes + totalSent, chunkSize, MSG_NOSIGNAL); +#else + auto sent = ::send(handle, bytes + totalSent, chunkSize, 0); +#endif if (sent <= 0) { lastError = socket_last_error(); @@ -229,7 +235,8 @@ namespace anm2ed while (totalReceived < size) { - auto received = ::recv(handle, bytes + totalReceived, static_cast(size - totalReceived), 0); + auto chunkSize = static_cast(std::min(size - totalReceived, static_cast(INT_MAX))); + auto received = ::recv(handle, bytes + totalReceived, chunkSize, 0); if (received <= 0) { lastError = socket_last_error(); diff --git a/workshop/metadata.xml b/workshop/metadata.xml index 4904701..2b36552 100644 --- a/workshop/metadata.xml +++ b/workshop/metadata.xml @@ -53,6 +53,6 @@ Alternatively, if you have subscribed to the mod, you can find the latest releas [h3]Happy animating![/h3] [img]https://files.catbox.moe/4auc1c.gif[/img] - 2.16 + 2.17 Public