LibVLC Access Violation

1

I am trying to set up logging in LibVLC, and am running into some problems.

The function I am using is libvlc_log_set_file, here are the docs: LibVLC logging docs

Here is the code I have now:

//header
private:
    FILE * logFile;

//source
logFile = fopen(path.c_str(), "w");
if(logFile != NULL)
{
    libvlc_log_set_file(_libvlc_instance, logFile);
}

On the libvlc_log_set_file line I get this error, "Unhandled exception at 0x77559E33 (ntdll.dll) in nw.exe: 0xC0000005: Access violation writing location 0x00000014."

I am able to open and write to the file with fputs() just fine.

I am using NW.js with WebChimera.js compiling to 32 bit with Visual Studio 2013 on a 64 bit Windows 7 machine.

Any ideas?

c++
access-violation
libvlc
nw.js
ntdll
asked on Stack Overflow Jul 10, 2015 by cascade256

1 Answer

0

I had this exact problem today. I was unable to solve it using libvlc_log_set_file. I instead chose to use libvlc_log_set to set up the callback and use that method to write to a log file instead. Here is a example, it shows what needs to be done. I don't recommend the global file pointer, it is just for this quick sample.

Note: logpath is a const char* that contains the path of your log file. Also, you probably want to flockfile to make this thread safe. You can also toss a switch statement in there to handle the level parameters for LIBVLC_NOTICE, LIBVLC_ERROR, LIBVLC_WARNING and LIBVLC_DEBUG to give your logging some granularity.

bool g_loggingEnabled = true;
FILE* g_logfp = nullptr;

void logcb(void *data, int level, const libvlc_log_t *ctx, const char *fmt, va_list args)
{
    if (!g_loggingEnabled) return;

    if (g_logfp == nullptr)
    {
        errno_t err = fopen_s(&g_logfp, logpath, "w");

        if (err != 0)
        {
            g_loggingEnabled = false;
            return;
        }
    }

    vfprintf(g_logfp, fmt, args);
}

Addendum: On Windows you might want to use CreateFile instead with the FILE_SHARE_READ flag set and use WriteFile so that external text editors can view the file while the logging is occurring in real-time. If you do, look into vsprintf_s instead of vfprintf to fill a character buffer that you would then pass to WriteFile in the logcb method.

answered on Stack Overflow Jul 14, 2015 by Nelson Rush • edited Jul 15, 2015 by Nelson Rush

User contributions licensed under CC BY-SA 3.0