[Scummvm-cvs-logs] SF.net SVN: scummvm:[47106] scummvm/trunk/engines/teenagent

megath at users.sourceforge.net megath at users.sourceforge.net
Thu Jan 7 13:01:33 CET 2010


Revision: 47106
          http://scummvm.svn.sourceforge.net/scummvm/?rev=47106&view=rev
Author:   megath
Date:     2010-01-07 12:01:33 +0000 (Thu, 07 Jan 2010)

Log Message:
-----------
cleaned up player, fixed invalid delete's and memory leaks

Modified Paths:
--------------
    scummvm/trunk/engines/teenagent/music.cpp
    scummvm/trunk/engines/teenagent/music.h

Modified: scummvm/trunk/engines/teenagent/music.cpp
===================================================================
--- scummvm/trunk/engines/teenagent/music.cpp	2010-01-07 10:31:29 UTC (rev 47105)
+++ scummvm/trunk/engines/teenagent/music.cpp	2010-01-07 12:01:33 UTC (rev 47106)
@@ -51,10 +51,7 @@
 	stream->read(header, 4);
 	//check header?
 
-	memset(_samples, 0, sizeof(_samples));
-
 	// Load the samples
-
 	sampleCount = stream->readByte();
 
 	debug(0, "sampleCount = %d", sampleCount);
@@ -70,25 +67,15 @@
 
 		if (in == 0) {
 			warning("load: invalid sample %d (0x%02x)", sample, sample);
-			_samples[sample].data = NULL;
-			_samples[sample].size = 0;
+			_samples[sample].clear();
 			continue;
 		}
 
-		byte *sampleData = new byte[sampleSize];
-		in->read(sampleData, sampleSize);
-
-		// Convert the sample from signed to unsigned
-		for (uint32 i = 0; i < sampleSize; i++)
-			*sampleData ^= 0x80;
-
-		delete _samples[sample].data;
-		_samples[sample].data = sampleData;
-		_samples[sample].size = sampleSize;
+		_samples[sample].resize(sampleSize);
+		in->read(_samples[sample].data, sampleSize);
 	}
 
 	// Load the music data
-
 	_rows.clear();
 
 	Row row;

Modified: scummvm/trunk/engines/teenagent/music.h
===================================================================
--- scummvm/trunk/engines/teenagent/music.h	2010-01-07 10:31:29 UTC (rev 47105)
+++ scummvm/trunk/engines/teenagent/music.h	2010-01-07 12:01:33 UTC (rev 47106)
@@ -54,18 +54,27 @@
 		} channels[3];
 	};
 
-	struct {
-		const byte *data;
-		uint32 size;
+	struct Sample {
+		byte *data;
+		uint size;
+		Sample(): data(0), size(0) {}
+		~Sample() { delete[] data; }
+
+		void resize(uint s) {
+			if (s != size) {
+				delete[] data;
+				data = new byte[s];
+				size = s;
+			}
+		}
+		void clear() { 
+			delete[] data; 
+			data = 0; 
+			size = 0; 
+		}
 	} _samples[256];
 	byte sampleCount;
 
-	struct {
-		byte volume;
-		const byte *data;
-		uint32 size;
-	} _channels[3];
-
 	Common::Array<Row> _rows;
 	uint _currRow;
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list