Counting the amount of surface objects, so we can see if there are multiple in memory when we have bugs.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2365 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-12-07 15:12:04 +00:00
parent 1a471ec77f
commit 83d244c3bf
5 changed files with 116 additions and 140 deletions

View file

@ -45,6 +45,7 @@ namespace Greenshot.Drawing {
/// </summary> /// </summary>
public class Surface : Control, ISurface { public class Surface : Control, ISurface {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(Surface)); private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(Surface));
public static int Count = 0;
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>(); private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
/// <summary> /// <summary>
@ -360,7 +361,8 @@ namespace Greenshot.Drawing {
/// Base Surface constructor /// Base Surface constructor
/// </summary> /// </summary>
public Surface() : base(){ public Surface() : base(){
LOG.Debug("Creating a surface!"); Count++;
LOG.Debug("Creating surface!");
this.MouseDown += new MouseEventHandler(SurfaceMouseDown); this.MouseDown += new MouseEventHandler(SurfaceMouseDown);
this.MouseUp += new MouseEventHandler(SurfaceMouseUp); this.MouseUp += new MouseEventHandler(SurfaceMouseUp);
this.MouseMove += new MouseEventHandler(SurfaceMouseMove); this.MouseMove += new MouseEventHandler(SurfaceMouseMove);
@ -427,7 +429,8 @@ namespace Greenshot.Drawing {
/// Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice /// Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
/// </summary> /// </summary>
public new void Dispose() { public new void Dispose() {
LOG.Debug("Disposing a surface!"); Count--;
LOG.Debug("Disposing surface!");
if (buffer != null) { if (buffer != null) {
buffer.Dispose(); buffer.Dispose();
buffer = null; buffer = null;
@ -438,10 +441,10 @@ namespace Greenshot.Drawing {
} }
// Cleanup undo/redo stacks // Cleanup undo/redo stacks
while(undoStack != null && undoStack.Count > 0) { while (undoStack != null && undoStack.Count > 0) {
undoStack.Pop().Dispose(); undoStack.Pop().Dispose();
} }
while(redoStack != null && redoStack.Count > 0) { while (redoStack != null && redoStack.Count > 0) {
redoStack.Pop().Dispose(); redoStack.Pop().Dispose();
} }
base.Dispose(); base.Dispose();

View file

@ -33,6 +33,7 @@ namespace Greenshot {
/// Description of AboutForm. /// Description of AboutForm.
/// </summary> /// </summary>
public partial class AboutForm : BaseForm { public partial class AboutForm : BaseForm {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(AboutForm));
public AboutForm() { public AboutForm() {
// //
// The InitializeComponent() call is required for Windows Forms designer support. // The InitializeComponent() call is required for Windows Forms designer support.
@ -88,7 +89,8 @@ namespace Greenshot {
default: default:
return base.ProcessCmdKey(ref msg, keyData); return base.ProcessCmdKey(ref msg, keyData);
} }
} catch (Exception) { } catch (Exception ex) {
LOG.Error(string.Format("Error handling key '{0}'", keyData), ex);
} }
return true; return true;
} }

View file

@ -67,11 +67,15 @@ namespace Greenshot {
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
// Initialize the IniConfig
IniConfig.Init();
// Log the startup // Log the startup
LOG.Info("Starting: " + EnvironmentInfo.EnvironmentToString(false)); LOG.Info("Starting: " + EnvironmentInfo.EnvironmentToString(false));
IniConfig.Init(); // Upgrade if needed
AppConfig.UpgradeToIni(); AppConfig.UpgradeToIni();
// Read configuration // Read configuration
conf = IniConfig.GetIniSection<CoreConfiguration>(); conf = IniConfig.GetIniSection<CoreConfiguration>();
try { try {

View file

@ -28,6 +28,7 @@ using System.Windows.Forms;
using GreenshotPlugin.UnmanagedHelpers; using GreenshotPlugin.UnmanagedHelpers;
using GreenshotPlugin.Core; using GreenshotPlugin.Core;
using Greenshot.IniFile; using Greenshot.IniFile;
using Greenshot.Drawing;
namespace Greenshot.Helpers { namespace Greenshot.Helpers {
/// <summary> /// <summary>
@ -46,14 +47,14 @@ namespace Greenshot.Helpers {
return isWindows.Value; return isWindows.Value;
} }
} }
public static string EnvironmentToString(bool newline) { public static string EnvironmentToString(bool newline) {
StringBuilder environment = new StringBuilder(); StringBuilder environment = new StringBuilder();
environment.Append("Software version: " + Application.ProductVersion); environment.Append("Software version: " + Application.ProductVersion);
if (IniConfig.IsPortable) { if (IniConfig.IsPortable) {
environment.Append(" Portable"); environment.Append(" Portable");
} }
environment.Append(" (" + OSInfo.Bits +" bit)"); environment.Append(" (" + OSInfo.Bits + " bit)");
if (newline) { if (newline) {
environment.AppendLine(); environment.AppendLine();
@ -67,51 +68,57 @@ namespace Greenshot.Helpers {
environment.Append(", "); environment.Append(", ");
} }
environment.Append("Time: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss zzz")); environment.Append("Time: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss zzz"));
if (IsWindows) {
if (newline) {
environment.AppendLine();
} else {
environment.Append(", ");
}
environment.Append(String.Format("OS: {0} {1} {2} (x{3}) {4}", OSInfo.Name, OSInfo.Edition, OSInfo.ServicePack, OSInfo.Bits, OSInfo.VersionString));
if (newline) {
environment.AppendLine();
} else {
environment.Append(", ");
}
// Get some important information for fixing GDI related Problems
environment.Append("GDI object count: " + User32.GetGuiResourcesGDICount());
if (newline) {
environment.AppendLine();
} else {
environment.Append(", ");
}
environment.Append("User object count: " + User32.GetGuiResourcesUserCount());
} else {
if (newline) {
environment.AppendLine();
} else {
environment.Append(", ");
}
environment.Append("OS: " + Environment.OSVersion.Platform.ToString());
}
if (newline) { if (newline) {
environment.AppendLine(); environment.AppendLine();
} else { } else {
environment.Append(", "); environment.Append(", ");
} }
environment.Append("Surface count: " + Surface.Count);
if (IsWindows) {
environment.Append(String.Format("OS: {0} {1} {2} (x{3}) {4}", OSInfo.Name, OSInfo.Edition, OSInfo.ServicePack, OSInfo.Bits, OSInfo.VersionString));
if (newline) {
environment.AppendLine();
} else {
environment.Append(", ");
}
// Get some important information for fixing GDI related Problems
environment.Append("GDI object count: " + User32.GetGuiResourcesGDICount());
if (newline) {
environment.AppendLine();
} else {
environment.Append(", ");
}
environment.Append("User object count: " + User32.GetGuiResourcesUserCount());
} else {
environment.Append("OS: " + Environment.OSVersion.Platform.ToString());
if (newline) {
environment.AppendLine();
} else {
environment.Append(", ");
}
}
return environment.ToString(); return environment.ToString();
} }
public static string ExceptionToString(Exception ex) { public static string ExceptionToString(Exception ex) {
if (ex == null) if (ex == null)
return "null\r\n"; return "null\r\n";
StringBuilder report = new StringBuilder(); StringBuilder report = new StringBuilder();
report.AppendLine("Exception: " + ex.GetType().ToString()); report.AppendLine("Exception: " + ex.GetType().ToString());
report.AppendLine("Message: " + ex.Message); report.AppendLine("Message: " + ex.Message);
if (ex.Data != null && ex.Data.Count > 0) { if (ex.Data != null && ex.Data.Count > 0) {
report.AppendLine(); report.AppendLine();
report.AppendLine("Additional Information:"); report.AppendLine("Additional Information:");
foreach(object key in ex.Data.Keys) { foreach (object key in ex.Data.Keys) {
object data = ex.Data[key]; object data = ex.Data[key];
if (data != null) { if (data != null) {
report.AppendLine(key + " = " + data); report.AppendLine(key + " = " + data);
@ -125,9 +132,9 @@ namespace Greenshot.Helpers {
report.AppendLine().AppendLine("Stack:").AppendLine(ex.StackTrace); report.AppendLine().AppendLine("Stack:").AppendLine(ex.StackTrace);
if(ex is ReflectionTypeLoadException) { if (ex is ReflectionTypeLoadException) {
report.AppendLine().AppendLine("LoaderExceptions: "); report.AppendLine().AppendLine("LoaderExceptions: ");
foreach(Exception cbE in (ex as ReflectionTypeLoadException).LoaderExceptions) { foreach (Exception cbE in (ex as ReflectionTypeLoadException).LoaderExceptions) {
report.AppendLine(cbE.Message); report.AppendLine(cbE.Message);
} }
} }
@ -138,7 +145,7 @@ namespace Greenshot.Helpers {
} }
return report.ToString(); return report.ToString();
} }
public static string BuildReport(Exception exception) { public static string BuildReport(Exception exception) {
StringBuilder exceptionText = new StringBuilder(); StringBuilder exceptionText = new StringBuilder();
exceptionText.AppendLine(EnvironmentInfo.EnvironmentToString(true)); exceptionText.AppendLine(EnvironmentInfo.EnvironmentToString(true));
@ -147,7 +154,7 @@ namespace Greenshot.Helpers {
using (TextWriter writer = new StringWriter(exceptionText)) { using (TextWriter writer = new StringWriter(exceptionText)) {
IniConfig.GetIniSection<CoreConfiguration>().Write(writer, true); IniConfig.GetIniSection<CoreConfiguration>().Write(writer, true);
} }
return exceptionText.ToString(); return exceptionText.ToString();
} }
} }
@ -162,8 +169,7 @@ namespace Greenshot.Helpers {
/// Determines if the current application is 32 or 64-bit. /// Determines if the current application is 32 or 64-bit.
/// </summary> /// </summary>
static public int Bits { static public int Bits {
get get {
{
return IntPtr.Size * 8; return IntPtr.Size * 8;
} }
} }
@ -176,39 +182,32 @@ namespace Greenshot.Helpers {
/// </summary> /// </summary>
static public string Edition { static public string Edition {
get { get {
if (s_Edition != null) { if (s_Edition != null) {
return s_Edition; //***** RETURN *****// return s_Edition; //***** RETURN *****//
} }
string edition = String.Empty; string edition = String.Empty;
OperatingSystem osVersion = Environment.OSVersion; OperatingSystem osVersion = Environment.OSVersion;
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX(); OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX();
osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf( typeof( OSVERSIONINFOEX ) ); osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX));
if (GetVersionEx( ref osVersionInfo )) { if (GetVersionEx(ref osVersionInfo)) {
int majorVersion = osVersion.Version.Major; int majorVersion = osVersion.Version.Major;
int minorVersion = osVersion.Version.Minor; int minorVersion = osVersion.Version.Minor;
byte productType = osVersionInfo.wProductType; byte productType = osVersionInfo.wProductType;
short suiteMask = osVersionInfo.wSuiteMask; short suiteMask = osVersionInfo.wSuiteMask;
#region VERSION 4 #region VERSION 4
if (majorVersion == 4) if (majorVersion == 4) {
{ if (productType == VER_NT_WORKSTATION) {
if (productType == VER_NT_WORKSTATION)
{
// Windows NT 4.0 Workstation // Windows NT 4.0 Workstation
edition = "Workstation"; edition = "Workstation";
} } else if (productType == VER_NT_SERVER) {
else if (productType == VER_NT_SERVER) if ((suiteMask & VER_SUITE_ENTERPRISE) != 0) {
{
if ((suiteMask & VER_SUITE_ENTERPRISE) != 0)
{
// Windows NT 4.0 Server Enterprise // Windows NT 4.0 Server Enterprise
edition = "Enterprise Server"; edition = "Enterprise Server";
} } else {
else
{
// Windows NT 4.0 Server // Windows NT 4.0 Server
edition = "Standard Server"; edition = "Standard Server";
} }
@ -217,60 +216,38 @@ namespace Greenshot.Helpers {
#endregion VERSION 4 #endregion VERSION 4
#region VERSION 5 #region VERSION 5
else if (majorVersion == 5) else if (majorVersion == 5) {
{ if (productType == VER_NT_WORKSTATION) {
if (productType == VER_NT_WORKSTATION) if ((suiteMask & VER_SUITE_PERSONAL) != 0) {
{
if ((suiteMask & VER_SUITE_PERSONAL) != 0)
{
// Windows XP Home Edition // Windows XP Home Edition
edition = "Home"; edition = "Home";
} } else {
else
{
// Windows XP / Windows 2000 Professional // Windows XP / Windows 2000 Professional
edition = "Professional"; edition = "Professional";
} }
} } else if (productType == VER_NT_SERVER) {
else if (productType == VER_NT_SERVER) if (minorVersion == 0) {
{ if ((suiteMask & VER_SUITE_DATACENTER) != 0) {
if (minorVersion == 0)
{
if ((suiteMask & VER_SUITE_DATACENTER) != 0)
{
// Windows 2000 Datacenter Server // Windows 2000 Datacenter Server
edition = "Datacenter Server"; edition = "Datacenter Server";
} } else if ((suiteMask & VER_SUITE_ENTERPRISE) != 0) {
else if ((suiteMask & VER_SUITE_ENTERPRISE) != 0)
{
// Windows 2000 Advanced Server // Windows 2000 Advanced Server
edition = "Advanced Server"; edition = "Advanced Server";
} } else {
else
{
// Windows 2000 Server // Windows 2000 Server
edition = "Server"; edition = "Server";
} }
} } else {
else if ((suiteMask & VER_SUITE_DATACENTER) != 0) {
{
if ((suiteMask & VER_SUITE_DATACENTER) != 0)
{
// Windows Server 2003 Datacenter Edition // Windows Server 2003 Datacenter Edition
edition = "Datacenter"; edition = "Datacenter";
} } else if ((suiteMask & VER_SUITE_ENTERPRISE) != 0) {
else if ((suiteMask & VER_SUITE_ENTERPRISE) != 0)
{
// Windows Server 2003 Enterprise Edition // Windows Server 2003 Enterprise Edition
edition = "Enterprise"; edition = "Enterprise";
} } else if ((suiteMask & VER_SUITE_BLADE) != 0) {
else if ((suiteMask & VER_SUITE_BLADE) != 0)
{
// Windows Server 2003 Web Edition // Windows Server 2003 Web Edition
edition = "Web Edition"; edition = "Web Edition";
} } else {
else
{
// Windows Server 2003 Standard Edition // Windows Server 2003 Standard Edition
edition = "Standard"; edition = "Standard";
} }
@ -280,13 +257,10 @@ namespace Greenshot.Helpers {
#endregion VERSION 5 #endregion VERSION 5
#region VERSION 6 #region VERSION 6
else if (majorVersion == 6) else if (majorVersion == 6) {
{
int ed; int ed;
if (GetProductInfo( majorVersion, minorVersion, osVersionInfo.wServicePackMajor, osVersionInfo.wServicePackMinor, out ed )) if (GetProductInfo(majorVersion, minorVersion, osVersionInfo.wServicePackMajor, osVersionInfo.wServicePackMinor, out ed)) {
{ switch (ed) {
switch (ed)
{
case PRODUCT_BUSINESS: case PRODUCT_BUSINESS:
edition = "Business"; edition = "Business";
break; break;
@ -425,9 +399,9 @@ namespace Greenshot.Helpers {
OperatingSystem osVersion = Environment.OSVersion; OperatingSystem osVersion = Environment.OSVersion;
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX(); OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX();
osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf( typeof( OSVERSIONINFOEX ) ); osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX));
if (GetVersionEx( ref osVersionInfo )) { if (GetVersionEx(ref osVersionInfo)) {
int majorVersion = osVersion.Version.Major; int majorVersion = osVersion.Version.Major;
int minorVersion = osVersion.Version.Minor; int minorVersion = osVersion.Version.Minor;
byte productType = osVersionInfo.wProductType; byte productType = osVersionInfo.wProductType;
@ -501,7 +475,7 @@ namespace Greenshot.Helpers {
case 0x0400: case 0x0400:
name = "Windows Server 2003 Web Edition"; name = "Windows Server 2003 Web Edition";
break; break;
case unchecked ((short)0x8000): case unchecked((short)0x8000):
name = "Windows Home Server"; name = "Windows Home Server";
break; break;
default: default:
@ -552,31 +526,30 @@ namespace Greenshot.Helpers {
#region PINVOKE #region PINVOKE
#region GET #region GET
#region PRODUCT INFO #region PRODUCT INFO
[DllImport( "Kernel32.dll" )] [DllImport("Kernel32.dll")]
internal static extern bool GetProductInfo( internal static extern bool GetProductInfo(
int osMajorVersion, int osMajorVersion,
int osMinorVersion, int osMinorVersion,
int spMajorVersion, int spMajorVersion,
int spMinorVersion, int spMinorVersion,
out int edition ); out int edition);
#endregion PRODUCT INFO #endregion PRODUCT INFO
#region VERSION #region VERSION
[DllImport( "kernel32.dll" )] [DllImport("kernel32.dll")]
private static extern bool GetVersionEx( ref OSVERSIONINFOEX osVersionInfo ); private static extern bool GetVersionEx(ref OSVERSIONINFOEX osVersionInfo);
#endregion VERSION #endregion VERSION
#endregion GET #endregion GET
#region OSVERSIONINFOEX #region OSVERSIONINFOEX
[StructLayout( LayoutKind.Sequential )] [StructLayout(LayoutKind.Sequential)]
private struct OSVERSIONINFOEX private struct OSVERSIONINFOEX {
{
public int dwOSVersionInfoSize; public int dwOSVersionInfoSize;
public int dwMajorVersion; public int dwMajorVersion;
public int dwMinorVersion; public int dwMinorVersion;
public int dwBuildNumber; public int dwBuildNumber;
public int dwPlatformId; public int dwPlatformId;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst = 128 )] [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szCSDVersion; public string szCSDVersion;
public short wServicePackMajor; public short wServicePackMajor;
public short wServicePackMinor; public short wServicePackMinor;
@ -646,17 +619,14 @@ namespace Greenshot.Helpers {
/// <summary> /// <summary>
/// Gets the service pack information of the operating system running on this computer. /// Gets the service pack information of the operating system running on this computer.
/// </summary> /// </summary>
static public string ServicePack static public string ServicePack {
{ get {
get
{
string servicePack = String.Empty; string servicePack = String.Empty;
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX(); OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX();
osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf( typeof( OSVERSIONINFOEX ) ); osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX));
if (GetVersionEx( ref osVersionInfo )) if (GetVersionEx(ref osVersionInfo)) {
{
servicePack = osVersionInfo.szCSDVersion; servicePack = osVersionInfo.szCSDVersion;
} }
@ -670,9 +640,9 @@ namespace Greenshot.Helpers {
/// <summary> /// <summary>
/// Gets the build version number of the operating system running on this computer. /// Gets the build version number of the operating system running on this computer.
/// </summary> /// </summary>
public static int BuildVersion { public static int BuildVersion {
get { get {
return Environment.OSVersion.Version.Build; return Environment.OSVersion.Version.Build;
} }
} }
#endregion BUILD #endregion BUILD
@ -693,10 +663,8 @@ namespace Greenshot.Helpers {
/// <summary> /// <summary>
/// Gets the full version of the operating system running on this computer. /// Gets the full version of the operating system running on this computer.
/// </summary> /// </summary>
static public Version Version static public Version Version {
{ get {
get
{
return Environment.OSVersion.Version; return Environment.OSVersion.Version;
} }
} }
@ -707,10 +675,8 @@ namespace Greenshot.Helpers {
/// <summary> /// <summary>
/// Gets the major version number of the operating system running on this computer. /// Gets the major version number of the operating system running on this computer.
/// </summary> /// </summary>
static public int MajorVersion static public int MajorVersion {
{ get {
get
{
return Environment.OSVersion.Version.Major; return Environment.OSVersion.Version.Major;
} }
} }
@ -720,10 +686,8 @@ namespace Greenshot.Helpers {
/// <summary> /// <summary>
/// Gets the minor version number of the operating system running on this computer. /// Gets the minor version number of the operating system running on this computer.
/// </summary> /// </summary>
static public int MinorVersion static public int MinorVersion {
{ get {
get
{
return Environment.OSVersion.Version.Minor; return Environment.OSVersion.Version.Minor;
} }
} }
@ -733,10 +697,8 @@ namespace Greenshot.Helpers {
/// <summary> /// <summary>
/// Gets the revision version number of the operating system running on this computer. /// Gets the revision version number of the operating system running on this computer.
/// </summary> /// </summary>
static public int RevisionVersion static public int RevisionVersion {
{ get {
get
{
return Environment.OSVersion.Version.Revision; return Environment.OSVersion.Version.Revision;
} }
} }

View file

@ -305,7 +305,12 @@ namespace Greenshot.IniFile {
Value = defaultValueFromConfig; Value = defaultValueFromConfig;
return; return;
} }
Value = Activator.CreateInstance(ValueType); try {
Value = Activator.CreateInstance(ValueType);
} catch (Exception) {
LOG.WarnFormat("Couldn't create instance of {0} for {1}, using default value.", ValueType.FullName, attributes.Name);
Value = default(ValueType);
}
} }
/// <summary> /// <summary>