Browse Source

Fixed potential crash in TUIO module, exposed eventMutex in Core

Ivan Safrin 13 năm trước cách đây
mục cha
commit
83f843670e

+ 1 - 3
Core/Contents/Include/PolyCocoaCore.h

@@ -137,9 +137,7 @@ namespace Polycode {
 		vector<Rectangle> getVideoModes();
 		vector<Rectangle> getVideoModes();
 		
 		
 		int lastMouseY;
 		int lastMouseY;
-		int lastMouseX;		
-		
-		CoreMutex *eventMutex;
+		int lastMouseX;				
 		
 		
 		vector<CocoaEvent> cocoaEvents;
 		vector<CocoaEvent> cocoaEvents;
 		
 		

+ 5 - 2
Core/Contents/Include/PolyCore.h

@@ -308,9 +308,12 @@ namespace Polycode {
 		/**
 		/**
 		* Returns the default working path of the application.
 		* Returns the default working path of the application.
 		*/
 		*/
-		String getUserHomeDirectory();		
+		String getUserHomeDirectory();	
 		
 		
-	protected:
+		CoreMutex *getEventMutex();
+		CoreMutex *eventMutex;
+				
+	protected:	
 		
 		
 		String userHomeDirectory;
 		String userHomeDirectory;
 		String defaultWorkingDirectory;
 		String defaultWorkingDirectory;

+ 0 - 2
Core/Contents/Include/PolyWinCore.h

@@ -240,8 +240,6 @@ public:
 		PolyKEY keyMap[1024];
 		PolyKEY keyMap[1024];
 		unsigned int lastGamepadDetect;
 		unsigned int lastGamepadDetect;
 
 
-		CoreMutex *eventMutex;
-
 		std::vector<Win32Event> win32Events;
 		std::vector<Win32Event> win32Events;
 
 
 		void initMultisample(int numSamples);
 		void initMultisample(int numSamples);

+ 4 - 0
Core/Contents/Source/PolyCore.cpp

@@ -135,6 +135,10 @@ namespace Polycode {
 		threads.push_back(target);
 		threads.push_back(target);
 		unlockMutex(threadedEventMutex);			
 		unlockMutex(threadedEventMutex);			
 	}
 	}
+	
+	CoreMutex *Core::getEventMutex() {
+		return eventMutex;
+	}
 			
 			
 	void Core::updateCore() {
 	void Core::updateCore() {
 		frames++;
 		frames++;

+ 4 - 0
Core/Contents/Source/PolyObject.cpp

@@ -161,6 +161,10 @@ TiXmlElement *Object::createElementFromObjectEntry(ObjectEntry *entry) {
 
 
 bool Object::loadFromXMLString(const String &xmlString) {
 bool Object::loadFromXMLString(const String &xmlString) {
 
 
+	if(xmlString.length() < 2) {
+		return false;
+	}
+
 	TiXmlDocument doc;
 	TiXmlDocument doc;
 	doc.Parse((const char*)xmlString.c_str(), 0, TIXML_ENCODING_UTF8);
 	doc.Parse((const char*)xmlString.c_str(), 0, TIXML_ENCODING_UTF8);
 
 

+ 1 - 0
Modules/Contents/Curl/PolycodeDownloader.cpp

@@ -45,6 +45,7 @@ void PolycodeDownloader::runThread() {
 	curl_easy_setopt(curl, CURLOPT_URL, url.c_str());	
 	curl_easy_setopt(curl, CURLOPT_URL, url.c_str());	
 	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, DownloaderCallback);
 	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, DownloaderCallback);
 	curl_easy_setopt(curl, CURLOPT_WRITEDATA, this);
 	curl_easy_setopt(curl, CURLOPT_WRITEDATA, this);
+	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
 			
 			
 	CURLcode curl_res = curl_easy_perform(curl);
 	CURLcode curl_res = curl_easy_perform(curl);
 	
 	

+ 1 - 1
Modules/Contents/Networking/Include/PolySocket.h

@@ -30,7 +30,7 @@ THE SOFTWARE.
 #define MAX_PACKET_SIZE 400
 #define MAX_PACKET_SIZE 400
 
 
 // if set to 1, will create a thread for each network socket
 // if set to 1, will create a thread for each network socket
-#define USE_THREADED_SOCKETS 0
+#define USE_THREADED_SOCKETS 1
 
 
 // Socket poll interval time in msecs
 // Socket poll interval time in msecs
 #define SOCKET_POLL_INTERVAL 5
 #define SOCKET_POLL_INTERVAL 5

+ 2 - 0
Modules/Contents/TUIO/Source/TUIOInputModule.cpp

@@ -114,6 +114,7 @@ void TUIOInputModule::Update(Number elapsed) {
 
 
 	Core *core = CoreServices::getInstance()->getCore();
 	Core *core = CoreServices::getInstance()->getCore();
 
 
+	core->lockMutex(core->eventMutex);	
 	CoreServices::getInstance()->getCore()->lockMutex(eventMutex);
 	CoreServices::getInstance()->getCore()->lockMutex(eventMutex);
 	for(int i=0; i < events.size(); i++) {
 	for(int i=0; i < events.size(); i++) {
 		for(int j=0; j < events[i].touches.size(); j++) {
 		for(int j=0; j < events[i].touches.size(); j++) {
@@ -136,5 +137,6 @@ void TUIOInputModule::Update(Number elapsed) {
 		}
 		}
 	}
 	}
 	events.clear();
 	events.clear();
+	core->unlockMutex(core->eventMutex);	
 	CoreServices::getInstance()->getCore()->unlockMutex(eventMutex);	
 	CoreServices::getInstance()->getCore()->unlockMutex(eventMutex);	
 }
 }