使用指针清理导入程序
Assimp importer cleanup with pointers
我正在尝试使用 Assimp 导入一些动画文件并将它们添加到现有动画列表中。但是,我在使用 aiAnimation->mChannels(类型 aiNodeAnim**(时遇到了问题,因为当我的函数返回时,我的新 aiAnimation 对象的 mChannels 指针无效。这是因为 Assimp 的进口商在被销毁时会自行清理。我需要的是复制通道,以便在导入程序超出范围时不会删除它们。
这是我的动画追加函数,它按我的预期更新,但在从函数返回时产生运行时异常"引擎.exe触发了断点"。
void Animation::AddAnimation(const char* p_filePath)
{
Assimp::Importer m_importer;
const aiScene* m_scene = m_importer.ReadFile(p_filePath,
aiProcess_CalcTangentSpace |
aiProcess_Triangulate |
aiProcess_JoinIdenticalVertices |
aiProcess_SortByPType | aiProcess_GenSmoothNormals);
for (int i = 0; i < m_scene->mNumAnimations; ++i)
{
aiAnimation* m_newAnimation = new aiAnimation(*m_scene->mAnimations[i]);
m_newAnimation->mName = m_scene->mAnimations[i]->mName;
m_newAnimation->mDuration = m_scene->mAnimations[i]->mDuration;
m_newAnimation->mTicksPerSecond = m_scene->mAnimations[i]->mTicksPerSecond;
m_newAnimation->mNumChannels = m_scene->mAnimations[i]->mNumChannels;
if (m_scene->mAnimations[i]->mChannels != NULL)
{
aiNodeAnim* m_channels = *m_scene->mAnimations[i]->mChannels;
*m_newAnimation->mChannels = new aiNodeAnim[m_scene->mAnimations[i]->mNumChannels];
for (int j = 0; j < m_scene->mAnimations[i]->mNumChannels; ++j)
{
m_newAnimation->mChannels[j] = new aiNodeAnim();
m_newAnimation->mChannels[j] = &m_channels[j];
}
}
g_channels = m_newAnimation->mChannels;
g_animations.push_back(m_newAnimation);
}
}
我没有足够的声誉来评论,但你是问是否需要单独复制动画频道吗?答案是肯定的,因为如果您尝试对数组m_channels
,甚至数组中的每个条目进行memcpy
,则无法确定它们在内存中是否是连续的。您必须手动复制旋转、转换和缩放密钥的每个数组。
顺便说一下,这些代码行
m_newAnimation->mChannels[j] = new aiNodeAnim();
m_newAnimation->mChannels[j] = &m_channels[j];
可能不做你想做的事。在第一行中,您分配空间并初始化新动画,在第二行中,您可以使用导入器通道的地址将其吹走。删除第二行并将 aiNodeAnim 的内容复制到数组中可以解决此问题。
相关文章:
- 为什么导入Mixed native/CLR lib.dll的本机C++应用程序没有在Mixed lib.dll中的外部变
- 如何在Windows窗体应用程序中打开txt文件并将行导入文本框
- 编写程序,导入三个浮点数a,b和c.按升序排序
- 如何在Python脚本中导入CPYTHON模块,该模块将由C 程序使用
- numpy.core.multiarray在通过Xcode中开发的C 应用程序调用Python模块时未能导入
- 如何查找从哪里导入程序C++特定功能
- 如何在Windows表单应用程序vc ++中导入C静态库
- 在另一个应用程序中嵌入python时,如何在子模块(即scipy.optimize.nnls)中导入或调用函数
- 将C++代码导入IOS应用程序
- 是否可以将用C ++编写的动态库导入C#程序
- 导入到 C# 应用程序中C++ DLL
- 多次定义"调度程序::_singleton",导入标头两次
- 在C++应用程序中导入 NPAPI DLL
- 无法在C++应用程序中导入dll
- 在C#应用程序中导入并使用C++DLL函数
- 提高了从客户端应用程序大规模导入MS SQL 2008数据库的速度
- 使用指针清理导入程序
- 将搅拌机模型导入到DirectX 11.2 c++应用程序中
- 如何将使用boost::asio的本地c++静态库导入CLI/ c++混合模式应用程序?
- 正在将dll导入C++程序