Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed bug: nodes were being deleted before they had been set up with …

…the particle system. Uptaded parts of code to assume that when a node is being deleted it may not be in the p system, and if a request comes back regarding putting the node in the p system, ignore it.
  • Loading branch information...
commit b282b8a4bce62d07db10786f09f822ce66c9bec4 1 parent 6a60805
@ptierney authored
View
9 include/adj/adj_GraphNodeFactory.h
@@ -43,9 +43,12 @@ class GraphNodeFactory {
void add_new_to_random_node();
void add_new_to_node(GraphNodePtr node);
+
void delete_node(GraphNodePtr);
// passed in node is set to NULL after the method
void delete_node_and_connections(GraphNodePtr&);
+ // this assumes that GraphNode exists, but is not in the ParticleSystem
+ void shallow_delete(GraphNodePtr&);
std::vector<GraphNodePtr>& nodes() { return graph_nodes_; }
std::map<SongId, GraphNodePtr>& song_map() { return song_map_; }
@@ -61,6 +64,8 @@ class GraphNodeFactory {
std::deque<PairRequest>& pair_requests() { return pair_requests_; }
+ bool song_has_node(SongId);
+
private:
GraphNodeFactory();
void init();
@@ -72,6 +77,10 @@ class GraphNodeFactory {
void check_pair_requests();
void pair_nodes(SongId, SongId);
void assert_node_has_particle(GraphNodePtr);
+
+ void remove_from_factory(GraphNodePtr node);
+ void remove_from_other_classes(GraphNodePtr node);
+ void remove_from_graph(GraphNodePtr node);
int sim_counter_;
bool agitate_nodes_;
View
81 src/adj/adj_GraphNodeFactory.cpp
@@ -157,9 +157,16 @@ void GraphNodeFactory::update_graph_from_vote(VotePtr vote) {
to_delete = *it;
}
- // properly delete node using
+ assert(to_delete);
+
- delete_node_and_connections(to_delete);
+ if (to_delete->particle())
+ // properly delete node and rebuild particle system
+ delete_node_and_connections(to_delete);
+ else // node hasn't been set up yet
+ shallow_delete(to_delete);
+
+ assert(!to_delete);
}
@@ -244,7 +251,12 @@ void GraphNodeFactory::check_pair_requests() {
for (std::deque<PairRequest>::iterator it = pair_requests_.begin();
it != pair_requests_.end(); ++it) {
- pair_nodes(it->first, it->second);
+ // the song may have been deleted while the program waited to hear back
+ // from the GraphOracle
+ if (!song_has_node(it->first) || !song_has_node(it->second))
+ continue;
+
+ pair_nodes(it->first, it->second);
}
pair_requests_.clear();
@@ -300,6 +312,8 @@ void GraphNodeFactory::delete_node_and_connections(GraphNodePtr& node) {
// make n-1 springs to now playing
GraphNodePtr now_playing = PlayManager::instance().now_playing();
+
+ assert(now_playing);
std::vector<GraphNodePtr>& nodes = GraphNodeFactory::instance().nodes();
@@ -309,6 +323,8 @@ void GraphNodeFactory::delete_node_and_connections(GraphNodePtr& node) {
if (*it == now_playing)
continue;
+ assert(*it);
+
GraphPhysics::instance().link_nodes(now_playing, *it);
temp_pair = std::pair<GraphNodePtr, GraphNodePtr>(now_playing, *it);
@@ -317,14 +333,51 @@ void GraphNodeFactory::delete_node_and_connections(GraphNodePtr& node) {
}
-
void GraphNodeFactory::delete_node(GraphNodePtr node) {
+ remove_from_factory(node);
+ remove_from_other_classes(node);
+ remove_from_graph(node);
+}
+
+void GraphNodeFactory::shallow_delete(GraphNodePtr& node) {
+ remove_from_factory(node);
+ remove_from_other_classes(node);
+
+ assert(node.unique());
+
+ node.reset();
+}
+
+void GraphNodeFactory::remove_from_factory(GraphNodePtr node) {
// remove from main vector
std::vector<GraphNodePtr>::iterator vec_it = std::find(
graph_nodes_.begin(), graph_nodes_.end(), node);
graph_nodes_.erase(vec_it);
+ // remove from song map
+ song_map_it_ = song_map_.find(node->song().id());
+
+ song_map_.erase(song_map_it_);
+}
+
+void GraphNodeFactory::remove_from_other_classes(GraphNodePtr node) {
+ // check the PlayManager
+
+ if (PlayManager::instance().next_song_ == node)
+ PlayManager::instance().next_song_.reset();
+
+ if (PlayManager::instance().now_playing_ == node)
+ PlayManager::instance().now_playing_.reset();
+
+ // check if it's in the Now Playing Headline
+
+ NowPlayingHeadline::instance().remove_now_playing(node);
+}
+
+
+
+void GraphNodeFactory::remove_from_graph(GraphNodePtr node) {
// remove from edges
for (std::vector<std::pair<GraphNodePtr, GraphNodePtr> >::iterator
@@ -339,11 +392,6 @@ void GraphNodeFactory::delete_node(GraphNodePtr node) {
++it;
}
- // remove from song map
- song_map_it_ = song_map_.find(node->song().id());
-
- song_map_.erase(song_map_it_);
-
// remove from any nodes's children
for (std::vector<GraphNodePtr>::iterator it = graph_nodes_.begin();
@@ -361,18 +409,11 @@ void GraphNodeFactory::delete_node(GraphNodePtr node) {
(*it)->delete_parent();
}
+}
- // check the PlayManager
-
- if (PlayManager::instance().next_song_ == node)
- PlayManager::instance().next_song_.reset();
-
- if (PlayManager::instance().now_playing_ == node)
- PlayManager::instance().now_playing_.reset();
-
- // check if it's in the Now Playing Headline
-
- NowPlayingHeadline::instance().remove_now_playing(node);
+bool GraphNodeFactory::song_has_node(SongId id) {
+ song_map_it_ = song_map_.find(id);
+ return song_map_it_ != song_map_.end();
}
View
4 src/adj/adj_User.cpp
@@ -254,6 +254,10 @@ void UserFactory::update_nodes_after_user_change(UserPtr user) {
for (std::deque<SongId>::iterator it = user->voted_songs().begin();
it != user->voted_songs().end(); ++it) {
+ // Node may have been deleted while image was downloading
+ if (!GraphNodeFactory::instance().song_has_node(*it))
+ continue;
+
ci::app::console() << "Updating nodes after user change, song id: " <<
*it << std::endl;
View
2  vc10/adj.vcxproj
@@ -139,7 +139,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
- <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>WIN32;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>C:\dev\adj\include;C:\dev\Cinder\boost;C:\dev\Cinder\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
Please sign in to comment.
Something went wrong with that request. Please try again.