Aaron Aaron - 1 year ago 85
C++ Question

OggVorbis ov_open() Throws Access Violation Exception

I'm trying to open an OggVorbis file using the Vorbis SDK/DLLs.

throws an Access Violation exception
. I have checked the file exists: I've opened it with
and printed the contents to the console just to check - all went fine!

Might not make a difference, but the DLLs have been compiled as DEBUG Win32, and my project is compiling under the same configuration.

I'm using an absolute path to the file, for reassurance, and the file does exist. As stated before, I can open and read it myself.

The *.ogg file was rendered using FL Studio at 192kbps, and it also opens and plays fine in Adobe Audition and VLC Media Player.

This is the code I have to open the file and send it to the Vorbis library (the code came from this tutorial):

FILE* oggFile;
const char* path = "C:\\absolute\\path\\to\\file.ogg";
const char* openMode = "rb";
int result;

if (!(oggFile = fopen(path, openMode)))
throw std::string("Could not open file.");

if ((result = ov_open(oggFile, &oggStream, NULL, 0)) < 0)
// Never gets here
throw std::string("Could not open Ogg stream: ");

The "Vorbis" code where the exception is thrown:

// vorbisfile.c: line #827

static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence) {
return fseek(f,off,whence); // Exception thrown here

At this point,
off == 0
whence == 1

I do see the method name contains "64". Could this be wanting to read a 64bit encoded file? Or is it trying to run as 64bit when it's actually compiled as 32bit? Or is this not the issue at all? :P

Also, as I followed the tutorial I noticed there were a couple of mistakes in the code that I had to correct. So I'm wondering if the tutorial is "complete" enough, ie: perhaps there is some variable I should
, or something else that's possibly missing prior to sending the opened file to
in order for it to be handled accordingly.

Tech Specs:

  • Windows 10

  • Visual Studio Express 2013

  • _MSC_VER

  • libogg.dll
    v1.3.2 (current)

  • libvorbis.dll
    v1.3.5 (current)

NOTE: The downloaded Vorbis source code only contained Solution and Project files up to VS2010. I opened the VS2010 Solutions in Visual Studio Express 2013 to compile them in order to attain compatibility with my project. I'm also wondering if this might lead to some issues.

Answer Source

The OggVorbis documentation recommends not using ov_open on windows (https://xiph.org/vorbis/doc/vorbisfile/ov_open.html).

Use ov_open_callbacks instead.

Something like this should work:

ov_open_callbacks(oggFile, &oggStream, NULL, 0, OV_CALLBACKS_DEFAULT);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download