mirror of
https://git.mirrors.martin98.com/https://github.com/bambulab/BambuStudio.git
synced 2025-09-28 14:23:13 +08:00
FIX:Less than 5 GB of free memory will not apply for lod
jira: STUDIO-12063 Change-Id: Id55f609cc62371ae8660e0487d2894dff6bcf836
This commit is contained in:
parent
853149ea26
commit
773319228a
@ -539,6 +539,8 @@ set(SLIC3R_GUI_SOURCES
|
||||
Utils/NetworkAgent.hpp
|
||||
Utils/MKS.hpp
|
||||
Utils/MKS.cpp
|
||||
Utils/CpuMemory.cpp
|
||||
Utils/CpuMemory.hpp
|
||||
Utils/Duet.cpp
|
||||
Utils/Duet.hpp
|
||||
Utils/FlashAir.cpp
|
||||
|
@ -3219,7 +3219,7 @@ void GCodeViewer::load_shells(const Print& print, bool initialized, bool force_p
|
||||
// BBS: fix the issue that object_idx is not assigned as index of Model.objects array
|
||||
int object_count = 0;
|
||||
const ModelObjectPtrs& model_objs = wxGetApp().model().objects;
|
||||
bool enable_lod = GUI::wxGetApp().app_config->get("enable_lod") == "true";
|
||||
bool enable_lod = false;
|
||||
for (const PrintObject* obj : print.objects()) {
|
||||
const ModelObject* model_obj = obj->model_object();
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
||||
#include "format.hpp"
|
||||
#include "DailyTips.hpp"
|
||||
#include "FilamentMapDialog.hpp"
|
||||
|
||||
#include "../Utils/CpuMemory.hpp"
|
||||
#if ENABLE_RETINA_GL
|
||||
#include "slic3r/Utils/RetinaHelper.hpp"
|
||||
#endif
|
||||
@ -1363,7 +1363,7 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, Bed3D &bed)
|
||||
|
||||
GLCanvas3D::~GLCanvas3D()
|
||||
{
|
||||
reset_volumes();
|
||||
reset_volumes(false);
|
||||
|
||||
m_sel_plate_toolbar.del_all_item();
|
||||
m_sel_plate_toolbar.del_stats_item();
|
||||
@ -1529,7 +1529,7 @@ unsigned int GLCanvas3D::get_volumes_count() const
|
||||
return (unsigned int)m_volumes.volumes.size();
|
||||
}
|
||||
|
||||
void GLCanvas3D::reset_volumes()
|
||||
void GLCanvas3D::reset_volumes(bool set_notice)
|
||||
{
|
||||
if (!m_initialized)
|
||||
return;
|
||||
@ -1542,8 +1542,7 @@ void GLCanvas3D::reset_volumes()
|
||||
m_selection.clear();
|
||||
m_volumes.clear();
|
||||
m_dirty = true;
|
||||
|
||||
_set_warning_notification(EWarning::ObjectOutside, false);
|
||||
if (set_notice) { _set_warning_notification(EWarning::ObjectOutside, false); }
|
||||
}
|
||||
|
||||
//BBS: get current plater's bounding box
|
||||
@ -2989,7 +2988,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
|
||||
}
|
||||
}
|
||||
m_volumes.volumes = std::move(glvolumes_new);
|
||||
bool enable_lod = GUI::wxGetApp().app_config->get("enable_lod") == "true";
|
||||
bool enable_lod = GUI::wxGetApp().app_config->get_bool("enable_lod") && CpuMemory::cur_free_memory_less_than_specify_size_gb(LOD_FREE_MEMORY_SIZE);
|
||||
for (unsigned int obj_idx = 0; obj_idx < (unsigned int)m_model->objects.size(); ++ obj_idx) {
|
||||
const ModelObject &model_object = *m_model->objects[obj_idx];
|
||||
for (int volume_idx = 0; volume_idx < (int)model_object.volumes.size(); ++ volume_idx) {
|
||||
|
@ -804,7 +804,7 @@ public:
|
||||
|
||||
unsigned int get_volumes_count() const;
|
||||
const GLVolumeCollection& get_volumes() const { return m_volumes; }
|
||||
void reset_volumes();
|
||||
void reset_volumes(bool set_notice = true);
|
||||
ModelInstanceEPrintVolumeState check_volumes_outside_state(ObjectFilamentResults* object_results = nullptr) const;
|
||||
bool is_all_plates_selected() { return m_sel_plate_toolbar.m_all_plates_stats_item && m_sel_plate_toolbar.m_all_plates_stats_item->selected; }
|
||||
const float get_scale() const;
|
||||
|
76
src/slic3r/Utils/CpuMemory.cpp
Normal file
76
src/slic3r/Utils/CpuMemory.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
#include "CpuMemory.hpp"
|
||||
|
||||
#include <boost/log/trivial.hpp>
|
||||
namespace Slic3r {
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
unsigned long long get_free_memory_win()
|
||||
{
|
||||
MEMORYSTATUSEX status;
|
||||
status.dwLength = sizeof(status);
|
||||
GlobalMemoryStatusEx(&status);
|
||||
return status.ullAvailPhys;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
#include <unistd.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#elif __APPLE__
|
||||
#include <mach/mach_host.h>
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
unsigned long long get_free_memory_unix()
|
||||
{
|
||||
#ifdef __linux__
|
||||
struct sysinfo info;
|
||||
if (sysinfo(&info) == 0) {
|
||||
return info.freeram * info.mem_unit;
|
||||
}
|
||||
#elif __APPLE__
|
||||
int mib[2] = {CTL_HW, HW_MEMSIZE};
|
||||
uint64_t memsize;
|
||||
size_t len = sizeof(memsize);
|
||||
if (sysctl(mib, 2, &memsize, &len, NULL, 0) == 0) {
|
||||
vm_size_t page_size;
|
||||
mach_port_t mach_port;
|
||||
mach_msg_type_number_t count;
|
||||
vm_statistics64_data_t vm_stats;
|
||||
|
||||
mach_port = mach_host_self();
|
||||
count = sizeof(vm_stats) / sizeof(natural_t);
|
||||
if (host_page_size(mach_port, &page_size) == KERN_SUCCESS && host_statistics64(mach_port, HOST_VM_INFO, (host_info64_t) &vm_stats, &count) == KERN_SUCCESS) {
|
||||
return (vm_stats.free_count + vm_stats.inactive_count) * page_size;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
unsigned long long get_free_memory()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return get_free_memory_win();
|
||||
#elif defined(__linux__) || defined(__APPLE__)
|
||||
return get_free_memory_unix();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
bool CpuMemory::cur_free_memory_less_than_specify_size_gb(int size)
|
||||
{
|
||||
unsigned long long free_mem = get_free_memory();
|
||||
auto cur_size = free_mem / (1024.0 * 1024.0 * 1024.0);
|
||||
static bool first_debug_free_memory = true;
|
||||
if (first_debug_free_memory) {
|
||||
first_debug_free_memory = false;
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " cur_size = " << cur_size << "GB";
|
||||
}
|
||||
if (cur_size > size) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
12
src/slic3r/Utils/CpuMemory.hpp
Normal file
12
src/slic3r/Utils/CpuMemory.hpp
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef slic3r_CpuMemory_hpp_
|
||||
#define slic3r_CpuMemory_hpp_
|
||||
|
||||
namespace Slic3r {
|
||||
#define LOD_FREE_MEMORY_SIZE 5
|
||||
class CpuMemory
|
||||
{
|
||||
public:
|
||||
static bool cur_free_memory_less_than_specify_size_gb(int size);
|
||||
};
|
||||
} // namespace Slic3r
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user