diff --git a/deps_src/admesh/stlinit.cpp b/deps_src/admesh/stlinit.cpp index a69bd5497a..9d44cdf266 100644 --- a/deps_src/admesh/stlinit.cpp +++ b/deps_src/admesh/stlinit.cpp @@ -162,7 +162,7 @@ static bool stl_read(stl_file *stl, FILE *fp, int first_facet, bool first, Impor rewind(fp); try{ char solid_name[256]; - int res_solid = fscanf(fp, " solid %[^\n]", solid_name); + int res_solid = fscanf(fp, " solid %255[^\n]", solid_name); if (res_solid == 1) { char* mw_position = strstr(solid_name, "MW"); if (mw_position != NULL) { @@ -170,7 +170,7 @@ static bool stl_read(stl_file *stl, FILE *fp, int first_facet, bool first, Impor char version_str[16]; char model_id_str[128]; char country_code_str[16]; - int num_values = sscanf(mw_position + 3, "%s %s %s", version_str, model_id_str, country_code_str); + int num_values = sscanf(mw_position + 3, "%15s %127s %15s", version_str, model_id_str, country_code_str); if (num_values == 3) { if (strcmp(version_str, "1.0") == 0) { model_id = model_id_str; diff --git a/scripts/test_build_win.ps1 b/scripts/test_build_win.ps1 index a8abfbc7bf..65dec8ffa1 100644 --- a/scripts/test_build_win.ps1 +++ b/scripts/test_build_win.ps1 @@ -22,6 +22,7 @@ Match regexes; each must match at least one output line NotMatch regexes; none may match any output line NotExists paths that must not exist after the case runs + DateStampedZip require a bundle date from during this case's invocation .PARAMETER Name Run only the cases whose name matches this regex. Headings with no @@ -109,12 +110,6 @@ $slnDir = Join-Path $fixtures 'sln' New-Item -ItemType Directory -Force -Path $slnDir | Out-Null Set-Content -Path (Join-Path $slnDir 'OrcaSlicer.sln') -Value '' -Encoding ascii -# The pack stamp is checked against real dates, so a locale-dependent parse -# in the script cannot pass by looking date-shaped. Yesterday is accepted too, -# so a run that crosses midnight does not flake. -$dateStamps = @((Get-Date -Format 'yyyyMMdd'), (Get-Date).AddDays(-1).ToString('yyyyMMdd')) -$stampPattern = '_(' + ($dateStamps -join '|') + ')\.zip$' - $cases = @( 'argument handling' @{ Name = 'no arguments prints help'; Args = @(); DryRun = $false @@ -326,12 +321,12 @@ $cases = @( Contains = @('OrcaSlicer_dep_win-x64_') NotContains = @('-clang', '-Release') } @{ Name = 'the bundle is stamped with today, not a shuffled date'; Args = @('-p') - Match = @($stampPattern) } + DateStampedZip = $true } # powershell.exe is not in System32 itself, so a trimmed PATH used to # leave the stamp empty and the bundle named OrcaSlicer_dep_win-x64_.zip. @{ Name = 'the bundle is stamped even with a bare PATH'; Args = @('-p') Env = @{ PATH = 'C:\Windows\system32;C:\Windows' } - Match = @($stampPattern) } + DateStampedZip = $true } @{ Name = '-p packs without rebuilding'; Args = @('-p') Match = @('^\+ .*(7z\.exe a|tar\.exe -a -c -f) ') NotContains = @('cmake -S deps') } @@ -861,7 +856,7 @@ function Invoke-BuildScript { $knownFields = @( 'Name', 'Args', 'ExpectExit', 'DryRun', 'First', 'Env', - 'Contains', 'NotContains', 'Match', 'NotMatch', 'NotExists' + 'Contains', 'NotContains', 'Match', 'NotMatch', 'NotExists', 'DateStampedZip' ) function Test-Case { @@ -876,7 +871,9 @@ function Test-Case { $expect = 0 if ($Case.ContainsKey('ExpectExit')) { $expect = $Case['ExpectExit'] } + $started = Get-Date $result = Invoke-BuildScript -Arguments $argv -Environment $Case['Env'] + $finished = Get-Date $problems = @() @@ -902,6 +899,15 @@ function Test-Case { $problems += "no line matching /$pattern/" } } + if ($Case['DateStampedZip']) { + # Bound the accepted dates to this invocation so crossing midnight is + # valid without allowing an unrelated past or future date. + $dateStamps = @($started.ToString('yyyyMMdd'), $finished.ToString('yyyyMMdd')) | Select-Object -Unique + $pattern = '_(' + ($dateStamps -join '|') + ')\.zip$' + if (@($lines | Where-Object { $_ -match $pattern }).Count -eq 0) { + $problems += "no line matching /$pattern/" + } + } foreach ($pattern in $Case['NotMatch']) { foreach ($line in @($lines | Where-Object { $_ -match $pattern })) { $problems += "line matches /$pattern/: $line" diff --git a/src/OrcaSlicer.cpp b/src/OrcaSlicer.cpp index 1f85cf7358..5463f55c20 100644 --- a/src/OrcaSlicer.cpp +++ b/src/OrcaSlicer.cpp @@ -1925,7 +1925,7 @@ int CLI::run(int argc, char **argv) } } catch (std::exception& e) { - boost::nowide::cerr << construct_assemble_list << ": " << e.what() << std::endl; + boost::nowide::cerr << "construct_assemble_list: " << e.what() << std::endl; record_exit_reson(outfile_dir, CLI_DATA_FILE_ERROR, 0, cli_errors[CLI_DATA_FILE_ERROR], sliced_info); flush_and_exit(CLI_DATA_FILE_ERROR); } @@ -1975,7 +1975,7 @@ int CLI::run(int argc, char **argv) } std::unique_ptr cli_preset_bundle; - auto ensure_cli_preset_bundle = [&cli_preset_bundle, config_substitution_rule](std::string &error) -> PresetBundle * { + auto ensure_cli_preset_bundle = [&cli_preset_bundle](std::string &error) -> PresetBundle * { if (cli_preset_bundle) return cli_preset_bundle.get(); try { @@ -2002,7 +2002,7 @@ int CLI::run(int argc, char **argv) } }; - auto resolve_preset = [&ensure_cli_preset_bundle, config_substitution_rule](const std::string &file, DynamicPrintConfig &config, + auto resolve_preset = [&ensure_cli_preset_bundle](const std::string &file, DynamicPrintConfig &config, std::string &config_type, const std::string &config_from, bool probe_type, std::string &error) { const auto *inherits = config.option(BBL_JSON_KEY_INHERITS); @@ -2046,7 +2046,7 @@ int CLI::run(int argc, char **argv) error, allow_source_manifest); }; - auto load_config_file = [config_substitution_rule, &resolve_preset](const std::string& file, DynamicPrintConfig& config, std::string& config_type, + auto load_config_file = [&resolve_preset](const std::string& file, DynamicPrintConfig& config, std::string& config_type, std::string& config_name, std::string& filament_id, std::string& config_from) { if (! boost::filesystem::exists(file)) { boost::nowide::cerr << __FUNCTION__<< ": can not find setting file: " << file << std::endl; @@ -4826,7 +4826,7 @@ int CLI::run(int argc, char **argv) } } - if (!arrange_cfg.is_seq_print && (assemble_plate.filaments_count > 1)||(enable_wrapping_detect && !current_wrapping_exclude_area.empty())) + if ((!arrange_cfg.is_seq_print && (assemble_plate.filaments_count > 1))||(enable_wrapping_detect && !current_wrapping_exclude_area.empty())) { //prepare the wipe tower int plate_count = partplate_list.get_plate_count(); diff --git a/src/OrcaSlicer_app_msvc.cpp b/src/OrcaSlicer_app_msvc.cpp index 35568a9cfa..265047fa34 100644 --- a/src/OrcaSlicer_app_msvc.cpp +++ b/src/OrcaSlicer_app_msvc.cpp @@ -297,7 +297,7 @@ int wmain(int argc, wchar_t **argv) // printf("Loading Slic3r library: %S\n", path_to_slic3r); HINSTANCE hInstance_Slic3r = LoadLibraryExW(path_to_slic3r, nullptr, 0); if (hInstance_Slic3r == nullptr) { - printf("OrcaSlicer.dll was not loaded, error=%d\n", GetLastError()); + printf("OrcaSlicer.dll was not loaded, error=%lu\n", GetLastError()); return -1; } diff --git a/src/dev-utils/StackWalker.cpp b/src/dev-utils/StackWalker.cpp index 468e8927a5..6038196cb0 100644 --- a/src/dev-utils/StackWalker.cpp +++ b/src/dev-utils/StackWalker.cpp @@ -364,7 +364,7 @@ void CStackWalker::GetModuleInformation(LPMODULE_INFO pmi) if (dwInfoSize > 0) { - LPVOID lpData = new byte[dwInfoSize]; + byte *lpData = new byte[dwInfoSize]; ZeroMemory(lpData, dwInfoSize * sizeof(byte)); if (GetFileVersionInfo(pmi->szModulePath, dwHandle, dwInfoSize, lpData) > 0 ) diff --git a/src/libslic3r/Algorithm/LineSplit.hpp b/src/libslic3r/Algorithm/LineSplit.hpp index 58b9fdc34a..e12113fa6c 100644 --- a/src/libslic3r/Algorithm/LineSplit.hpp +++ b/src/libslic3r/Algorithm/LineSplit.hpp @@ -49,7 +49,7 @@ SplittedLine split_line(const PathType& path, const ExPolygons& clip, bool close // Convert the input path into an open ZPath ClipperZUtils::ZPath p; - p.reserve(path.size() + closed ? 1 : 0); + p.reserve(path.size() + (closed ? 1 : 0)); ClipperLib_Z::cInt z = 0; for (const auto& point : path) { p.emplace_back(point.x(), point.y(), z); diff --git a/src/libslic3r/Fill/FillRectilinear.cpp b/src/libslic3r/Fill/FillRectilinear.cpp index db340748ab..7edf350081 100644 --- a/src/libslic3r/Fill/FillRectilinear.cpp +++ b/src/libslic3r/Fill/FillRectilinear.cpp @@ -3090,10 +3090,11 @@ bool FillRectilinear::fill_surface_trapezoidal( case 0: // Grid / Trapezoidal { // Generate a non-crossing trapezoidal pattern to avoid overextrusion at intersections when `multiline > 1`. - // P2--P3 - // / \ - // P0_P1/ \P4_ - // + /* + * P2--P3 + * / \ + * P0_P1/ \P4_ + */ // P0xP1x=P4xP0x=d1/2 // P2xP3x=d1 // P1yP2y=P2yP3y=d2 @@ -3171,10 +3172,12 @@ bool FillRectilinear::fill_surface_trapezoidal( case 1: // Triangular { // Generate a non-crossing trapezoidal pattern with a base line below. - // P1-P2 - // / \ - // P0/ \P3_P4 - // ---------------- + /* + * P1-P2 + * / \ + * P0/ \P3_P4 + * ---------------- + */ // P1xP2x=P3xP4x=d2 // P0yP1y=P2yP3y=h-2d1 // diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index cd6c494f33..e4da19cd73 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -1468,9 +1468,11 @@ void GCodeProcessor::run_post_process() // Append a per-filament usage block at a filament change. auto handle_filament_change = [&](int filament_id, int cur_line_id, int nozzle_id) { - // skip filament changes emitted inside the machine start / end gcode - if (m_machine_start_gcode_end_line_id == (unsigned int) (-1) && (unsigned int) (cur_line_id) < m_machine_start_gcode_end_line_id || - m_machine_end_gcode_start_line_id != (unsigned int) (-1) && (unsigned int) (cur_line_id) > m_machine_end_gcode_start_line_id) + // Skip filament changes emitted inside the machine start / end gcode. One forward pass assigns + // the tag ids and tests them in the same loop, so inside the start gcode the end tag is unseen + // and the id still holds the sentinel. That is why the first clause tests == and the second !=. + if ((m_machine_start_gcode_end_line_id == (unsigned int) (-1) && (unsigned int) (cur_line_id) < m_machine_start_gcode_end_line_id) || + (m_machine_end_gcode_start_line_id != (unsigned int) (-1) && (unsigned int) (cur_line_id) > m_machine_end_gcode_start_line_id)) return; if (!m_filament_blocks.empty()) m_filament_blocks.back().upper_gcode_id = cur_line_id; @@ -2777,7 +2779,7 @@ bool GCodeProcessor::check_multi_extruder_gcode_valid(const int std::map> gcode_path_pos; // object_id, filament_id, pos for (const GCodeProcessorResult::MoveVertex &move : m_result.moves) { // sometimes, the start line extrude was outside the edge of plate a little, this is allowed, so do not include into the gcode_path_pos - if (move.type == EMoveType::Extrude /* && move.extrusion_role != ExtrusionRole::erFlush || move.type == EMoveType::Travel*/) + if (move.type == EMoveType::Extrude /* && move.extrusion_role != ExtrusionRole::erFlush || move.type == EMoveType::Travel*/) { if (move.extrusion_role == ExtrusionRole::erCustom) { /*if (move.is_arc_move_with_interpolation_points()) { for (int i = 0; i < move.interpolation_points.size(); i++) { @@ -2799,6 +2801,7 @@ bool GCodeProcessor::check_multi_extruder_gcode_valid(const int gcode_path_pos[move.object_label_id][int(move.extruder_id)].max_print_z = std::max(gcode_path_pos[move.object_label_id][int(move.extruder_id)].max_print_z, move.print_z); } + } } bool valid = true; diff --git a/src/libslic3r/GCode/ToolOrdering.cpp b/src/libslic3r/GCode/ToolOrdering.cpp index 0a97e7ac41..c6517c6e65 100644 --- a/src/libslic3r/GCode/ToolOrdering.cpp +++ b/src/libslic3r/GCode/ToolOrdering.cpp @@ -3137,7 +3137,7 @@ void ToolOrdering::assign_custom_gcodes(const Print &print) // Skip all custom G-codes above this layer and skip all extruder switches. for (; custom_gcode_it != custom_gcode_per_print_z.gcodes.rend() && ( (print_z_above > lt.print_z && custom_gcode_it->print_z > 0.5 * (lt.print_z + print_z_above)) - || custom_gcode_it->type == CustomGCode::ToolChange); ++ custom_gcode_it); + || custom_gcode_it->type == CustomGCode::ToolChange); ++ custom_gcode_it) {} print_z_above = lt.print_z; if (custom_gcode_it == custom_gcode_per_print_z.gcodes.rend()) // Custom G-codes were processed. diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index bef3803c55..589ac14bad 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -4971,12 +4971,8 @@ void WipeTower::generate_new(std::vector #pragma intrinsic(_mul128) #endif diff --git a/src/libslic3r/ObjectID.hpp b/src/libslic3r/ObjectID.hpp index f2697b74f5..56042bbaa3 100644 --- a/src/libslic3r/ObjectID.hpp +++ b/src/libslic3r/ObjectID.hpp @@ -170,6 +170,10 @@ public: this->m_check_sum = rhs.check_sum(); this->m_connectors_cnt = rhs.connectors_cnt(); } + // A user-declared copy assignment or destructor deprecates the implicitly generated + // copy constructor, and this class has both, so declare it rather than rely on it. + CutObjectBase(const CutObjectBase &) = default; + CutObjectBase &operator=(const CutObjectBase &other) { this->copy(other); diff --git a/src/libslic3r/utils.cpp b/src/libslic3r/utils.cpp index 875c90f6ab..58323b29ce 100644 --- a/src/libslic3r/utils.cpp +++ b/src/libslic3r/utils.cpp @@ -961,7 +961,7 @@ CopyFileResult copy_file(const std::string &from, const std::string &to, std::st BOOL result = CopyFileW(src_wstr, dst_wstr, FALSE); if (!result) { DWORD errCode = GetLastError(); - error_message = "Error: " + errCode; + error_message = "Error: " + std::to_string(errCode); ret = FAIL_COPY_FILE; goto __finished; } diff --git a/src/slic3r/GUI/AmsMappingPopupUpdate.cpp b/src/slic3r/GUI/AmsMappingPopupUpdate.cpp index 7d8215f55d..3e2853ad1a 100644 --- a/src/slic3r/GUI/AmsMappingPopupUpdate.cpp +++ b/src/slic3r/GUI/AmsMappingPopupUpdate.cpp @@ -406,7 +406,7 @@ void AmsMapingPopup::update_ams_data_multi_machines() int ams_type = 1; int nozzle_id = 0; - if (ams_type >= 1 || ams_type <= 3) { // 1:ams 2:ams-lite 3:n3f + if (ams_type >= 1 && ams_type <= 3) { // 1:ams 2:ams-lite 3:n3f auto sizer_mapping_list = new wxBoxSizer(wxHORIZONTAL); auto ams_mapping_item_container = new MappingContainer(nozzle_id == 0 ? m_right_marea_panel : m_left_marea_panel, "AMS-1", 4); diff --git a/src/slic3r/GUI/BackgroundSlicingProcess.cpp b/src/slic3r/GUI/BackgroundSlicingProcess.cpp index 64c52c6e72..f795b41999 100644 --- a/src/slic3r/GUI/BackgroundSlicingProcess.cpp +++ b/src/slic3r/GUI/BackgroundSlicingProcess.cpp @@ -848,7 +848,9 @@ void BackgroundSlicingProcess::finalize_gcode() case CopyFileResult::SUCCESS: break; // no error case CopyFileResult::FAIL_COPY_FILE: throw Slic3r::ExportError(GUI::format( - _L("Copying of the temporary G-code to the output G-code failed. Maybe the SD card is write locked?\nError message: %1%"), + m_export_path_on_removable_media ? + _L("Copying of the temporary G-code to the output G-code failed. Maybe the SD card is write locked?\nError message: %1%") : + _L("Copying of the temporary G-code to the output G-code failed.\nError message: %1%"), error_message)); break; case CopyFileResult::FAIL_FILES_DIFFERENT: diff --git a/src/slic3r/GUI/CalibrationWizardPresetPage.cpp b/src/slic3r/GUI/CalibrationWizardPresetPage.cpp index 5267715439..c6d491a930 100644 --- a/src/slic3r/GUI/CalibrationWizardPresetPage.cpp +++ b/src/slic3r/GUI/CalibrationWizardPresetPage.cpp @@ -360,7 +360,7 @@ void CaliPresetCustomRangePanel::create_panel(wxWindow* parent) int max_decimal_length; if (i <= 1) max_decimal_length = 3; - else if (i >= 2) + else max_decimal_length = 4; if (decimal_number > max_decimal_length) { int allowed_length = number.length() - decimal_number + max_decimal_length; diff --git a/src/slic3r/GUI/DeviceCore/DevManager.cpp b/src/slic3r/GUI/DeviceCore/DevManager.cpp index 8844303793..feb6301df3 100644 --- a/src/slic3r/GUI/DeviceCore/DevManager.cpp +++ b/src/slic3r/GUI/DeviceCore/DevManager.cpp @@ -872,7 +872,7 @@ namespace Slic3r obj->m_is_online = elem["dev_online"].get(); if (elem.contains("dev_model_name") && !elem["dev_model_name"].is_null()) { auto printer_type = elem["dev_model_name"].get(); - for (const std::pair> &pair : device_subseries) { + for (const auto &pair : device_subseries) { auto it = std::find(pair.second.begin(), pair.second.end(), printer_type); if (it != pair.second.end()) { diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 142cf70522..b7564551f8 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -2711,7 +2711,8 @@ void ColourPicker::set_value(const boost::any& value, bool change_event) auto field = dynamic_cast(window); #ifdef __WXMSW__ - wxColour clr = (clr_str.IsEmpty() || !clr.IsOk()) ? wxTransparentColour : clr_str; + const wxColour parsed_clr(clr_str); + wxColour clr = (clr_str.IsEmpty() || !parsed_clr.IsOk()) ? wxTransparentColour : parsed_clr; field->SetColour(clr); draw_bmp_btn(field, clr); #else diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 8d72405cdd..556faaa763 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2191,7 +2191,7 @@ void GLCanvas3D::render(bool only_init) // Negative coordinate means out of the window, likely because the window was deactivated. // In that case the tooltip should be hidden. - if (m_mouse.position.x() >= 0. && m_mouse.position.y() >= 0. || has_mouse_capture()) { // ORCA continue to capture mouse pos mid drag + if ((m_mouse.position.x() >= 0. && m_mouse.position.y() >= 0.) || has_mouse_capture()) { // ORCA continue to capture mouse pos mid drag if (tooltip.empty()) tooltip = m_layers_editing.get_tooltip(*this); @@ -9780,18 +9780,18 @@ void GLCanvas3D::_render_paint_toolbar() const ImVec2 number_label_size = ImGui::CalcTextSize(std::to_string(i + 1).c_str()); ImGui::SetCursorPosY(cursor_y + text_offset_y); ImGui::SetCursorPosX(spacing + i * (spacing + button_size.x) + (button_size.x - number_label_size.x) / 2); - ImGui::TextColored(text_color, std::to_string(i + 1).c_str()); + ImGui::TextColored(text_color, "%s", std::to_string(i + 1).c_str()); imgui.pop_bold_font(); ImVec2 filament_first_line_label_size = ImGui::CalcTextSize(filament_text_first_line[i].c_str()); ImGui::SetCursorPosY(cursor_y + text_offset_y + number_label_size.y); ImGui::SetCursorPosX(spacing + i * (spacing + button_size.x) + (button_size.x - filament_first_line_label_size.x) / 2); - ImGui::TextColored(text_color, filament_text_first_line[i].c_str()); + ImGui::TextColored(text_color, "%s", filament_text_first_line[i].c_str()); ImVec2 filament_second_line_label_size = ImGui::CalcTextSize(filament_text_second_line[i].c_str()); ImGui::SetCursorPosY(cursor_y + text_offset_y + number_label_size.y + filament_first_line_label_size.y); ImGui::SetCursorPosX(spacing + i * (spacing + button_size.x) + (button_size.x - filament_second_line_label_size.x) / 2); - ImGui::TextColored(text_color, filament_text_second_line[i].c_str()); + ImGui::TextColored(text_color, "%s", filament_text_second_line[i].c_str()); } if (ImGui::GetWindowWidth() == constraint_window_width) { @@ -10018,9 +10018,9 @@ void GLCanvas3D::_render_assemble_info() const double size1 = m_selection.get_bounding_box().size()(1); double size2 = m_selection.get_bounding_box().size()(2); if (!m_selection.is_empty()) { - ImGui::Text(_L("Volume:").ToUTF8()); ImGui::SameLine(caption_max); + ImGui::Text("%s", _L("Volume:").ToUTF8().data()); ImGui::SameLine(caption_max); ImGui::Text("%.2f", size0 * size1 * size2); - ImGui::Text(_L("Size:").ToUTF8()); ImGui::SameLine(caption_max); + ImGui::Text("%s", _L("Size:").ToUTF8().data()); ImGui::SameLine(caption_max); ImGui::Text("%.2f x %.2f x %.2f", size0, size1, size2); } imgui->end(); diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 3500493329..99a829bdcc 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -6808,7 +6808,7 @@ bool GUI_App::check_preset_parent_available(const std::pair>& preset_data) { - Preset::Type type; + Preset::Type type = Preset::Type::TYPE_INVALID; if (preset_data.second.at(BBL_JSON_KEY_TYPE) == PRESET_IOT_PRINT_TYPE) type = Preset::Type::TYPE_PRINT; else if (preset_data.second.at(BBL_JSON_KEY_TYPE) == PRESET_IOT_PRINTER_TYPE) diff --git a/src/slic3r/GUI/GUI_Utils.cpp b/src/slic3r/GUI/GUI_Utils.cpp index cb8ba45c6b..bc66d90ffd 100644 --- a/src/slic3r/GUI/GUI_Utils.cpp +++ b/src/slic3r/GUI/GUI_Utils.cpp @@ -102,7 +102,7 @@ CopyFileResult copy_file_gui(const std::string &from, const std::string &to, std result = ReadFile(handlesrc, buff, size, &dwRead, NULL); if (!result) { DWORD errCode = GetLastError(); - error_message = "Error: " + errCode; + error_message = "Error: " + std::to_string(errCode); ret = FAIL_COPY_FILE; goto __finished; } @@ -110,7 +110,7 @@ CopyFileResult copy_file_gui(const std::string &from, const std::string &to, std result = WriteFile(handledst,buff,size,&dwWrite,NULL); if (!result) { DWORD errCode = GetLastError(); - error_message = "Error: " + errCode; + error_message = "Error: " + std::to_string(errCode); ret = FAIL_COPY_FILE; goto __finished; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBrimEars.cpp b/src/slic3r/GUI/Gizmos/GLGizmoBrimEars.cpp index 709e7b5b21..904e7d0a07 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBrimEars.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBrimEars.cpp @@ -342,7 +342,7 @@ bool GLGizmoBrimEars::on_mouse(const wxMouseEvent& mouse_event) // concludes that the event was not intended for it, it should return false. bool GLGizmoBrimEars::gizmo_event(SLAGizmoEventType action, const Vec2d &mouse_position, bool shift_down, bool alt_down, bool control_down) { - if (action != SLAGizmoEventType::MouseWheelDown || action != SLAGizmoEventType::MouseWheelUp || action != SLAGizmoEventType::Moving) { + if (action != SLAGizmoEventType::MouseWheelDown && action != SLAGizmoEventType::MouseWheelUp && action != SLAGizmoEventType::Moving) { apply_radius_change(); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp index f190e1ad97..035fb895aa 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp @@ -122,7 +122,7 @@ bool GLGizmoFdmSupports::on_init() {ctrl + _L("Mouse wheel"), _L("Gap area")} }; - memset(&m_print_instance, 0, sizeof(m_print_instance)); + m_print_instance = PrintInstance(); return true; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp index f4fa1fbbb9..6a08d5eff4 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp @@ -343,12 +343,12 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing,ImVec2(10,20)); if (is_worker_running) { // apply or preview // draw progress bar - std::string progress_text = GUI::format("%1%", std::to_string(progress)) + "%%"; + std::string progress_text = GUI::format("%1%", std::to_string(progress)) + "%"; ImVec2 progress_size(bottom_left_width - space_size, 0.0f); ImGui::BBLProgressBar2(progress / 100., progress_size); ImGui::SameLine(); ImGui::AlignTextToFramePadding(); - ImGui::TextColored(ImVec4(0.42f, 0.42f, 0.42f, 1.00f), progress_text.c_str()); + ImGui::TextColored(ImVec4(0.42f, 0.42f, 0.42f, 1.00f), "%s", progress_text.c_str()); ImGui::SameLine(bottom_left_width + slider_width + m_imgui->scaled(1.0f)); } else { ImGui::Dummy(ImVec2(bottom_left_width - space_size, -1)); diff --git a/src/slic3r/GUI/MediaPlayCtrl.cpp b/src/slic3r/GUI/MediaPlayCtrl.cpp index 0d75c3770d..29c8c9f664 100644 --- a/src/slic3r/GUI/MediaPlayCtrl.cpp +++ b/src/slic3r/GUI/MediaPlayCtrl.cpp @@ -71,7 +71,7 @@ MediaPlayCtrl::MediaPlayCtrl(wxWindow *parent, wxMediaCtrl3 *media_ctrl, const w auto ip = str.find(' ', ik); if (ip == wxString::npos) ip = str.Length(); auto v = str.Mid(ik, ip - ik); - if (k == "T:" && v.Length() == 8) { + if (strcmp(k, "T:") == 0 && v.Length() == 8) { long h = 0,m = 0,s = 0; v.Left(2).ToLong(&h); v.Mid(3, 2).ToLong(&m); diff --git a/src/slic3r/GUI/Mouse3DController.cpp b/src/slic3r/GUI/Mouse3DController.cpp index 11709501ac..8ed91d461f 100644 --- a/src/slic3r/GUI/Mouse3DController.cpp +++ b/src/slic3r/GUI/Mouse3DController.cpp @@ -498,7 +498,7 @@ void Mouse3DController::render_settings_dialog(GLCanvas3D& canvas) const ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20.0f, 20.0f)); static ImVec2 last_win_size(0.0f, 0.0f); bool shown = true; - if (imgui.begin(_L("3Dconnexion settings"), &shown, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse || ImGuiWindowFlags_NoTitleBar)) { + if (imgui.begin(_L("3Dconnexion settings"), &shown, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar)) { if (shown) { ImVec2 win_size = ImGui::GetWindowSize(); if (last_win_size.x != win_size.x || last_win_size.y != win_size.y) { diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 90c7837efd..a28add0e4d 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -3659,8 +3659,8 @@ void Sidebar::update_presets(Preset::Type preset_type) // so extruders without an explicit sub-nozzle count never offer Hybrid. A nullable-int // nil is INT_MAX (> 1) and would otherwise falsely pass the gate, so exclude it too. if (boost::algorithm::contains(extruder_variants->values[index], type + " " + nozzle_volumes_def->enum_labels[i]) || - extruder_max_nozzle_count->get_at(index) > 1 && extruder_max_nozzle_count->get_at(index) != ConfigOptionIntsNullable::nil_value() && - nozzle_volumes_def->enum_keys_map->at(nozzle_volumes_def->enum_values[i]) == nvtHybrid) { + (extruder_max_nozzle_count->get_at(index) > 1 && extruder_max_nozzle_count->get_at(index) != ConfigOptionIntsNullable::nil_value() && + nozzle_volumes_def->enum_keys_map->at(nozzle_volumes_def->enum_values[i]) == nvtHybrid)) { if (nozzle_volumes_def->enum_keys_map->at(nozzle_volumes_def->enum_values[i]) == NozzleVolumeType::nvtHighFlow &&(diameter == "0.2" || is_skip_high_flow_printer(printer_model))) continue; diff --git a/src/slic3r/GUI/SelectMachine.cpp b/src/slic3r/GUI/SelectMachine.cpp index 41ee523fbe..629aef7296 100644 --- a/src/slic3r/GUI/SelectMachine.cpp +++ b/src/slic3r/GUI/SelectMachine.cpp @@ -3073,7 +3073,7 @@ static bool _HasExt(const std::vector &ams_mapping_result) { }; for (const auto &info : ams_mapping_result) { - if (info.ams_id == VIRTUAL_AMS_MAIN_ID_STR || info.ams_id == VIRTUAL_AMS_DEPUTY_ID_STR && !info.ams_id.empty()) { + if (info.ams_id == VIRTUAL_AMS_MAIN_ID_STR || (info.ams_id == VIRTUAL_AMS_DEPUTY_ID_STR && !info.ams_id.empty())) { return true; } } diff --git a/src/slic3r/GUI/SyncAmsInfoDialog.cpp b/src/slic3r/GUI/SyncAmsInfoDialog.cpp index 92c3d218e5..7f075dbbfa 100644 --- a/src/slic3r/GUI/SyncAmsInfoDialog.cpp +++ b/src/slic3r/GUI/SyncAmsInfoDialog.cpp @@ -678,7 +678,7 @@ SyncAmsInfoDialog::SyncAmsInfoDialog(wxWindow *parent, SyncInfo &info) : wxBoxSizer *loading_Sizer = new wxBoxSizer(wxHORIZONTAL); m_gif_ctrl = new wxAnimationCtrl(m_loading_page, wxID_ANY, wxNullAnimation, wxDefaultPosition, wxDefaultSize, wxAC_DEFAULT_STYLE); - auto gif_path = Slic3r::var("loading.gif").c_str(); + const wxString gif_path = from_u8(Slic3r::var("loading.gif")); if (m_gif_ctrl->LoadFile(gif_path)){ m_gif_ctrl->SetSize(m_gif_ctrl->GetAnimation().GetSize()); m_gif_ctrl->Play(); @@ -1547,7 +1547,7 @@ bool SyncAmsInfoDialog::is_nozzle_type_match(DevExtderSystem data, wxString &err auto sai_nz_pt = wxGetApp().preset_bundle->printers.get_edited_preset().get_printer_type(wxGetApp().preset_bundle); if (target_machine_nozzle_id == DEPUTY_EXTRUDER_ID) { pos = _L(DevPrinterConfigUtil::get_toolhead_display_name(sai_nz_pt, DEPUTY_EXTRUDER_ID, ToolHeadComponent::Nozzle, ToolHeadNameCase::LowerCase)); - } else if ((target_machine_nozzle_id == MAIN_EXTRUDER_ID)) { + } else if (target_machine_nozzle_id == MAIN_EXTRUDER_ID) { pos = _L(DevPrinterConfigUtil::get_toolhead_display_name(sai_nz_pt, MAIN_EXTRUDER_ID, ToolHeadComponent::Nozzle, ToolHeadNameCase::LowerCase)); } diff --git a/src/slic3r/GUI/UnsavedChangesDialog.cpp b/src/slic3r/GUI/UnsavedChangesDialog.cpp index dd1bf43253..65b678953d 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.cpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.cpp @@ -23,7 +23,6 @@ #include "MsgDialog.hpp" #include "PresetComboBoxes.hpp" -#include "Widgets/RoundedRectangle.hpp" #include "Widgets/CheckBox.hpp" #include "Widgets/DialogButtons.hpp" #include "Widgets/HyperLink.hpp" diff --git a/src/slic3r/Utils/Http.cpp b/src/slic3r/Utils/Http.cpp index f1ff056d10..6f43df74e4 100644 --- a/src/slic3r/Utils/Http.cpp +++ b/src/slic3r/Utils/Http.cpp @@ -254,10 +254,8 @@ int Http::priv::xfercb(void *userp, curl_off_t dltotal, curl_off_t dlnow, curl_o bool cb_cancel = false; if (self->progressfn) { - double speed; + double speed = 0.; curl_easy_getinfo(self->curl, CURLINFO_SPEED_UPLOAD, &speed); - if (speed > 0.01) - speed = speed; Progress progress(dltotal, dlnow, ultotal, ulnow, self->buffer, speed); self->progressfn(progress, cb_cancel); } @@ -323,8 +321,10 @@ void Http::priv::form_add_file(const char *name, const fs::path &path, const cha // We can't use CURLFORM_FILECONTENT, because curl doesn't support Unicode filenames on Windows // and so we use CURLFORM_STREAM with boost ifstream to read the file. + std::string filename_str; if (filename == nullptr) { - filename = path.string().c_str(); + filename_str = path.string(); + filename = filename_str.c_str(); } form_files.emplace_back(path, offset, length); diff --git a/src/slic3r/Utils/SnapmakerPrinterAgent.cpp b/src/slic3r/Utils/SnapmakerPrinterAgent.cpp index 9b9a6809fd..ab7aa9bd52 100644 --- a/src/slic3r/Utils/SnapmakerPrinterAgent.cpp +++ b/src/slic3r/Utils/SnapmakerPrinterAgent.cpp @@ -39,7 +39,7 @@ std::string find_closest_color_preset_by_vendor_and_type(const PresetCollection& std::string p_color = p.config.opt_string("default_filament_colour", 0u); unsigned int p_color_value; if (!p_color.empty()) { - unsigned int hash_pos = p_color.find("#"); + size_t hash_pos = p_color.find("#"); p_color_value = std::stoul(p_color.substr(hash_pos != std::string::npos ? hash_pos + 1 : 0), nullptr, 16); } else { // Default to black if no color specified in profile. Assume other profiles might be a closer color match. diff --git a/tests/libslic3r/test_utils.cpp b/tests/libslic3r/test_utils.cpp index c039069b2a..484438127c 100644 --- a/tests/libslic3r/test_utils.cpp +++ b/tests/libslic3r/test_utils.cpp @@ -2,6 +2,13 @@ #include "libslic3r/Utils.hpp" +#include "test_utils.hpp" + +#include +#include +#include +#include + #ifndef _WIN32 #include // getuid #endif @@ -52,3 +59,32 @@ TEST_CASE("per-user temp root is unchanged on Windows, isolated elsewhere", "[ut REQUIRE_THAT(root, Catch::Matchers::StartsWith(base + "/orcaslicer_")); #endif } + +TEST_CASE("copy_file reports the OS error when the destination cannot be written", "[utils]") { + ScopedTemporaryFile source(".txt"); + { + std::ofstream ofs(source.string(), std::ios::binary); + ofs << "orca"; + } + REQUIRE(boost::filesystem::exists(source.path())); + + // A directory that was never created, so the copy fails on every platform. + const boost::filesystem::path destination = source.path().parent_path() / "orca-missing-dir" / "copy.txt"; + REQUIRE_FALSE(boost::filesystem::exists(destination.parent_path())); + + std::string error_message; + REQUIRE(copy_file(source.string(), destination.string(), error_message) == FAIL_COPY_FILE); + REQUIRE_FALSE(error_message.empty()); + +#ifdef _WIN32 + // The Windows branch formats GetLastError() itself. Writing that as + // "Error: " + errCode adds an integer to a string literal, which indexes into the + // literal instead of appending and runs off its end for any code above 7. + const std::string prefix = "Error: "; + REQUIRE(error_message.rfind(prefix, 0) == 0); + + const std::string code = error_message.substr(prefix.size()); + REQUIRE_FALSE(code.empty()); + REQUIRE(std::all_of(code.begin(), code.end(), [](unsigned char c) { return std::isdigit(c) != 0; })); +#endif // _WIN32 +}