【发布时间】:2017-12-09 21:36:24
【问题描述】:
我有一个相当莫名其妙的问题,一个过去总是可以运行的程序现在每次重启只能运行一次,再次运行时我被授予:
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,但没有成功。
正如我所说,程序没有任何变化,所以我完全不知道是什么原因造成的。
【问题讨论】:
-
您是否安装了使用您的声卡的新软件?或者您要从中采样的任何设备?
-
你在
SetSample的类中有终结器吗? -
@Grantly 最近什么都没有,我正在从本地 WAV 文件中获取示例数据。
-
@Evk 是的,我确实有一个终结器,设置了一个断点但从未命中。
-
@Evk 我刚刚注释掉了所有与 dispose 模式相关的代码,但这并没有改变任何东西:(