[longomatch] Try to fix some memory leaks handling Pxibuf's



commit bc2ce6b39564acb54a890dfe8c04b767117105e0
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Thu Oct 15 10:53:56 2009 +0200

    Try to fix some memory leaks handling Pxibuf's

 CesarPlayer/Gui/PlayerBin.cs                |   24 +++---------------------
 CesarPlayer/Handlers/Handlers.cs            |    2 +-
 LongoMatch/Gui/Component/DrawingWidget.cs   |    5 +++++
 LongoMatch/Gui/Dialog/DrawingTool.cs        |    4 ++++
 LongoMatch/Gui/MainWindow.cs                |    2 +-
 LongoMatch/Handlers/EventsManager.cs        |   17 ++++++++++++++---
 LongoMatch/Handlers/VideoDrawingsManager.cs |    7 +++++--
 7 files changed, 33 insertions(+), 28 deletions(-)
---
diff --git a/CesarPlayer/Gui/PlayerBin.cs b/CesarPlayer/Gui/PlayerBin.cs
index 8f66d69..0edc86d 100644
--- a/CesarPlayer/Gui/PlayerBin.cs
+++ b/CesarPlayer/Gui/PlayerBin.cs
@@ -117,10 +117,7 @@ namespace LongoMatch.Gui
 		}
 		
 		public Pixbuf CurrentFrame{
-			get{
-				Pixbuf pixbuf = player.GetCurrentFrame();				
-				return pixbuf;
-			}
+			get{return player.GetCurrentFrame();}
 		}
 		
 		public Pixbuf LogoPixbuf{
@@ -534,23 +531,8 @@ namespace LongoMatch.Gui
 		{
 			int currentTime;
 			Pixbuf frame=null;
-			if (DrawFrame != null){
-				if (!InSegment())
-					DrawFrame(CurrentFrame,(int)AccurateCurrentTime);
-				else {
-					//We need an extra acurracy and we have to grant the frame 
-					//correspond to the instant we are assigning to this frame
-					//This process should be the same when when retrieving the 
-					//frame to paint over the drawings
-					currentTime = (int)AccurateCurrentTime;
-					Pause();
-					SeekInSegment(currentTime);
-					 //We have to wait untill the seek event is done to get a valid frame
-					while (frame == null)
-						frame = CurrentFrame;
-					DrawFrame(frame,currentTime);
-				}				
-			}				
+			if (DrawFrame != null)
+				DrawFrame((int)AccurateCurrentTime);
 		}
 #endregion	
 	}
diff --git a/CesarPlayer/Handlers/Handlers.cs b/CesarPlayer/Handlers/Handlers.cs
index 2460ff1..32d84ca 100644
--- a/CesarPlayer/Handlers/Handlers.cs
+++ b/CesarPlayer/Handlers/Handlers.cs
@@ -33,7 +33,7 @@ namespace LongoMatch.Video.Handlers
 	public delegate void PrevButtonClickedHandler ();
 	public delegate void ProgressHandler (float progress);
 	public delegate void FramesProgressHandler (int actual, int total,Pixbuf frame);
-	public delegate void DrawFrameHandler (Pixbuf frame,int time);
+	public delegate void DrawFrameHandler (int time);
 
 	
 	
diff --git a/LongoMatch/Gui/Component/DrawingWidget.cs b/LongoMatch/Gui/Component/DrawingWidget.cs
index e611984..99b9adc 100644
--- a/LongoMatch/Gui/Component/DrawingWidget.cs
+++ b/LongoMatch/Gui/Component/DrawingWidget.cs
@@ -76,6 +76,11 @@ namespace LongoMatch.Gui.Component
 			preview=false;
 		}
 		
+		~DrawingWidget(){
+			source.Destroy();
+			drawings.Destroy();
+		}
+
 		public Pixbuf SourceImage{
 			set{
 				sourceWidth = value.Width;
diff --git a/LongoMatch/Gui/Dialog/DrawingTool.cs b/LongoMatch/Gui/Dialog/DrawingTool.cs
index 855bbac..c14f048 100644
--- a/LongoMatch/Gui/Dialog/DrawingTool.cs
+++ b/LongoMatch/Gui/Dialog/DrawingTool.cs
@@ -41,6 +41,10 @@ namespace LongoMatch.Gui.Dialog
 			drawingtoolbox1.InfoVisible = false;
 		}
 		
+		~ DrawingTool(){
+			drawingwidget1.Destroy();
+		}
+		
 		public Pixbuf Image{
 			set{drawingwidget1.SourceImage = value;}
 		}
diff --git a/LongoMatch/Gui/MainWindow.cs b/LongoMatch/Gui/MainWindow.cs
index d838a02..5bd73d7 100644
--- a/LongoMatch/Gui/MainWindow.cs
+++ b/LongoMatch/Gui/MainWindow.cs
@@ -56,7 +56,7 @@ namespace LongoMatch.Gui
 				base("LongoMatch")
 		{	
 			this.Build();
-			
+
 			/*Updater updater = new Updater();
 			updater.NewVersion += new LongoMatch.Handlers.NewVersionHandler(OnUpdate);
 			updater.Run();*/
diff --git a/LongoMatch/Handlers/EventsManager.cs b/LongoMatch/Handlers/EventsManager.cs
index e9a6918..f3efd15 100644
--- a/LongoMatch/Handlers/EventsManager.cs
+++ b/LongoMatch/Handlers/EventsManager.cs
@@ -27,6 +27,7 @@ using LongoMatch.Video.Player;
 using LongoMatch.Video.Handlers;
 using LongoMatch.Video.Utils;
 using LongoMatch.Video.Editor;
+using LongoMatch.Video;
 using LongoMatch.Handlers;
 using LongoMatch.Gui;
 using Gtk;
@@ -324,17 +325,27 @@ namespace LongoMatch
 			plNode.Rate = player.Rate;
 		}
 		
-		protected virtual void OnDrawFrame (Pixbuf pixbuf,int time){
+		protected virtual void OnDrawFrame (int time){
+			Pixbuf pixbuf=null;
+			IFramesCapturer capturer;
 			DrawingTool dialog = new DrawingTool();
-			dialog.TransientFor = (Gtk.Window)player.Toplevel;
+			
+			if (selectedTimeNode == null)
+				player.SeekTo(time,true);
+			else
+				player.SeekTo(time,true);
+			while (pixbuf == null)
+				pixbuf = player.CurrentFrame;
+				
 			dialog.Image = pixbuf;
+			dialog.TransientFor = (Gtk.Window)player.Toplevel;
 			if (selectedTimeNode != null)
 				dialog.SetPlay((selectedTimeNode as MediaTimeNode),
 				                time);
 			player.Pause();
+			pixbuf.Dispose();
 			dialog.Run();
 			dialog.Destroy();
-			pixbuf.Dispose();
 		}
 		
 		protected virtual void OnPlayersTagged (MediaTimeNode tNode, Team team){
diff --git a/LongoMatch/Handlers/VideoDrawingsManager.cs b/LongoMatch/Handlers/VideoDrawingsManager.cs
index 219b2fd..23a929d 100644
--- a/LongoMatch/Handlers/VideoDrawingsManager.cs
+++ b/LongoMatch/Handlers/VideoDrawingsManager.cs
@@ -93,17 +93,20 @@ namespace LongoMatch.Handlers
 				
 		private void PrintDrawing(){
 			Pixbuf frame = null;
+			Pixbuf drawing = null;
 
 			player.Pause();
 			player.SeekInSegment(Drawing.StopTime);
 			while (frame == null)
 				frame = player.CurrentFrame;			
 			player.LogoPixbuf = frame;
-			frame.Dispose();
-			player.DrawingPixbuf = Drawing.Pixbuf;
+			drawing = Drawing.Pixbuf;
+			player.DrawingPixbuf = drawing; 
 			player.LogoMode = true;
 			player.DrawingMode = true;
 			inKeyFrame = true;
+			frame.Dispose();
+			drawing.Dispose();
 		}
 		
 		private void ResetPlayerWindow(){



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]