抛出例外:阅读访问违规.这是0xbf13d000



我有一个相当令人困惑的问题,这个程序曾经始终每次重新启动一次工作一次,当我再次运行时,我会接受:

Exception thrown: read access violation. this was 0xBF13D000.

我已经使用C出口扩展了一个C 项目,因此我可以从C#:

使用它

C出口:

KeyFinder::AudioData* new_audio_data(const unsigned frame_rate, const unsigned channels, const unsigned samples)
{
    auto audio_data = new KeyFinder::AudioData();
    audio_data->setFrameRate(frame_rate);
    audio_data->setChannels(channels);
    audio_data->addToSampleCount(samples);
    return audio_data;
}
void audio_data_set_sample(KeyFinder::AudioData* audio_data, const unsigned index, const double value)
{
    audio_data->setSample(index, value);
}
void keyfinder_progressive_chromagram(KeyFinder::KeyFinder* key_finder, KeyFinder::AudioData* audio_data, KeyFinder::Workspace* workspace)
{
    key_finder->progressiveChromagram(*audio_data, *workspace);
}
KeyFinder::key_t keyfinder_key_of_chromagram(KeyFinder::KeyFinder* key_finder, KeyFinder::Workspace* workspace)
{
    return key_finder->keyOfChromagram(*workspace);
}
enum key_t {
    A_MAJOR = 0,
    A_MINOR,
    B_FLAT_MAJOR,
    B_FLAT_MINOR,
    B_MAJOR,
    B_MINOR = 5,
    C_MAJOR,
    C_MINOR,
    D_FLAT_MAJOR,
    D_FLAT_MINOR,
    D_MAJOR = 10,
    D_MINOR,
    E_FLAT_MAJOR,
    E_FLAT_MINOR,
    E_MAJOR,
    E_MINOR = 15,
    F_MAJOR,
    F_MINOR,
    G_FLAT_MAJOR,
    G_FLAT_MINOR,
    G_MAJOR = 20,
    G_MINOR,
    A_FLAT_MAJOR,
    A_FLAT_MINOR,
    SILENCE = 24
};

c#声明:

[DllImport("libKeyFinder", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr new_audio_data(
    uint frameRate, uint channels, uint samples);
[DllImport("libKeyFinder", CallingConvention = CallingConvention.Cdecl)]
private static extern void audio_data_set_sample(
    IntPtr audioData, uint index, double value);
[DllImport("libKeyFinder", CallingConvention = CallingConvention.Cdecl)]
private static extern void keyfinder_progressive_chromagram(IntPtr keyFinder, IntPtr audioData, IntPtr workspace);
[DllImport("libKeyFinder", CallingConvention = CallingConvention.Cdecl)]
private static extern Key keyfinder_key_of_chromagram(IntPtr keyFinder, IntPtr workspace);
public enum Key
{
    AMajor = 0,
    AMinor,
    BFlatMajor,
    BFlatMinor,
    BMajor,
    BMinor = 5,
    CMajor,
    CMinor,
    DFlatMajor,
    DFlatMinor,
    DMajor = 10,
    DMinor,
    EFlatMajor,
    EFlatMinor,
    EMajor,
    EMinor = 15,
    FMajor,
    FMinor,
    GFlatMajor,
    GFlatMinor,
    GMajor = 20,
    GMinor,
    AFlatMajor,
    AFlatMinor,
    Silence = 24
}

c#用法:

public void SetSample(uint index, double value)
{
    audio_data_set_sample(_audioData, index, value);
}

真正令人困惑的是,当我调试它时,看似处置的/破坏的指针在C#部分中已经可以看到:SetSample._audioData。最初,当new_audio_data从C#I调用时,获得了一个有效的指针,例如0x032fe940,但由于某种原因,它变为0xBF13D000。请注意,它始终成为值0xBF13D000,因此我在线搜索了此类值,希望发现已知的内存模式但没有成功。

正如我说的,没有任何任何更改程序,所以我完全损失了可能导致的。

尝试为_audiodata添加挥发性https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/volatile

事实证明,某些本机库需要使用相同的编译器版本进行重建,现在它可以完美无缺!

相关内容

  • 没有找到相关文章

最新更新