[fixed] Custom font causes crash

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
pc0de
Posts: 300
Joined: Wed Dec 05, 2007 4:41 pm

[fixed] Custom font causes crash

Post by pc0de »

Bug: 3507262 - Custom font causes crash.

When loading a custom font, the xml "Texture" node is being skipped and causes a crash when text is drawn using the custom font.

Simple patch:

Code: Select all

 
===================================================================
--- source/Irrlicht/CGUIEnvironment.cpp (revision 4106)
+++ source/Irrlicht/CGUIEnvironment.cpp (working copy)
@@ -1399,7 +1399,7 @@
                EGUI_FONT_TYPE t = EGFT_CUSTOM;
 
                bool found=false;
-               while(xml->read() && !found)
+               while(!found && xml->read())
                {
                        if (xml->getNodeType() == io::EXN_ELEMENT)
                        {
 
*edit*
test case:
"test1()" in idebug.cpp
"init()" loads custom font.

Custom font: defaults.zip
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: [bug] Custom font causes crash

Post by CuteAlien »

Could not repdoduce this even after I got your example compiling. It worked without crash. And I also don't see so far why changing those 2 commands would matter. I tested with 1.7 branch and svn.

I don't say there is no bug ... but please try giving me just the code to reproduce this and test if it compiles and still crashes on your system first.
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
pc0de
Posts: 300
Joined: Wed Dec 05, 2007 4:41 pm

Re: [bug] Custom font causes crash

Post by pc0de »

Thanks for taking a look. Here's the full source of an example that causes a crash compiled against the latest trunk:

Code: Select all

#include "irrlicht.h"
 
using namespace irr;
using namespace irr::io;
using namespace irr::core;
using namespace irr::scene;
using namespace irr::gui;
using namespace video;
 
#define WINDOW_SIZE_X       640
#define WINDOW_SIZE_Y       480
#define DEVICE_BPP          32
 
static IrrlichtDevice*      m_device;
static IVideoDriver*        m_videoDriver;
static ISceneManager*       m_sceneManager;
static IFileSystem*         m_fileSystem;
static IEventReceiver*      m_eventReceiver;
static IGUIEnvironment*     m_gui;
static IGUIFont*            m_defaultFont=0;
static IGUIFont*            m_monoFont=0;
static ICameraSceneNode*    m_camera;
static bool                 m_running=true;
static int                  m_capNumber=1;
 
static E_DRIVER_TYPE        m_driverType=EDT_OPENGL;  
 
IGUIEnvironment* getGUI()
{
    return m_gui;
}
 
//-----------------------------------------------------------------------------
//                             E v e n t R e c e i v e r
//-----------------------------------------------------------------------------
class EventReceiver : public IEventReceiver
{
    bool OnEvent(const SEvent& event)
    {
        if (event.EventType == irr::EET_KEY_INPUT_EVENT)
            if( !event.KeyInput.PressedDown ) // key up?
            {
                switch(event.KeyInput.Key)
                {
                case KEY_ESCAPE:
                    m_running = false;
                    return true;
                default:
                    break;
                }
            }
            return false;
    }
 
public:
    EventReceiver() : IEventReceiver() {}
};
 
//-----------------------------------------------------------------------------
//                                 m a i n
//-----------------------------------------------------------------------------
#ifdef _IRR_WINDOWS_
#pragma comment(linker, "/subsystem:console /ENTRY:mainCRTStartup") 
#endif
int main(int argc, char* argv[])
{
    m_eventReceiver = new EventReceiver();
    SIrrlichtCreationParameters cp;
    cp.DriverType = m_driverType;
    cp.WindowSize = dimension2du(WINDOW_SIZE_X,WINDOW_SIZE_Y);
    cp.Bits = DEVICE_BPP;
    cp.Fullscreen = false;
    cp.Vsync = false;
    cp.Stencilbuffer = false;
    cp.AntiAlias = false;
    cp.EventReceiver = m_eventReceiver;
    cp.WindowId = 0;
 
    m_device = createDeviceEx(cp);
    if(!m_device)
        return 1;
 
    m_fileSystem = m_device->getFileSystem();
    m_videoDriver = m_device->getVideoDriver();
    m_sceneManager = m_device->getSceneManager();
    m_gui = m_device->getGUIEnvironment();
 
    //
    // override default font
    //        
    stringc defFonts = "defaults.zip";
    m_defaultFont = 0;
    if(m_fileSystem->existFile(defFonts.c_str()))
    {
        m_fileSystem->addZipFileArchive(defFonts.c_str());
        m_defaultFont = m_gui->getFont("tdeffont.xml");
        if(m_defaultFont)
        {
            m_defaultFont->grab();
            m_gui->getSkin()->setFont(m_defaultFont);
        }
    }
    if(!m_defaultFont)
        printf("Error loading defaults.zip\n");
 
    m_device->setWindowCaption(L"idebug");
 
    m_camera = m_sceneManager->addCameraSceneNodeFPS(0, 100.0f, 100.0f);
    m_camera->setPosition(vector3df(0,10,0));
 
 
    IGUIStaticText* stext = getGUI()->addStaticText(L" ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789 ",
        rect<s32>(50,200,350,225),false,false,0,true);
    stext->setBackgroundColor(SColor(129,128,0,0));
    stext->setOverrideColor(SColor(255,255,255,255));
 
    while(m_device->run() && m_running)
    {
        m_videoDriver->beginScene(true, true, SColor(255,100,101,140));
 
        m_sceneManager->drawAll();
        m_gui->drawAll();
 
        m_videoDriver->endScene();
    }
 
    if(m_defaultFont)
        m_defaultFont->drop();
    m_device->drop();
    delete m_eventReceiver;    
 
    return 0;
} 
Make sure the "defaults.zip" (includes custom font) file exists in the same directory as the executable and it's loaded by addZipFileArchive().

The reason moving "!found" in front of xml->read() fixes the problem is that xml->read() isn't executed when "found" is set to true inside the loop. I suspect this may be related to the fairly recent tightening up of the xml reader source code.

Let me know if you need anything else.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: [bug] Custom font causes crash

Post by CuteAlien »

Ok, thank you. For some reason it had worked on Linux, which should probably worry me (xml-reading should behave similar now, that was the point behind the xml-patches...). Anyway, changing is definitely correct as it should not read the next xml node when it has found the type.

Fixed in svn trunk r4109
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