mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 04:31:15 -06:00 
			
		
		
		
	Fixed a memory leak during locales switching on macOS and
removed frequent locales switching during gcode processing
This commit is contained in:
		
							parent
							
								
									d8ac2ceaf6
								
							
						
					
					
						commit
						d2874f2e34
					
				
					 4 changed files with 11 additions and 10 deletions
				
			
		|  | @ -720,6 +720,8 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessor::Result* re | |||
| { | ||||
|     PROFILE_CLEAR(); | ||||
| 
 | ||||
|     CNumericLocalesSetter locales_setter; | ||||
| 
 | ||||
|     // Does the file exist? If so, we hope that it is still valid.
 | ||||
|     if (print->is_step_done(psGCodeExport) && boost::filesystem::exists(boost::filesystem::path(path))) | ||||
|         return; | ||||
|  | @ -750,7 +752,6 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessor::Result* re | |||
|     std::string path_tmp(path); | ||||
|     path_tmp += ".tmp"; | ||||
| 
 | ||||
|     CNumericLocalesSetter c_locales_setter; | ||||
|     FILE *file = boost::nowide::fopen(path_tmp.c_str(), "wb"); | ||||
|     if (file == nullptr) | ||||
|         throw Slic3r::RuntimeError(std::string("G-code export to ") + path + " failed.\nCannot open the file for writing.\n"); | ||||
|  |  | |||
|  | @ -1257,6 +1257,8 @@ void GCodeProcessor::process_file(const std::string& filename, bool apply_postpr | |||
| { | ||||
|     auto last_cancel_callback_time = std::chrono::high_resolution_clock::now(); | ||||
| 
 | ||||
|     CNumericLocalesSetter locales_setter; | ||||
| 
 | ||||
| #if ENABLE_GCODE_VIEWER_STATISTICS | ||||
|     auto start_time = std::chrono::high_resolution_clock::now(); | ||||
| #endif // ENABLE_GCODE_VIEWER_STATISTICS
 | ||||
|  |  | |||
|  | @ -27,7 +27,8 @@ void GCodeReader::apply_config(const DynamicPrintConfig &config) | |||
| const char* GCodeReader::parse_line_internal(const char *ptr, GCodeLine &gline, std::pair<const char*, const char*> &command) | ||||
| { | ||||
|     PROFILE_FUNC(); | ||||
|     CNumericLocalesSetter locales_setter; // for strtod
 | ||||
| 
 | ||||
|     assert(is_decimal_separator_point()); | ||||
|      | ||||
|     // command and args
 | ||||
|     const char *c = ptr; | ||||
|  | @ -153,7 +154,7 @@ bool GCodeReader::GCodeLine::has(char axis) const | |||
| 
 | ||||
| bool GCodeReader::GCodeLine::has_value(char axis, float &value) const | ||||
| { | ||||
|     CNumericLocalesSetter locales_setter; // for strtod
 | ||||
|     assert(is_decimal_separator_point()); | ||||
|     const char *c = m_raw.c_str(); | ||||
|     // Skip the whitespaces.
 | ||||
|     c = skip_whitespaces(c); | ||||
|  |  | |||
|  | @ -11,11 +11,14 @@ CNumericLocalesSetter::CNumericLocalesSetter() | |||
|     _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); | ||||
|     m_orig_numeric_locale = std::setlocale(LC_NUMERIC, nullptr); | ||||
|     std::setlocale(LC_NUMERIC, "C"); | ||||
| #else | ||||
| #elif __linux__ | ||||
|     m_original_locale = uselocale((locale_t)0); | ||||
|     m_new_locale = duplocale(m_original_locale); | ||||
|     m_new_locale = newlocale(LC_NUMERIC_MASK, "C", m_new_locale); | ||||
|     uselocale(m_new_locale); | ||||
| #else // APPLE
 | ||||
|     m_original_locale = uselocale((locale_t)0); | ||||
|     m_new_locale = newlocale(LC_NUMERIC_MASK, "C", m_original_locale); | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
|  | @ -58,7 +61,6 @@ double string_to_double_decimal_point(const std::string& str, size_t* pos /* = n | |||
| 
 | ||||
| std::string float_to_string_decimal_point(double value, int precision/* = -1*/) | ||||
| { | ||||
|     assert(is_decimal_separator_point()); | ||||
|     std::stringstream buf; | ||||
|     if (precision >= 0) | ||||
|         buf << std::fixed << std::setprecision(precision); | ||||
|  | @ -66,11 +68,6 @@ std::string float_to_string_decimal_point(double value, int precision/* = -1*/) | |||
|     return buf.str(); | ||||
| } | ||||
| 
 | ||||
| //std::string float_to_string_decimal_point(float value, int precision/* = -1*/)
 | ||||
| //{
 | ||||
| //    return float_to_string_decimal_point(double(value), precision);
 | ||||
| //}
 | ||||
| 
 | ||||
| 
 | ||||
| } // namespace Slic3r
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lukas Matena
						Lukas Matena