ocarina/include/library.h
Bryan Schumaker 05bbad5444 libsaria: Resizing a vector invalidates pointers
I was keeping a vector of objects, and then pass pointers to these
objects around everywhere.  HOWEVER, when vectors are resized they
allocate new memory and copy things over invalidating iterators and
pointers to the original objects.  This can cause memory corruption
issues when I try to use a pointer to an object that no longer exists.

The simple solution?  Allocate tracks dynamically and then store the
pointer in the library path.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
2014-04-06 19:56:50 -04:00

44 lines
667 B
C++

#ifndef LIBSARIA_LIBRARY_H
#define LIBSARIA_LIBRARY_H
#include <fs.h>
#include <track.h>
#include <playlist.h>
#include <string>
#include <vector>
using namespace std;
namespace libsaria
{
namespace library
{
struct Path {
bool visible;
unsigned int id;
string path;
vector<Track *> tracks;
};
void init();
void quit();
void add_path(string);
void delete_path(Path *);
void update_path(Path *);
void save_path(Path *);
void update_all();
void hide_path(Path *);
void show_path(Path *);
Track *lookup(unsigned int, unsigned int);
void set_random(bool);
Playlist *get_playlist();
}
}
#endif /* LIBSARIA_LIBRARY_H */