New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix QFile close bug with libsndfile #7171
base: master
Are you sure you want to change the base?
Conversation
if (sf_error(sndFile) != 0) { return std::nullopt; } | ||
sndFile = sf_open(audioFile.toStdString().c_str(), SFM_READ, &sfInfo); | ||
if (sf_error(sndFile)) { | ||
sf_close(sndFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per the libsndfile API:
Every call to sf_open_fd() should be matched with a call to sf_close() to free up memory allocated during the call to sf_open_fd().
We missed this one.
On Windows, |
This might be the reason sometimes my msvc build crashes when loading any Audio file. The issue was so random that when i clean rebuild, it gets fixed on its own and i couldn't find a consistent reason. For me, when i build lmms, sometimes it crashes when i load any audio file with the build. But when i nuke it and rebuild, there's a chance this issue might disappear. |
I didn't see in the docs that |
On Windows, |
Part of the libsndfile 1.1.0 changelog:
I think this means we can use the normal |
But with libsndfile < 1.1.0 we'll need to handle it appropriately. |
Looking into the source code, sndfile still internally converts the path as narrow encoding -> UTF-16 -> UTF-8, meaning we can't pass UTF-8 strings directly on Windows. |
QString uses 16-bit QChar which is UTF-16. With the current code then we do UTF-16 -> std::string (as byte string), that should work right? |
I mean, the input to |
Don't we have a fix for this in sndfile version 1.2.2? |
We're at a "it's complicated" point here. Apparently my linked version wasn't updated, so I was using a 1.2.0 or .1 DLL that was never actually updated with 1.2.2 one. Once I deleted it, it was replaced with the 1.2.2 DLL I cannot reproduce. On one hand we should get rid of the QFile usage here, but the bug was because CMake didn't replace the DLL as expected. |
So I believe the use of
I think this allows us to pass in the path using only |
Oh, I just realized @Veratil mentioned the same thing above me previously, lol. |
While testing loading Krem Kaakkuja in a MSVC LMMS build, when libsndfile was unable to detect the format of the file it would cause QFile to throw an exception that the file handle was already closed. This might be a bug in libsndfile, but we can prevent it altogether by just not using QFile.