Prompt in what a problem?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Pinic
Posts: 21
Joined: Wed Mar 07, 2018 10:55 am

Prompt in what a problem?

Post by Pinic »

When I try to load something the program breaks. How to fix?
Here is the project or code below
Thanks in advance))

MAIN

Code: Select all

 #include "C_Engine.h"
 
int main()
{
 
    if ( !CEngine::reset() ) return 0;
 
 
 
 
    device->getFileSystem()->addFileArchive("Data");
 
    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();
 
    guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
        rect<s32>(10,10,260,22), true);
 
    /*IAnimatedMesh* mesh = smgr->getMesh("zombie.b3d");
    if (!mesh)
    {
        device->drop();
        return 1;
    }
    IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
    if (node)
    {
        node->setMaterialFlag(EMF_LIGHTING, false);
        node->setMD2Animation(scene::EMAT_STAND);
        node->setMaterialTexture( 0, driver->getTexture("ZOMBIE.jpg") );
    }*/
 
 
    smgr->addCameraSceneNode(0, vector3df(0,20,-25), vector3df(0,10,0));
 
 
    int lastFPS = -1;
 
///////////////////////Игровой цикл////////////////////////////////
    while(device->run())
    {
        now = device->getTimer()->getTime();
        if (now - sceneStartTime > sceneSkipTime)
        {
            sceneStartTime = device->getTimer()->getTime();
            ////////////////Игровой Движек/////////////////////////
 
 
 
            ////////////////Конец игрового движка//////////////////
            driver->beginScene(true, true, video::SColor(255,200,200,200));
            smgr->drawAll();
            guienv->drawAll();
            driver->endScene();
 
            int fps = driver->getFPS();
 
            if (lastFPS != fps)
            {
                core::stringw str = L"Demo Game [";
                str += driver->getName();
                str += "] FPS:";
                str += fps;
 
                device->setWindowCaption(str.c_str());
                lastFPS = fps;
            }
        }
 
    }
 
    device->drop();
    return 0;
}
 
C_ENGINE

Code: Select all

 #ifndef C_ENGINE_H
#define C_ENGINE_H
 
#include "A_Header.h"
 
 
/// СПИСОК ОСНОВНЫХ УСТРОЙСТВ ИРРЛИХТА
 
        irr::IrrlichtDevice * device = 0;                // 1
        irr::video::IVideoDriver * driver = 0;           // 2
        irr::scene::ISceneManager * smgr = 0;            // 3
        irr::gui::IGUIEnvironment * guienv = 0;          // 4
        irr::scene::ISceneCollisionManager * cmgr = 0;   // 5
        irr::gui::ICursorControl * cControl = 0;         // 6
        irr::io::IFileSystem * fSys = 0;                 // 7
        irr::IOSOperator * OS = 0;                       // 8
        irr::ITimer * timer = 0;                         // 9
        irr::ILogger * logger = 0;                       // 10
        irr::IRandomizer * rzer = 0;                     // 11
 
    /// Загружаются TLoaderFont.h
        irr::gui::IGUIFont * font = 0,
                           * font_bold = 0,
                           * font_italic = 0;
    ///
 
    int Height = 512;
    int Width = 1024;
 
    s32 framelimit = 120,
    now = 0;
    u32 sceneStartTime = 0,
    sceneSkipTime = 1000 / framelimit;
 
/// 2 приватные служебные ф-ции
/// и только 1 рабочая - доступна
    class CEngine
    {
    ///
        static void initAll()
        {
                driver = device->getVideoDriver();
                cControl = device->getCursorControl();
                smgr = device->getSceneManager();
                cmgr = smgr->getSceneCollisionManager(); // менеджер коллизий
                guienv = device->getGUIEnvironment();
                fSys = device->getFileSystem();
                OS = device->getOSOperator();
                timer = device->getTimer();
                logger = device->getLogger();
                rzer = device->createDefaultRandomizer();
        }
 
        static void initDev ( irr::SIrrlichtCreationParameters _dcparams_= irr::SIrrlichtCreationParameters() )
        {
            device = createDeviceEx(  _dcparams_ );
            if ( device ) initAll();
 
        }
 
        public:
    ///
        static irr::IrrlichtDevice * reset( irr::video::E_DRIVER_TYPE _driverType_ = irr::video::EDT_OPENGL,
                                            //irr::core::dimension2di _newScrExt_ = irr::core::dimension2di(800,600),
                                            irr::SIrrlichtCreationParameters _dcparams_ = irr::SIrrlichtCreationParameters() )
        {
            _dcparams_.DriverType = _driverType_;
            //_dcparams_.WindowSize = _newScrExt_;
            _dcparams_.WindowSize.Height = Height;
            _dcparams_.WindowSize.Width = Width;
 
            if ( !device ) initDev ( _dcparams_ );
            else /// если устройство уже сущестует, значит его нужно "перезагрузить"
            {
                device->closeDevice();
                device->run();
                device->drop();
                device = NULL;
 
                initDev ( _dcparams_ );
            }
        ///
            return device;
        }
    }; /// end class C_ENGINE_H
 
#endif // C_ENGINE_H
 
A_Header

Code: Select all

 // include this file only once
//#pragma once
 
 
#include "Irrlicht.h"
 
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
using namespace std;
 
CuteAlien
Admin
Posts: 9647
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Prompt in what a problem?

Post by CuteAlien »

In which line does it break? And sorry, can't see project, for some reason your rar format isn't recognized by my rar tool, maybe you used a newer version or so.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Pinic
Posts: 21
Joined: Wed Mar 07, 2018 10:55 am

Re: Prompt in what a problem?

Post by Pinic »

CuteAlien wrote:In which line does it break? And sorry, can't see project, for some reason your rar format isn't recognized by my rar tool, maybe you used a newer version or so.
And if zip format?
The program works without errors until I start to download the animated model. Without loading the scene is normally drawn.
CuteAlien
Admin
Posts: 9647
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Prompt in what a problem?

Post by CuteAlien »

Are you sure it does crash? Or does it just quit?

When it crashes, please do run the c::b project file in the examples folder. If that also crashes - then rebuild Irrlicht (can be done by simply compiling inside the same project file in examples). Explanation: There had been different MinGW/gcc versions which are not compatible to each other and if you use one coming with Irrlicht release it won't work unless you have the same versions. So often you have to compile engine as first step.

If it does not crash but just quits - check if this happens only when you start it form inside CodeBlocks or also when you click the exe directly. Because inside Code::Blocks you have set the Execution working directory to "." - and that means it's at your main.cpp. If you want to set it to the same folder as your .exe then in properties - Build targets - do set "Execution working dir" to same folder as Output filename uses. So bin/Debug in your case.

Note that your code works here. But some minor things you should maybe do different:
- Use include "irrlicht.h" not "Irrlicht.h". On Windows it will work, but not a good habit to get upper/lowercase wrong as on other platforms this will fail.
- Don't use "using namespace" in headers. That's polluting your global namespace (or each one which includes that header). In headers it's better to use full qualifiers for names (like: irr::s32 instead of s32). Otherwise you will run into namespace conflicts sooner or later.
- Better to avoid globals. Put variables inside classes/structs. Otherwise every single place in your code that includes that header can change any variable. This will make it very hard to read your code in the future as you will have to check always all files to find out who messes with variables instead of just having to check the implementation of a single class.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply