抛出异常:读取访问冲突。这是0xBF13D000
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了抛出异常:读取访问冲突。这是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
。最初,当从C#调用new_audio_data
时,我得到一个像0x032fe940
这样的有效指针,但由于某种原因它变成了0xBF13D000
。请注意它总是变成值0xBF13D000
所以我在网上搜索了这样的价值,希望能发现a known memory pattern但没有成功。
正如我所说,该计划没有任何变化,所以我完全失去了可能导致这种情况的原因。
答案
尝试为_audioData https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/volatile添加volatile
另一答案
事实证明,一些本机库需要使用相同的编译器版本进行全部重建,现在它可以完美运行!
以上是关于抛出异常:读取访问冲突。这是0xBF13D000的主要内容,如果未能解决你的问题,请参考以下文章
为什么调试器会抛出“读取访问冲突。这是nullptr”例外吗?
抛出异常:读取访问冲突。 **dynamicArray** 为 0x1118235。发生了
抛出未处理的异常:读取访问冲突。 x 是 0x20B4112