|
From: Lasse Kärkkäi. <tr...@us...> - 2009-10-30 17:37:17
|
Module: performous
Branch: master
Commit: eb42d079490e031cf8722fc7ec41c4c9859cddb1
Author: Lasse Karkkainen <tro...@tr...>
Date: Fri Oct 30 19:35:40 2009 +0200
Fix the bad_alloc issue that has been around for a long time, even in 0.3 series.
---
game/engine.hh | 16 +++++++++++-----
game/song.cc | 2 ++
game/song.hh | 1 +
game/songparser.hh | 2 ++
4 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/game/engine.hh b/game/engine.hh
index 49b401c..ee00df9 100644
--- a/game/engine.hh
+++ b/game/engine.hh
@@ -19,6 +19,8 @@ namespace {
size_t playerColorsSize = sizeof(playerColors) / sizeof(*playerColors);
}
+#include <iostream>
+
/// performous engine
class Engine {
Audio& m_audio;
@@ -44,11 +46,15 @@ class Engine {
// clear old player information
m_players.cur.clear();
m_players.scores.clear();
-
- size_t frames = m_audio.getLength() / Engine::TIMESTEP;
- while (anBegin != anEnd) m_players.cur.push_back(Player(song, *anBegin++, frames));
- size_t player = 0;
- for (std::list<Player>::iterator it = m_players.cur.begin(); it != m_players.cur.end(); ++it, ++player) it->m_color = playerColors[player % playerColorsSize];
+ // Only add players if the vocal track has sensible length (not NaN or extremely long)
+ std::cout << "Endtime: " << song.endTime << std::endl;
+ if (song.endTime < 10000.0) {
+ // Calculate the space required for pitch frames
+ size_t frames = song.endTime / Engine::TIMESTEP;
+ while (anBegin != anEnd) m_players.cur.push_back(Player(song, *anBegin++, frames));
+ size_t player = 0;
+ for (std::list<Player>::iterator it = m_players.cur.begin(); it != m_players.cur.end(); ++it, ++player) it->m_color = playerColors[player % playerColorsSize];
+ }
m_thread.reset(new boost::thread(boost::ref(*this)));
}
~Engine() { kill(); }
diff --git a/game/song.cc b/game/song.cc
index 1bf5b4f..d75d92a 100644
--- a/game/song.cc
+++ b/game/song.cc
@@ -1,6 +1,7 @@
#include "song.hh"
#include "songparser.hh"
+#include "util.hh"
#include <limits>
#include <algorithm>
@@ -25,6 +26,7 @@ void Song::reload(bool errorIgnore) {
noteMax = std::numeric_limits<int>::min();
videoGap = 0.0;
start = 0.0;
+ beginTime = endTime = getNaN();
m_scoreFactor = 0.0;
try { SongParser(*this); } catch (...) { if (!errorIgnore) throw; }
collateUpdate();
diff --git a/game/song.hh b/game/song.hh
index dd3e9df..f02bf87 100644
--- a/game/song.hh
+++ b/game/song.hh
@@ -73,6 +73,7 @@ class Song: boost::noncopyable {
std::vector<double> pitchPitchGraph; ///< pitch of pitch graph
std::vector<double> volumePitchGraph; ///< volume of pitch graph
std::vector<bool> drawPitchGraph; ///< if pitch graph should be drawn
+ double beginTime, endTime; ///< the period where there are notes
double m_scoreFactor; ///< Normalization factor for the scoring system
};
diff --git a/game/songparser.hh b/game/songparser.hh
index 7be9ee4..d17b147 100644
--- a/game/songparser.hh
+++ b/game/songparser.hh
@@ -76,6 +76,8 @@ class SongParser {
it->notePrev += shift;
}
}
+ // Set begin/end times
+ if (!s.notes.empty()) s.beginTime = s.notes.front().begin, s.endTime = s.notes.back().end;
m_song.m_scoreFactor = 1.0 / m_maxScore;
}
private:
|