Hi
There are at least two major problems in your code.
1. capacity() returns the amount of memory that is allocated for the vector, not the actual number of elements. It may lead to "gaps" in your vector: when you add 1 element with resize, the capacity may be increased a lot more (typically multiplied by a factor > 1).
2. Your SoundFile class doesn't handle properly the copy. After a copy, the instance's sound will still point to the sound buffer of the copy instead of being updated with its own buffer. You should define a copy constructor to fix this. This is very well explained at the end of the sound tutorial.
A correct solution would be:
struct SoundFile
{
SoundFile(const SoundFile& copy) : Name(copy.Name), Vol(Copy.Vol), Buffer(Copy.Buffer), Sound(Copy.Sound)
{
Sound.SetBuffer(Buffer);
}
std::string Name;
float Vol;
SoundBuffer Buffer;
Sound Sound;
};
void Sfx::LoadSoundFile(std::string filename, float Volume)
{
SoundFile Sound;
if (Sound.Buffer.LoadFromFile(filename))
{
Sound.Name = filename;
Sound.Vol = Volume;
Sound.Sound.SetBuffer(Sound.Buffer);
Sound.Sound.SetVolume(Volume);
cout << Soundtest.size() << " loaded: " << filename << endl;
Soundtest.push_back(Sound);
}
}
(not tested)