Ogre3D显示了段错误

时间:2011-02-01 08:02:09

标签: c++ segmentation-fault ogre3d

我正在使用Ogre3D编写游戏,但我遇到了问题。

当我启动程序时,它显示一个段错误:

*-*-* OGRE Initialising                                                                                                                                                                                                                                                        
*-*-* Version 1.7.2 (Cthugha)                                                                                                                                                                                                                                                  
Creating resource group Essential                                                                                                                                                                                                                                              
Added resource location '../media/packs/SdkTrays.zip' of type 'Zip' to resource group 'Essential'
Added resource location '../media' of type 'FileSystem' to resource group 'General'
Added resource location '../media/materials/scripts' of type 'FileSystem' to resource group 'General'
Added resource location '../media/materials/textures' of type 'FileSystem' to resource group 'General'
Added resource location '../media/models' of type 'FileSystem' to resource group 'General'
Naruszenie ochrony pamięci [This means segfault]

我不知道,为什么......

代码:

#define OGRE_CHANGE1 ((1 << 16) | (1 << 8))

#include "Ogre.h"
#include "ExampleApplication.h"

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#else
#include <iostream>
#endif

class MyApp : public ExampleApplication
{
  protected:
  public:
    MyApp()
    {
    }

    ~MyApp()
    {
    }
  protected:
    void createScene(void)
    {
    }
};

#ifdef __cplusplus
extern "C" {
#endif

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
  MyApp App;
   try
   {
     App.go();
     return 0;
   }
   catch (Ogre::Exception& e)
   {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
     MessageBox( NULL, e.getFullDescription().c_str(), "Exception!",
           MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
     std::cerr <<"Exception:\n";
     std::cerr <<e.getFullDescription().c_str() <<"\n";
#endif
     return 1;
   }
}

#ifdef __cplusplus
}
#endif

(部分来自Ogre Wiki的代码)

resources.cfg

# Resources required by the sample browser and most samples.
[Essential]
Zip=../media/packs/SdkTrays.zip

# Resource locations to be added to the default path
[General]
FileSystem=../media
FileSystem=../media/materials/scripts
FileSystem=../media/materials/textures
FileSystem=../media/models

plugins.cfg

# Defines plugins to load

# Define plugin folder
PluginFolder=/usr/lib/OGRE

# Define plugins
# Plugin=RenderSystem_Direct3D9
# Plugin=RenderSystem_Direct3D10
# Plugin=RenderSystem_Direct3D11
 Plugin=RenderSystem_GL
# Plugin=RenderSystem_GLES
 Plugin=Plugin_ParticleFX
 Plugin=Plugin_BSPSceneManager
 Plugin=Plugin_CgProgramManager
 Plugin=Plugin_PCZSceneManager
 Plugin=Plugin_OctreeZone
 Plugin=Plugin_OctreeSceneManager

而且 - 当我在Plugin=Plugin_CgProgramManager中评论plugins.cfg时...程序有效,但我需要这个插件。 :)

请帮忙。
提前致谢。

1 个答案:

答案 0 :(得分:2)

  1. 使用包含的调试信息编译程序(使用GCC,这意味着确保将-g选项传递给编译器)。
  2. 在调试器中运行它。
  3. 当它崩溃时,你会得到一个堆栈跟踪。
  4. 调查它是否依赖于您所做的事情(或者没有,例如缺少初始化),或者它是否适合在Ogre3D中崩溃。
    1. 如果是前者,请修理它。
    2. 如果是后者,请报告。