C++可能的线程问题 - 可能是 Ogre 的错误

发布于 2024-12-08 22:45:55 字数 5552 浏览 2 评论 0原文

我的代码中有一个非常奇怪的问题。我正在使用 Ogre,并尝试手动创建材质,但我不认为问题是 Ogre 特有的。链接:头文件源文件, 堆栈跟踪。请原谅随机名称、注释和 std::cout << 的。我很绝望,但享受有趣的编码:D

如果您不想阅读,这里是我的代码摘要:

  1. 创建根
  2. 加载插件
  3. 设置渲染系统
  4. 加载资源
  5. 设置输入系统
  6. 创建场景管理器
  7. 创建场景
    一个。设置照明
    b.手动创建材质
    c.使用手动创建的材质将实体添加到场景
  8. 添加帧更新回调
  9. 开始渲染

现在,如果我省略步骤 7b 和 7c,代码可以正常工作并按预期运行,并且程序按预期输出到日志。但如果我包括步骤 7b 和 7c,则不会发生任何情况,也不会写入任何日志。该代码永远不会完成第一步。我相信这是一个查看堆栈跟踪的死锁,但不知道如何解决它 - 我不明白稍后添加代码将如何影响之前的代码,因为它将在初始代码之后运行,这就是我怀疑的原因线程问题。欢迎任何建议!预先感谢,嗯。

编辑:删除了大部分代码,仅保留步骤 1、7a、7b 和 7c。我将堆栈跟踪留在其中,因为它不是那么长!

以下是有问题的代码:

步骤 1(第 13 行)

mRoot = new Ogre::Root("", "", "ogre.log");

步骤 7a、b、c(第 146-169 行)

mSceneManager->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));

std::cout << "Before material creation" << std::endl;


//Make cube material
Ogre::MaterialPtr cube_material_ptr = Ogre::MaterialManager::getSingleton().create(
    "trolcherry",
    Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME
    );
std::cout << "After material creation" << std::endl;

// Get a material pass
Ogre::Pass *pass = cube_material_ptr->getTechnique(0)->getPass(0);
pass->setDiffuse(Ogre::ColourValue(1.0, 0.2, 0.2));


//Make cube
Ogre::Entity& cube_entity = *(mSceneManager->createEntity("Head", "Prefab_Cube"));
cube_entity.setMaterialName("trolcherry");

Ogre::SceneNode& cube_node = *(mSceneManager->getRootSceneNode()->createChildSceneNode());
cube_node.attachObject(&cube_entity);
cube_node.scale(0.3, 0.3, 0.3);

堆栈跟踪

#0 (    0x0012e416 in __kernel_vsyscall() (??:??)
#1 0x9b20b9 __lll_lock_wait() (../nptl/sysdeps/unix/sysv/linux/i386/i686/../i486/lowlevellock.S:142)
#2 0x9af566 pthread_cond_wait@@GLIBC_2.3.2() (../nptl/sysdeps/unix/sysv/linux/i386/i686/../i486/pthread_cond_wait.S:299)
#3 0x9223fd __pthread_cond_wait(cond=0xb7bd727c, mutex=0xb7bd7264) (forward.c:139)
#4 0x804c65b    boost::recursive_mutex::lock(this=0xb7bd7264) (lib/boost_1_47_0/boost/thread/pthread/recursive_mutex.hpp:133)
#5 0x804d4af    boost::unique_lock<boost::recursive_mutex>::lock(this=0xbffff3c4) (lib/boost_1_47_0/boost/thread/locks.hpp:412)
#6 0x47dd96 unique_lock(this=0xb7bd7260, name=..., inGlobalPool=true) (/usr/include/boost/thread/locks.hpp:227)
#7 (    Ogre::ResourceGroupManager::createResourceGroup(this=0xb7bd7260, name=..., inGlobalPool=true) (/home/elliot/Programming/C and C++/Project MuffinSnatcher/lib/ogre_src_v1-7-3/OgreMain/src/OgreResourceGroupManager.cpp:84)
#8 0x47eaa6 Ogre::ResourceGroupManager::ResourceGroupManager(this=0xb7bd7260) (/home/elliot/Programming/C and C++/Project MuffinSnatcher/lib/ogre_src_v1-7-3/OgreMain/src/OgreResourceGroupManager.cpp:61)
#9 0x497bc2 Ogre::Root::Root(this=0xb7ed7260, pluginFileName=..., configFileName=..., logFileName=...) (/home/elliot/Programming/C and C++/Project MuffinSnatcher/lib/ogre_src_v1-7-3/OgreMain/src/OgreRoot.cpp:154)
#10 0x804adfe   ProjectMuffinSnatcher::Client::Run(this=0xbffff6ec) (/home/elliot/Programming/C and C++/Project MuffinSnatcher/src/Client.cpp:13)
#11 0x804e0da   main() (/home/elliot/Programming/C and C++/Project MuffinSnatcher/src/main.cpp:6)

ldd的输出

linux-gate.so.1 =>  (0x009a3000)
libboost_system.so.1.42.0 => /usr/lib/libboost_system.so.1.42.0 (0x00c14000)
libOgreMain.so.1.7.3 => /usr/local/lib/libOgreMain.so.1.7.3 (0x00110000)
libOIS-1.3.0.so => /usr/local/lib/libOIS-1.3.0.so (0x006d3000)
libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0x00ce8000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0x006f4000)
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0x00f66000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x0071a000)
libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0x0087b000)
librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0x00e7b000)
libfreetype.so.6 => /usr/lib/i386-linux-gnu/libfreetype.so.6 (0x008da000)
libSM.so.6 => /usr/lib/i386-linux-gnu/libSM.so.6 (0x00e2d000)
libICE.so.6 => /usr/lib/i386-linux-gnu/libICE.so.6 (0x00894000)
libX11.so.6 => /usr/lib/i386-linux-gnu/libX11.so.6 (0x009a4000)
libXext.so.6 => /usr/lib/i386-linux-gnu/libXext.so.6 (0x008ac000)
libXt.so.6 => /usr/lib/i386-linux-gnu/libXt.so.6 (0x00abf000)
libXaw.so.7 => /usr/lib/libXaw.so.7 (0x00b11000)
libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0x008bb000)
libboost_thread.so.1.42.0 => /usr/lib/libboost_thread.so.1.42.0 (0x008bf000)
libboost_date_time.so.1.42.0 => /usr/lib/libboost_date_time.so.1.42.0 (0x00960000)
libfreeimage.so.3 => /usr/lib/libfreeimage.so.3 (0x00f82000)
libzzip-0.so.13 => /usr/lib/libzzip-0.so.13 (0x00973000)
libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0x0097a000)
/lib/ld-linux.so.2 (0x00c2e000)
libuuid.so.1 => /lib/i386-linux-gnu/libuuid.so.1 (0x008d4000)
libxcb.so.1 => /usr/lib/i386-linux-gnu/libxcb.so.1 (0x00b6e000)
libXmu.so.6 => /usr/lib/libXmu.so.6 (0x00b87000)
libXpm.so.4 => /usr/lib/libXpm.so.4 (0x0098f000)
libXau.so.6 => /usr/lib/i386-linux-gnu/libXau.so.6 (0x00b9d000)
libXdmcp.so.6 => /usr/lib/i386-linux-gnu/libXdmcp.so.6 (0x00ba1000)

I have a very strange problem in my code. I'm using Ogre and I'm trying to manually create a material but I don't think the problem is Ogre specific. Links: Header file, Source file, Stack trace. Please excuse random names, comments and std::cout <<'s. I am in despair and enjoy fun coding :D

Here is a summary of my code if you don't wish to read it:

  1. Create root
  2. Load plugins
  3. Setup render system
  4. Load resources
  5. Setup input system
  6. Create scene manager
  7. Create scene
    a. Setup lighting
    b. Manually create material
    c. Add entity to scene with manually created material
  8. Add frame update callback
  9. Begin rendering

Now, If I omit steps 7b and 7c, the code works fine and as expected, and the program outputs to a log, as expected. But if I include steps 7b and 7c, nothing happens and no log is written. The code never finishes step one. I believe this is a deadlock from looking at the stack trace but have no idea how to solve it - I don't understand how adding code later on will affect code earlier on as it will run after the initial code, this is why I suspected a threading issue. Any suggestions welcome! Thanks in advance, ell.

Edit: Removed most code, leaving in only steps 1, 7a, 7b and 7c. I'm leaving the stack trace in because its not so long!

Here is the offending code:

Step 1 (line 13)

mRoot = new Ogre::Root("", "", "ogre.log");

Steps 7a,b,c (lines 146-169)

mSceneManager->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));

std::cout << "Before material creation" << std::endl;


//Make cube material
Ogre::MaterialPtr cube_material_ptr = Ogre::MaterialManager::getSingleton().create(
    "trolcherry",
    Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME
    );
std::cout << "After material creation" << std::endl;

// Get a material pass
Ogre::Pass *pass = cube_material_ptr->getTechnique(0)->getPass(0);
pass->setDiffuse(Ogre::ColourValue(1.0, 0.2, 0.2));


//Make cube
Ogre::Entity& cube_entity = *(mSceneManager->createEntity("Head", "Prefab_Cube"));
cube_entity.setMaterialName("trolcherry");

Ogre::SceneNode& cube_node = *(mSceneManager->getRootSceneNode()->createChildSceneNode());
cube_node.attachObject(&cube_entity);
cube_node.scale(0.3, 0.3, 0.3);

Stack trace

#0 (    0x0012e416 in __kernel_vsyscall() (??:??)
#1 0x9b20b9 __lll_lock_wait() (../nptl/sysdeps/unix/sysv/linux/i386/i686/../i486/lowlevellock.S:142)
#2 0x9af566 pthread_cond_wait@@GLIBC_2.3.2() (../nptl/sysdeps/unix/sysv/linux/i386/i686/../i486/pthread_cond_wait.S:299)
#3 0x9223fd __pthread_cond_wait(cond=0xb7bd727c, mutex=0xb7bd7264) (forward.c:139)
#4 0x804c65b    boost::recursive_mutex::lock(this=0xb7bd7264) (lib/boost_1_47_0/boost/thread/pthread/recursive_mutex.hpp:133)
#5 0x804d4af    boost::unique_lock<boost::recursive_mutex>::lock(this=0xbffff3c4) (lib/boost_1_47_0/boost/thread/locks.hpp:412)
#6 0x47dd96 unique_lock(this=0xb7bd7260, name=..., inGlobalPool=true) (/usr/include/boost/thread/locks.hpp:227)
#7 (    Ogre::ResourceGroupManager::createResourceGroup(this=0xb7bd7260, name=..., inGlobalPool=true) (/home/elliot/Programming/C and C++/Project MuffinSnatcher/lib/ogre_src_v1-7-3/OgreMain/src/OgreResourceGroupManager.cpp:84)
#8 0x47eaa6 Ogre::ResourceGroupManager::ResourceGroupManager(this=0xb7bd7260) (/home/elliot/Programming/C and C++/Project MuffinSnatcher/lib/ogre_src_v1-7-3/OgreMain/src/OgreResourceGroupManager.cpp:61)
#9 0x497bc2 Ogre::Root::Root(this=0xb7ed7260, pluginFileName=..., configFileName=..., logFileName=...) (/home/elliot/Programming/C and C++/Project MuffinSnatcher/lib/ogre_src_v1-7-3/OgreMain/src/OgreRoot.cpp:154)
#10 0x804adfe   ProjectMuffinSnatcher::Client::Run(this=0xbffff6ec) (/home/elliot/Programming/C and C++/Project MuffinSnatcher/src/Client.cpp:13)
#11 0x804e0da   main() (/home/elliot/Programming/C and C++/Project MuffinSnatcher/src/main.cpp:6)

Output of ldd

linux-gate.so.1 =>  (0x009a3000)
libboost_system.so.1.42.0 => /usr/lib/libboost_system.so.1.42.0 (0x00c14000)
libOgreMain.so.1.7.3 => /usr/local/lib/libOgreMain.so.1.7.3 (0x00110000)
libOIS-1.3.0.so => /usr/local/lib/libOIS-1.3.0.so (0x006d3000)
libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0x00ce8000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0x006f4000)
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0x00f66000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x0071a000)
libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0x0087b000)
librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0x00e7b000)
libfreetype.so.6 => /usr/lib/i386-linux-gnu/libfreetype.so.6 (0x008da000)
libSM.so.6 => /usr/lib/i386-linux-gnu/libSM.so.6 (0x00e2d000)
libICE.so.6 => /usr/lib/i386-linux-gnu/libICE.so.6 (0x00894000)
libX11.so.6 => /usr/lib/i386-linux-gnu/libX11.so.6 (0x009a4000)
libXext.so.6 => /usr/lib/i386-linux-gnu/libXext.so.6 (0x008ac000)
libXt.so.6 => /usr/lib/i386-linux-gnu/libXt.so.6 (0x00abf000)
libXaw.so.7 => /usr/lib/libXaw.so.7 (0x00b11000)
libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0x008bb000)
libboost_thread.so.1.42.0 => /usr/lib/libboost_thread.so.1.42.0 (0x008bf000)
libboost_date_time.so.1.42.0 => /usr/lib/libboost_date_time.so.1.42.0 (0x00960000)
libfreeimage.so.3 => /usr/lib/libfreeimage.so.3 (0x00f82000)
libzzip-0.so.13 => /usr/lib/libzzip-0.so.13 (0x00973000)
libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0x0097a000)
/lib/ld-linux.so.2 (0x00c2e000)
libuuid.so.1 => /lib/i386-linux-gnu/libuuid.so.1 (0x008d4000)
libxcb.so.1 => /usr/lib/i386-linux-gnu/libxcb.so.1 (0x00b6e000)
libXmu.so.6 => /usr/lib/libXmu.so.6 (0x00b87000)
libXpm.so.4 => /usr/lib/libXpm.so.4 (0x0098f000)
libXau.so.6 => /usr/lib/i386-linux-gnu/libXau.so.6 (0x00b9d000)
libXdmcp.so.6 => /usr/lib/i386-linux-gnu/libXdmcp.so.6 (0x00ba1000)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

℉絮湮 2024-12-15 22:45:55

我本想对此发表评论,但我缺乏所需的代表。 :(

有几件事需要尝试:

Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME 是一个静态 OGRE_AUTO_MUTEX 字符串 - 而不是将其直接传递给材质管理器的 create,首先尝试将其复制到本地作用域的 String 实例中,看看错误发生的位置是否发生变化,或者实际上它是否纠正了它

Ogre::Root 构造函数 您明确使用“”覆盖默认插件和配置文件名(并且没有真正提供日志文件的有用替换 - 从“Ogre.log”更改为“ogre.log”)。 log”)。您可以尝试删除构造函数参数吗?

I would have made this a comment, but I lack the required rep. :(

A couple of things to try:

The Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME is a static OGRE_AUTO_MUTEX String - instead of passing it directly to the material manager's create, try to copy it into a locally scoped String instance first. See if that changes where the error occurs, or if in fact it corrects it.

Alternatively, I noticed in the Ogre::Root constructor you are explicitly overriding the default plugin and config file names with "" (and not really providing a useful replacement of the log file - changed from "Ogre.log" to "ogre.log"). Could you try removing the constructor arguments?

回眸一笑 2024-12-15 22:45:55

我终于解决了我的问题。我删除了所有的 boost 和ogre相关库并重新编译boost,然后ogre并重新安装它们。现在一切正常(显然!)。感谢您的所有帮助,但我想我只需要重新安装即可。很少,我很高兴这一切都结束了!

I've finally fixed my problem. I deleted all boost & ogre related libraries and recompiled boost and then ogre and reinstalled them. Now things work fine (apparently!). Thanks for all the help but I guess a fresh reinstall is all I needed. Few, I'm glad that's over!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文