[Scummvm-cvs-logs] CVS: scummvm/sound vorbis.cpp,1.15,1.16

Max Horn fingolfin at users.sourceforge.net
Tue Jun 29 16:28:06 CEST 2004


Update of /cvsroot/scummvm/scummvm/sound
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15371

Modified Files:
	vorbis.cpp 
Log Message:
Fix for bug #981991 (VORBIS: Crash when using Ogg Vorbis CD tracks)

Index: vorbis.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/vorbis.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- vorbis.cpp	28 Jun 2004 22:35:22 -0000	1.15
+++ vorbis.cpp	29 Jun 2004 23:27:18 -0000	1.16
@@ -48,6 +48,7 @@
 public:
 	VorbisTrackInfo(File *file);
 	~VorbisTrackInfo();
+	bool openTrack();
 	bool error() { return _error_flag; }
 	void play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration);
 };
@@ -119,21 +120,45 @@
 
 
 VorbisTrackInfo::VorbisTrackInfo(File *file) {
+	
+	_file = file;
+	if (openTrack()) {
+		warning("Invalid file format");
+		_error_flag = true;
+		_file = 0;
+	} else {
+		_error_flag = false;
+		_file->incRef();
+		ov_clear(&_ov_file);
+	}
+}
+
+bool VorbisTrackInfo::openTrack() {
+	assert(_file);
+
 	file_info *f = new file_info;
 
-	f->file = file;
+	f->file = _file;
 	f->start = 0;
-	f->len = file->size();
-	f->curr_pos = file->pos();
-
-	if (ov_open_callbacks((void *) f, &_ov_file, NULL, 0, g_File_wrap) < 0) {
-		warning("Invalid file format");
-		_error_flag = true;
+	f->len = _file->size();
+	f->curr_pos = 0;
+	_file->seek(0);
+	
+	bool err = (ov_open_callbacks((void *) f, &_ov_file, NULL, 0, g_File_wrap) < 0);
+	
+	if (err) {
 		delete f;
-		delete file;
 	} else {
-		_error_flag = false;
-		_file = file;
+		_file->incRef();
+	}
+
+	return err;
+}
+
+VorbisTrackInfo::~VorbisTrackInfo() {
+	if (! _error_flag) {
+		ov_clear(&_ov_file);
+		_file->decRef();
 	}
 }
 
@@ -142,6 +167,10 @@
 #endif
 
 void VorbisTrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration) {
+
+	bool err = openTrack();
+	assert(!err);
+
 #ifdef VORBIS_TREMOR
 	ov_time_seek(&_ov_file, (ogg_int64_t)(startFrame / 75.0 * 1000));
 #else
@@ -152,13 +181,6 @@
 	mixer->playInputStream(handle, input, true);
 }
 
-VorbisTrackInfo::~VorbisTrackInfo() {
-	if (! _error_flag) {
-		ov_clear(&_ov_file);
-		delete _file;
-	}
-}
-
 DigitalTrackInfo *getVorbisTrack(int track) {
 	char track_name[32];
 	File *file = new File();
@@ -168,6 +190,7 @@
 
 	if (file->isOpen()) {
 		VorbisTrackInfo *trackInfo = new VorbisTrackInfo(file);
+		file->decRef();
 		if (!trackInfo->error())
 			return trackInfo;
 		delete trackInfo;





More information about the Scummvm-git-logs mailing list