SetLooped() read access violation?

I’m trying to create some background music in my game.
I’ve change the sample.inl to enable sounds and such, but whenever i attempt to call SetLooped i get a read access violation as the Sound is null. The music is there in the Data folder.

Sound* music = cache->GetResource<Sound>("Music/background.ogg");
backgroundMusic = scene_->CreateComponent<SoundSource>();

If the returned Sound* is null at this point , the file you’re trying to load does not exists or it’s format is invalid and could not be loaded.make sure the file and path exists.
Also you should check the console for errors (on windows at least)

The file is there, and plays fine out of Urho.
Is .ogg not a good format? Could it be an issue with the file itself?

Were there any mentions of failing to read the vorbis ogg file in the log?

You’ll need to step through the Sound::Load function in the debugger to see why your file is failing. stb vorbis is used, so it may not support particulars of your file.

Also, OggVorbisSoundStream is the resource type you probably want to use for music, not Sound. Sound loads the entire audio file (decoded if ogg) into memory, OggVorbisSoundStream incrementally decodes while playing.

1 Like

Thanks! turns out it must’ve been an issue with the file. stepped through the load function like you said and it wasn’t reading it in properly. Do i need to include any header files for a OggVorbisSoundStream?

I’m not sure if using a sound stream could work if using the sample as Sound doesn’t work. Maybe streams are more versatile, but you could try changing the samplerate or bitrate of the audio file first.
On Linux I use SoundConverter for this: sudo apt-get install soundconverter

Also, welcome to the forums! :confetti_ball: :slightly_smiling_face:

I’m not sure if using a sound stream could work if using the sample as Sound doesn’t work.

If specifics of the vorbis file are the problem, it won’t matter since both use stb vorbis.

Only real thing that can be done is to open up the file in a DAW/audacity/etc and see if there’s anything odd about the format/encoding/bitrate as stb vorbis isn’t very clear about what it supports other than multi-voice not being supported.