Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 引发异常:读取访问冲突。这是0xBF13D000_C#_C++_C_Memory_Null - Fatal编程技术网

C# 引发异常:读取访问冲突。这是0xBF13D000

C# 引发异常:读取访问冲突。这是0xBF13D000,c#,c++,c,memory,null,C#,C++,C,Memory,Null,我有一个相当令人困惑的问题,一个过去一直有效的程序现在每次重新启动只工作一次,当再次运行它时,我被授予: Exception thrown: read access violation. this was 0xBF13D000. 我已经扩展了一个带有C导出的C++项目,所以我可以从C ^:< /p>使用它。 C出口: KeyFinder::AudioData* new_audio_data(const unsigned frame_rate, const unsigned channels,

我有一个相当令人困惑的问题,一个过去一直有效的程序现在每次重新启动只工作一次,当再次运行它时,我被授予:

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

我已经扩展了一个带有C导出的C++项目,所以我可以从C ^:< /p>使用它。 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#用法:

真正令人费解的是,当我调试它时,在C部分:
SetSample.\u audioData
中已经可以看到看似已处理/销毁的指针。最初,当从C调用
new_audio_data
时,我会得到一个有效指针,如
0x032fe940
,但由于某种原因,它会变成
0xBF13D000
。请注意,它总是成为值
0xBF13D000
,因此我在网上搜索了有关该值的信息,希望找到它,但没有成功


正如我所说,该程序没有任何改动,因此我完全不知道是什么原因造成了这种情况。

尝试为音频数据添加volatile

事实证明,一些本机库需要全部使用相同的编译器版本重建,现在它可以完美地工作

您是否安装了使用声卡的新软件?或者从任何设备进行采样?在带有
SetSample
的类中是否有终结器?@granny最近没有任何东西,我从本地WAV文件中获取样本数据。@Evk是的,我有终结器,设置了断点但从未命中。@Evk我刚刚注释掉了所有与dispose模式相关的代码,但这没有改变任何内容:(不幸的是,这没有帮助:(
public void SetSample(uint index, double value)
{
    audio_data_set_sample(_audioData, index, value);
}