aboutsummaryrefslogtreecommitdiffstats
path: root/Software
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-01-08 15:12:45 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-01-08 15:12:45 +0200
commit65e6368cbe7eeddd02bbd43ae5159ab4b762165f (patch)
treef137a7a2cbcacab1ee3533b5f41c1c388ad32d4f /Software
parente2bf9f578c3ed53d869744f94b020048ca806c6e (diff)
downloadTango-65e6368cbe7eeddd02bbd43ae5159ab4b762165f.tar.gz
Tango-65e6368cbe7eeddd02bbd43ae5159ab4b762165f.zip
Fixed color conversion memory leak by dynamically loading the library. (LoadLibrary, FreeLibrary)
Diffstat (limited to 'Software')
-rw-r--r--Software/DB/Tango.mdfbin75497472 -> 75497472 bytes
-rw-r--r--Software/DB/Tango_log.ldfbin22675456 -> 22675456 bytes
-rw-r--r--Software/Visual_Studio/Tango.BL/ColorConversion/TangoColorConverter.cs55
-rw-r--r--Software/Visual_Studio/Tango.PMR/NativePMR.cs19
4 files changed, 42 insertions, 32 deletions
diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf
index 2468d8559..fda449446 100644
--- a/Software/DB/Tango.mdf
+++ b/Software/DB/Tango.mdf
Binary files differ
diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf
index de658cfa8..ec0a2e6b6 100644
--- a/Software/DB/Tango_log.ldf
+++ b/Software/DB/Tango_log.ldf
Binary files differ
diff --git a/Software/Visual_Studio/Tango.BL/ColorConversion/TangoColorConverter.cs b/Software/Visual_Studio/Tango.BL/ColorConversion/TangoColorConverter.cs
index 776fa7448..e94dd851b 100644
--- a/Software/Visual_Studio/Tango.BL/ColorConversion/TangoColorConverter.cs
+++ b/Software/Visual_Studio/Tango.BL/ColorConversion/TangoColorConverter.cs
@@ -17,16 +17,31 @@ namespace Tango.BL.ColorConversion
{
public static class TangoColorConverter
{
- [DllImport("Tango.ColorLib.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "Convert")]
- private static extern int Convert(IntPtr data, int size, ref IntPtr output);
+ static class NativeMethods
+ {
+ [DllImport("kernel32.dll")]
+ public static extern IntPtr LoadLibrary(string dllToLoad);
- public static ConversionOutput GetSuggestions(BrushStop brushStop)
+ [DllImport("kernel32.dll")]
+ public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
+
+ [DllImport("kernel32.dll")]
+ public static extern bool FreeLibrary(IntPtr hModule);
+ }
+
+ private static ConversionOutput Convert(ConversionInput conversionInput)
{
- ConversionInput conversionInput = CreateConversionInput(brushStop);
+ IntPtr pDll = NativeMethods.LoadLibrary(@"Tango.ColorLib.dll");
+ IntPtr pAddressOfFunctionToCall = NativeMethods.GetProcAddress(pDll, "Convert");
+ NativeMethodDelegate convert = (NativeMethodDelegate)Marshal.GetDelegateForFunctionPointer(
+ pAddressOfFunctionToCall,
+ typeof(NativeMethodDelegate));
- NativePMR<ConversionInput, ConversionOutput> nativePMR = new NativePMR<ConversionInput, ConversionOutput>(Convert);
+ NativePMR<ConversionInput, ConversionOutput> nativePMR = new NativePMR<ConversionInput, ConversionOutput>(convert);
ConversionOutput output = nativePMR.Invoke(conversionInput);
+ bool result = NativeMethods.FreeLibrary(pDll);
+
if (output.HasError)
{
throw new ExternalException($"Color Conversion Error: {output.ErrorMessage}!");
@@ -35,16 +50,16 @@ namespace Tango.BL.ColorConversion
return output;
}
- public static ConversionOutput GetSuggestions(ConversionInput conversionInput)
+ public static ConversionOutput GetSuggestions(BrushStop brushStop)
{
- NativePMR<ConversionInput, ConversionOutput> nativePMR = new NativePMR<ConversionInput, ConversionOutput>(Convert);
- ConversionOutput output = nativePMR.Invoke(conversionInput);
-
- if (output.HasError)
- {
- throw LogManager.Default.Log(new ExternalException($"Color Conversion Error: {output.ErrorMessage}!"), LogCategory.Warning);
- }
+ ConversionInput conversionInput = CreateConversionInput(brushStop);
+ ConversionOutput output = Convert(conversionInput);
+ return output;
+ }
+ public static ConversionOutput GetSuggestions(ConversionInput conversionInput)
+ {
+ ConversionOutput output = Convert(conversionInput);
return output;
}
@@ -59,9 +74,9 @@ namespace Tango.BL.ColorConversion
conversionInput.InputCoordinates.Green = Math.Max((int)color.G, 1);
conversionInput.InputCoordinates.Blue = Math.Max((int)color.B, 1);
- conversionInput.ThreadL = 92.1815;//brushStop.Segment.Job.Rml.MediaColor.L;
- conversionInput.ThreadA = 2.2555;//brushStop.Segment.Job.Rml.MediaColor.A;
- conversionInput.ThreadB = -10.9325;//brushStop.Segment.Job.Rml.MediaColor.B;
+ conversionInput.ThreadL = 92.1815;//brushStop.Segment.Job.Rml.WhitePoint.L;
+ conversionInput.ThreadA = 2.2555;//brushStop.Segment.Job.Rml.WhitePoint.A;
+ conversionInput.ThreadB = -10.9325;//brushStop.Segment.Job.Rml.WhitePoint.B;
conversionInput.ForwardData = ByteString.CopyFrom(job.Rml.Ccts.FirstOrDefault().ForwardData);
@@ -104,13 +119,7 @@ namespace Tango.BL.ColorConversion
});
}
- NativePMR<ConversionInput, ConversionOutput> nativePMR = new NativePMR<ConversionInput, ConversionOutput>(Convert);
- ConversionOutput output = nativePMR.Invoke(conversionInput);
-
- if (output.HasError)
- {
- throw LogManager.Default.Log(new ExternalException($"Color Conversion Error: {output.ErrorMessage}!"), LogCategory.Warning);
- }
+ ConversionOutput output = Convert(conversionInput);
return output;
}
diff --git a/Software/Visual_Studio/Tango.PMR/NativePMR.cs b/Software/Visual_Studio/Tango.PMR/NativePMR.cs
index 14e740656..5666fbeb0 100644
--- a/Software/Visual_Studio/Tango.PMR/NativePMR.cs
+++ b/Software/Visual_Studio/Tango.PMR/NativePMR.cs
@@ -10,6 +10,16 @@ using System.Runtime.ExceptionServices;
namespace Tango.PMR
{
/// <summary>
+ /// Represents a standard C++ protobuf method delegate.
+ /// </summary>
+ /// <param name="requestArray">The request array.</param>
+ /// <param name="requestArraySize">Size of the request array.</param>
+ /// <param name="resultArray">The result array.</param>
+ /// <returns>The size of the result array.</returns>
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate int NativeMethodDelegate(IntPtr requestArray, int requestArraySize, ref IntPtr resultArray);
+
+ /// <summary>
/// Represents a PMR wrapper for invoking native protobuf supported methods.
/// </summary>
/// <typeparam name="Request">The type of the Request.</typeparam>
@@ -28,15 +38,6 @@ namespace Tango.PMR
}
/// <summary>
- /// Represents a standard C++ protobuf method delegate.
- /// </summary>
- /// <param name="requestArray">The request array.</param>
- /// <param name="requestArraySize">Size of the request array.</param>
- /// <param name="resultArray">The result array.</param>
- /// <returns>The size of the result array.</returns>
- public delegate int NativeMethodDelegate(IntPtr requestArray, int requestArraySize, ref IntPtr resultArray);
-
- /// <summary>
/// Invokes the native method with the specified request.
/// </summary>
/// <param name="request">The request.</param>