“使用了无效的对象句柄”在 FMOD 3D 声音监听器中
我正在尝试在使用 Ogre 的游戏中使用 FMOD 设置 3D 声音。声音监听器连接到在样条线上运行的摄像机。我在播放器上附加了脚步声,音量应根据播放器与摄像机的距离来确定。
脚步声的作用就好像声音听者没有从其起始位置移动一样。在关卡开始时,脚步声很大,当你远离起点时,脚步声会变得更安静,直到你再也听不到它们。如果你跑回起点,他们的声音就会更大。但是,声音侦听器场景节点的位置正在更新并与摄像机保持同步。
在代码中,以下行的每一帧都会生成 FMOD 错误:
result = m_system->set3DListenerAttributes(0, &pos, &vel, &forward, &up);
结果始终返回 FMOD_ERR_INVALID_HANDLE,并带有以下错误字符串 -“使用了无效的对象句柄”。我不明白为什么会产生这个错误。作为参数传入的所有 FMOD_VECTOR 都已初始化,我似乎正在正确设置系统。代码遍布不同的类中,但这里是重要的部分:
// Initialise FMOD system
result = m_system->init(4093, FMOD_INIT_3D_RIGHTHANDED, 0);
result = m_system->set3DSettings(1.0f, 1.0f, 1.0f);
// Create sound
FMOD_MODE mode = FMOD_SOFTWARE;
if(a_positional)
{
mode |= FMOD_3D;
}
FMOD_CREATESOUNDEXINFO info;
memset(&info, 0, sizeof(FMOD_CREATESOUNDEXINFO));
info.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
r = sys->_getFMODSystem()->createSound(a_file.c_str(), mode, &info, &retVal);
// Update sound listener
FMOD_VECTOR pos, vel, forward, up;
pos.x = m_sceneNode->getParentSceneNode()->_getDerivedPosition().x;
pos.y = m_sceneNode->getParentSceneNode()->_getDerivedPosition().y;
pos.z = m_sceneNode->getParentSceneNode()->_getDerivedPosition().z;
vel.x = 0;
vel.y = 0;
vel.z = 0;
forward.x = 0;
forward.y = 0;
forward.z = 1;
up.x = 0;
up.y = 1;
up.z = 0;
result = m_system->set3DListenerAttributes(0, &pos, &vel, &forward, &up);
// FMOD error: (36) An invalid object handle was used.
关于为什么“结果”返回此错误有什么想法吗?我假设这就是 3D 声音无法正常播放的原因。
I'm trying to set up 3D sounds with FMOD in a game which uses Ogre. The sound listener is attached to the camera which runs on a spline. I have footstep sounds attached to the player, and the volume should be determined by how far the player is from the camera.
The foot step sounds are acting as though the sound listener is not moving from its start position. At the start of the level, the footsteps are loud, and as you move away from the start they get quieter until you can't hear them anymore. If you run back to the start, they get louder. However, the position of the sound listener's scene node is updating and staying in sync with the camera.
In code there is an FMOD error being generated every frame on the following line:
result = m_system->set3DListenerAttributes(0, &pos, &vel, &forward, &up);
result is always returning FMOD_ERR_INVALID_HANDLE, with the following error string - 'An invalid object handle was used'. I can't figure out why this error is being generated. All the FMOD_VECTORs being passed in as parameters are initialised and I appear to be setting up the system correctly. The code is all over the place in different classes but here are the important bits:
// Initialise FMOD system
result = m_system->init(4093, FMOD_INIT_3D_RIGHTHANDED, 0);
result = m_system->set3DSettings(1.0f, 1.0f, 1.0f);
// Create sound
FMOD_MODE mode = FMOD_SOFTWARE;
if(a_positional)
{
mode |= FMOD_3D;
}
FMOD_CREATESOUNDEXINFO info;
memset(&info, 0, sizeof(FMOD_CREATESOUNDEXINFO));
info.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
r = sys->_getFMODSystem()->createSound(a_file.c_str(), mode, &info, &retVal);
// Update sound listener
FMOD_VECTOR pos, vel, forward, up;
pos.x = m_sceneNode->getParentSceneNode()->_getDerivedPosition().x;
pos.y = m_sceneNode->getParentSceneNode()->_getDerivedPosition().y;
pos.z = m_sceneNode->getParentSceneNode()->_getDerivedPosition().z;
vel.x = 0;
vel.y = 0;
vel.z = 0;
forward.x = 0;
forward.y = 0;
forward.z = 1;
up.x = 0;
up.y = 1;
up.z = 0;
result = m_system->set3DListenerAttributes(0, &pos, &vel, &forward, &up);
// FMOD error: (36) An invalid object handle was used.
Any ideas as to why 'result' is returning this error? I'm assuming it's the reason why the 3D sounds aren't playing correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无效句柄错误(FMOD_ERR_INVALID_HANDLE)指的是您正在调用函数的对象,在这种情况下,这意味着 m_system 句柄无效。
首先,我注意到您省略了创建 FMOD::System 对象的代码,您能否确认您正在执行以下操作:
其次,如果您在某处有该代码,您是否可以验证 m_system 的值在创建和创建之间保持不变使用时(可能有东西损坏了手柄)。
最后(长远来看)如果您的标头和库不同步,您可能会收到不同的错误消息,请确保您使用的标头和库均来自同一版本的 FMOD。
特别注意,尝试链接 FMOD 的日志记录版本,您应该在 TTY 上获得一些有用的调试输出,这可能对您的情况有所帮助。
An invalid handle error (FMOD_ERR_INVALID_HANDLE) is referring to the object you are calling functions on, in this case it means the m_system handle is invalid.
Firstly I noticed you have omited the code to create the FMOD::System object, can you confirm you are doing the following:
Secondly, provided you have that code somewhere can you verify that the value of m_system remains unchanged between when it is created and when it is used (perhaps something is corrupting the handle).
Finally (as a long shot) if your headers and lib are out of sync you might be getting a different error message, ensure the headers and libs you are using are all from the same version of FMOD.
Extra note, try linking with the logging version of FMOD, you should get some useful debug output on the TTY that might help your situation.