[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17950] branches/web-plugin/source/ gameengine/GamePlayer/ActiveX-ng: Added Mutex to control m_engineStatus.

Marcelo Coraça de Freitas mfreitas at ydeasolutions.com.br
Fri Dec 19 17:25:53 CET 2008


Revision: 17950
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17950
Author:   mfreitas
Date:     2008-12-19 17:25:50 +0100 (Fri, 19 Dec 2008)

Log Message:
-----------
Added Mutex to control m_engineStatus. 

Without it, in slower machines the plugin launched a big number of blenderplayer instances, causing internet explorer to crash and leave those instances in the memory. Mutex should have solved this.

Modified Paths:
--------------
    branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin/ActiveX PluginCtrl.cpp
    branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin/ActiveX PluginCtrl.h
    branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin/ActiveX Pluginidl.h
    branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin/ActiveXPlugin_i.c
    branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin.suo

Removed Paths:
-------------
    branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin.ncb

Modified: branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin/ActiveX PluginCtrl.cpp
===================================================================
--- branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin/ActiveX PluginCtrl.cpp	2008-12-19 14:14:43 UTC (rev 17949)
+++ branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin/ActiveX PluginCtrl.cpp	2008-12-19 16:25:50 UTC (rev 17950)
@@ -181,7 +181,8 @@
 	 * but could be done.
 	 */
 
-	m_engineStatus = stateStoped;
+	m_engineStatusMutex = CreateMutex( NULL, TRUE, _T("EngineControllerMutex"));
+	setEngineStatus( stateStoped );
 	InternalSetReadyState(READYSTATE_UNINITIALIZED);
 }
 
@@ -196,7 +197,7 @@
 	 * is not running anymore when destroying this marvelous 
 	 * ActiveX control.
 	 */
-	if( m_engineStatus == stateRunning )
+	if( getEngineStatus() == stateRunning )
 		StopEngine();
 }
 
@@ -208,15 +209,24 @@
  */
 void CActiveXPluginCtrl::StartEngine( CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid )
 {
+	
 	int		tmp;
 	TCHAR	argumentsBuffer[500];
 
 	STARTUPINFO		sInfo;
 
+	// we check if we really should go on or not:
+	if( !setEngineStatus( stateRunning ) ) {
+		 // if the status is already stateRunning someone has called this function before
+		return;
+	}
+
+	
+
 	pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(BLACK_BRUSH)));
 
 	if( !m_hWnd ) {
-		m_engineStatus = stateError;
+		setEngineStatus( stateError );
 		return;
 	}
 
@@ -244,22 +254,22 @@
 
 		);
 	if(!tmp) {
-		m_engineStatus = stateError;
+		// if the process couldn't be created, show error.
+		// otherwise, I assume the process is running just fine.
+		setEngineStatus( stateError );
 		// TODO: get the error message
 	}
-	else {
-		m_engineStatus = stateRunning;
-	}
+	
 	// TODO: check if needed:
 	InvalidateControl();
 }
 
 void CActiveXPluginCtrl::StopEngine()
 {
-	if( m_engineStatus == stateRunning ) {
+	if( getEngineStatus() == stateRunning ) {
 		// TODO: use GetExitCodeProcess to set the exit code
 		TerminateProcess( m_pInfo.hProcess, 0 );
-		m_engineStatus = stateStoped;
+		setEngineStatus( stateStoped );
 	}
 	
 }
@@ -271,11 +281,11 @@
 
 	CFileException error;
 	if(!m_blenderFile.Open(&error)) {
-		m_engineStatus = stateError;
+		setEngineStatus( stateError );
 		InternalSetReadyState(READYSTATE_INTERACTIVE);
 	}
 	else {
-		m_engineStatus = stateStoped;
+		setEngineStatus( stateStoped );
 		InternalSetReadyState(READYSTATE_COMPLETE);
 	}
 	InvalidateControl();
@@ -300,6 +310,38 @@
 }
 
 
+
+// TODO: from hereeees
+
+CActiveXPluginCtrl::EngineStatus CActiveXPluginCtrl::getEngineStatus() {
+	EngineStatus st;
+	WaitForSingleObject( m_engineStatusMutex, 5000L );
+		st = m_engineStatus;
+	ReleaseMutex( m_engineStatusMutex );
+	
+	return st;
+}
+	/*
+	 * try to change the engine stats.
+	 * if the given status is the exactly same as the current status, does nothing and
+	 * return false.
+	 * Always use this because of mutexes.
+	 */
+bool CActiveXPluginCtrl::setEngineStatus( EngineStatus engineStatus ){
+	bool ret = true;
+
+	WaitForSingleObject( m_engineStatusMutex, 5000L );
+
+		if( m_engineStatus == engineStatus )
+			ret = false;
+		else
+			m_engineStatus = engineStatus;
+	ReleaseMutex( m_engineStatusMutex );
+
+	return ret;
+}
+
+
 void CActiveXPluginCtrl::log_debug( LPCTSTR msg ) {
 	//MessageBox(msg);
 }
@@ -319,9 +361,9 @@
 		// and if it was a success or a failure
 
 		if( m_blenderFile.m_succeeded )
-			m_engineStatus = stateStoped;
+			setEngineStatus( stateStoped );
 		else
-			m_engineStatus = stateError;
+			setEngineStatus(stateError );
 
 		InvalidateControl();
 		return;
@@ -345,7 +387,7 @@
 			break;
 		case READYSTATE_COMPLETE:
 			//log_debug( _T("complete") );
-			switch( m_engineStatus ) {
+			switch( getEngineStatus() ) {
 				case stateRunning:
 					log_debug( _T("running") );
 					// TODO: check if the process is still running.
@@ -394,7 +436,7 @@
 {
 	COleControl::OnResetState();  // Resets defaults found in DoPropExchange
 
-	m_engineStatus = stateStoped;
+	setEngineStatus( stateStoped );
 	InternalSetReadyState(READYSTATE_UNINITIALIZED);
 }
 

Modified: branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin/ActiveX PluginCtrl.h
===================================================================
--- branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin/ActiveX PluginCtrl.h	2008-12-19 14:14:43 UTC (rev 17949)
+++ branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin/ActiveX PluginCtrl.h	2008-12-19 16:25:50 UTC (rev 17950)
@@ -5,7 +5,6 @@
 #include "BlenderDataPathProperty.h"
 
 
-
 /**
  * Some notes about ReadyState on this control:
  *	READYSTATE_UNITIALIZED :: the control has just been created.
@@ -64,8 +63,9 @@
 		stateError			// it's when something when wrong. TODO: improve error handling
 	} EngineStatus;
 
-
+	
 	EngineStatus m_engineStatus;
+	HANDLE m_engineStatusMutex;
 	PROCESS_INFORMATION	m_pInfo;
 
 	CBlenderDataPathProperty m_blenderFile;	// to download the file
@@ -97,7 +97,20 @@
 	void DrawError( CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid );
 
 
+	/*
+	 * Used to access the engine status.
+	 * Always use this because of mutexes.
+	 */
+	EngineStatus getEngineStatus();
 
+	/*
+	 * try to change the engine stats.
+	 * if the given status is the exactly same as the current status, does nothing and
+	 * return false.
+	 * Always use this because of mutexes.
+	 */
+	bool setEngineStatus( EngineStatus engineStatus );
+
 	BEGIN_OLEFACTORY(CActiveXPluginCtrl)        // Class factory and guid
 		virtual BOOL VerifyUserLicense();
 		virtual BOOL GetLicenseKey(DWORD, BSTR FAR*);

Modified: branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin/ActiveX Pluginidl.h
===================================================================
--- branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin/ActiveX Pluginidl.h	2008-12-19 14:14:43 UTC (rev 17949)
+++ branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin/ActiveX Pluginidl.h	2008-12-19 16:25:50 UTC (rev 17950)
@@ -4,7 +4,7 @@
 
 
  /* File created by MIDL compiler version 7.00.0500 */
-/* at Wed Nov 19 15:37:00 2008
+/* at Fri Dec 19 14:09:18 2008
  */
 /* Compiler settings for .\ActiveXPlugin.idl:
     Oicf, W1, Zp8, env=Win32 (32b run)

Modified: branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin/ActiveXPlugin_i.c
===================================================================
--- branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin/ActiveXPlugin_i.c	2008-12-19 14:14:43 UTC (rev 17949)
+++ branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin/ActiveXPlugin_i.c	2008-12-19 16:25:50 UTC (rev 17950)
@@ -6,7 +6,7 @@
 
 
  /* File created by MIDL compiler version 7.00.0500 */
-/* at Wed Nov 19 15:37:00 2008
+/* at Fri Dec 19 14:09:18 2008
  */
 /* Compiler settings for .\ActiveXPlugin.idl:
     Oicf, W1, Zp8, env=Win32 (32b run)

Deleted: branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin.ncb
===================================================================
(Binary files differ)

Modified: branches/web-plugin/source/gameengine/GamePlayer/ActiveX-ng/ActiveX Plugin.suo
===================================================================
(Binary files differ)





More information about the Bf-blender-cvs mailing list