我已经花了一周时间试图解决我的项目中的一个神秘问题,但我已经没有想法了。
我写了一个 Go 包,旨在播放包含 OpenAL 的声音......非常基本的东西。我让它在我的 Xubuntu 14.04(32 位)上运行,所以我启动到 Windows(7,也是 32 位)以移植它......这就是问题开始的地方。
每当我尝试使用我的音频包时,程序都会因 c0000005 而崩溃。我尝试通过 gdb 运行它并惊讶地发现它没有问题,甚至可以播放我的测试声音。
时间过去了,不知道该怎么做,我下载了 OpenAL Soft 源代码并开始添加 printfs - 并发现它崩溃的确切行:
http://repo.or.cz/w/openal-soft.git/blob/HEAD:/Alc/backends/dsound.c#l361
对于那些懒得点击链接的人(或者如果链接停止工作),这是对 DirectSoundCreate 的调用。再次运行调试器,我在调用前后看到了我的打印,并且在它们之间创建了 4 个新线程。
这些是 Go 文件中的相关内容:
package audio
/*
#cgo CFLAGS: -I"../libraries/include"
#cgo windows,386 LDFLAGS: ../libraries/lib/windows/x86/OpenAL32.dll
#cgo windows,amd64 LDFLAGS: ../libraries/lib/windows/x64/OpenAL32.dll
#cgo linux LDFLAGS: -lopenal
#include "audio.h"
*/
import "C"
import (
"errors"
)
var context *C.ALCcontext
func Init() error {
context = C.initAudio() // it crashes on this line
if context == nil {
return errors.New("could not initialize audio")
}
SetActiveListener(NewListener())
return nil
}
这是实际进行 OpenAL 调用的 C 文件:
#include "audio.h"
#include <string.h>
#include <stdio.h>
ALCcontext* initAudio() {
ALCdevice* device = alcOpenDevice(NULL); // crashes here
if (device == NULL) {
return NULL;
}
ALCcontext* context = alcCreateContext(device, NULL);
if (!alcMakeContextCurrent(context)) {
return NULL;
}
return context;
}
最后但并非最不重要的一点是,如果我在纯 C 中做完全相同的事情(实际上只是将 main 添加到我发布并调用的文件中initAudio),它就可以工作。
我的问题很明显:#@!$ 发生了什么?
桃花长相依
相关分类