我有一个相当令人困惑的问题,一个过去常常工作的程序现在只能在每次重启时工作一次,再次运行它我被授予:
# Access by name
x_vec[["x10"]]
# [1] 100
# Access by index
x_vec[[10]]
# [1] 100
我已经使用C导出扩展了一个C ++项目,所以我可以在C#中使用它:
C出口:
Exception thrown: read access violation. this was 0xBF13D000.
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
但由于某种原因,它变为0x032fe940
。请注意,始终会成为价值0xBF13D000
,因此我已经在线搜索了这样的价值,希望能够发现a known memory pattern,但却没有成功。
正如我所说的那样,对程序没有任何更改,所以我完全失去了可能导致此问题的原因。
答案 0 :(得分:0)
尝试为_audioData添加volatile https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/volatile
答案 1 :(得分:0)
事实证明,有些本机库需要使用相同的编译器版本进行全部重建,现在它可以完美运行!