hopefully fix frequently segfaults
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Sun, 18 Jun 2006 19:09:36 +0000 (19:09 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Sun, 18 Jun 2006 19:09:36 +0000 (19:09 +0000)
lib/gdi/font.cpp
lib/gdi/font.h
lib/gdi/grc.cpp
lib/gdi/grc.h
lib/gui/einput.cpp
lib/gui/elabel.cpp
lib/service/listboxservice.cpp

index 2ff5fbf..f7c1bca 100644 (file)
@@ -443,7 +443,7 @@ void eTextPara::setFont(Font *fnt, Font *replacement)
 void
 shape (std::vector<unsigned long> &string, const std::vector<unsigned long> &text);
 
 void
 shape (std::vector<unsigned long> &string, const std::vector<unsigned long> &text);
 
-int eTextPara::renderString(const std::string &string, int rflags)
+int eTextPara::renderString(const char *string, int rflags)
 {
        singleLock s(ftlock);
        
 {
        singleLock s(ftlock);
        
@@ -467,11 +467,12 @@ int eTextPara::renderString(const std::string &string, int rflags)
        }
        
        std::vector<unsigned long> uc_string, uc_visual;
        }
        
        std::vector<unsigned long> uc_string, uc_visual;
-       uc_string.reserve(string.length());
+       if (string)
+               uc_string.reserve(strlen(string));
        
        
-       std::string::const_iterator p(string.begin());
+       const char *p = string;
 
 
-       while(p != string.end())
+       while(p)
        {
                unsigned int unicode=(unsigned char)*p++;
 
        {
                unsigned int unicode=(unsigned char)*p++;
 
@@ -481,28 +482,28 @@ int eTextPara::renderString(const std::string &string, int rflags)
                        {
                                unicode&=0x1F;
                                unicode<<=6;
                        {
                                unicode&=0x1F;
                                unicode<<=6;
-                               if (p != string.end())
+                               if (p)
                                        unicode|=(*p++)&0x3F;
                        } else if ((unicode & 0xF0)==0xE0) // three bytes
                        {
                                unicode&=0x0F;
                                unicode<<=6;
                                        unicode|=(*p++)&0x3F;
                        } else if ((unicode & 0xF0)==0xE0) // three bytes
                        {
                                unicode&=0x0F;
                                unicode<<=6;
-                               if (p != string.end())
+                               if (p)
                                        unicode|=(*p++)&0x3F;
                                unicode<<=6;
                                        unicode|=(*p++)&0x3F;
                                unicode<<=6;
-                               if (p != string.end())
+                               if (p)
                                        unicode|=(*p++)&0x3F;
                        } else if ((unicode & 0xF8)==0xF0) // four bytes
                        {
                                unicode&=0x07;
                                unicode<<=6;
                                        unicode|=(*p++)&0x3F;
                        } else if ((unicode & 0xF8)==0xF0) // four bytes
                        {
                                unicode&=0x07;
                                unicode<<=6;
-                               if (p != string.end())
+                               if (p)
                                        unicode|=(*p++)&0x3F;
                                unicode<<=6;
                                        unicode|=(*p++)&0x3F;
                                unicode<<=6;
-                               if (p != string.end())
+                               if (p)
                                        unicode|=(*p++)&0x3F;
                                unicode<<=6;
                                        unicode|=(*p++)&0x3F;
                                unicode<<=6;
-                               if (p != string.end())
+                               if (p)
                                        unicode|=(*p++)&0x3F;
                        }
                }
                                        unicode|=(*p++)&0x3F;
                        }
                }
index b898391..6cc238d 100644 (file)
@@ -126,7 +126,7 @@ public:
        static void forceReplacementGlyph(int unicode) { forced_replaces.insert(unicode); }
 
        void setFont(const gFont *font);
        static void forceReplacementGlyph(int unicode) { forced_replaces.insert(unicode); }
 
        void setFont(const gFont *font);
-       int renderString(const std::string &string, int flags=0);
+       int renderString(const char *string, int flags=0);
 
        void clear();
 
 
        void clear();
 
index 274d221..ef75aac 100644 (file)
@@ -237,7 +237,7 @@ void gPainter::renderText(const eRect &pos, const std::string &string, int flags
        o.dc = m_dc.grabRef();
        o.parm.renderText = new gOpcode::para::prenderText;
        o.parm.renderText->area = pos;
        o.dc = m_dc.grabRef();
        o.parm.renderText = new gOpcode::para::prenderText;
        o.parm.renderText->area = pos;
-       o.parm.renderText->text = string;
+       o.parm.renderText->text = string.empty()?0:strdup(string.c_str());
        o.parm.renderText->flags = flags;
        m_rc->submit(o);
 }
        o.parm.renderText->flags = flags;
        m_rc->submit(o);
 }
@@ -539,7 +539,8 @@ void gDC::exec(gOpcode *o)
                assert(m_current_font);
                para->setFont(m_current_font);
                para->renderString(o->parm.renderText->text, (flags & gPainter::RT_WRAP) ? RS_WRAP : 0);
                assert(m_current_font);
                para->setFont(m_current_font);
                para->renderString(o->parm.renderText->text, (flags & gPainter::RT_WRAP) ? RS_WRAP : 0);
-               
+               if (o->parm.renderText->text)
+                       free(o->parm.renderText->text);
                if (flags & gPainter::RT_HALIGN_RIGHT)
                        para->realign(eTextPara::dirRight);
                else if (flags & gPainter::RT_HALIGN_CENTER)
                if (flags & gPainter::RT_HALIGN_RIGHT)
                        para->realign(eTextPara::dirRight);
                else if (flags & gPainter::RT_HALIGN_CENTER)
index 58371e7..1135550 100644 (file)
@@ -78,7 +78,7 @@ struct gOpcode
                struct prenderText
                {
                        eRect area;
                struct prenderText
                {
                        eRect area;
-                       std::string text;
+                       char *text;
                        int flags;
                } *renderText;
 
                        int flags;
                } *renderText;
 
index 62a77c5..30dc3f0 100644 (file)
@@ -55,7 +55,7 @@ int eInput::event(int event, void *data, void *data2)
                
                eDebug("cursor is %d", cursor);
                para->setFont(m_font);
                
                eDebug("cursor is %d", cursor);
                para->setFont(m_font);
-               para->renderString(text, 0);
+               para->renderString(text.empty()?0:text.c_str(), 0);
                int glyphs = para->size();
                
                if (m_have_focus)
                int glyphs = para->size();
                
                if (m_have_focus)
index 591b725..5c8e0b7 100644 (file)
@@ -36,7 +36,7 @@ int eLabel::event(int event, void *data, void *data2)
                        style->setStyle(painter, eWindowStyle::styleLabel);
                        ePtr<eTextPara> para = new eTextPara(eRect(0, 0, size().width(), size().height()));
                        para->setFont(m_font);
                        style->setStyle(painter, eWindowStyle::styleLabel);
                        ePtr<eTextPara> para = new eTextPara(eRect(0, 0, size().width(), size().height()));
                        para->setFont(m_font);
-                       para->renderString(m_text, 0);
+                       para->renderString(m_text.empty()?0:m_text.c_str(), 0);
                        para->realign(eTextPara::dirLeft);
                        int glyphs = para->size();
 
                        para->realign(eTextPara::dirLeft);
                        int glyphs = para->size();
 
@@ -185,7 +185,7 @@ eSize eLabel::calculateSize()
        ePtr<eTextPara> p = new eTextPara(eRect(0, 0, size().width(), size().height()));
        
        p->setFont(m_font);
        ePtr<eTextPara> p = new eTextPara(eRect(0, 0, size().width(), size().height()));
        
        p->setFont(m_font);
-       p->renderString(m_text, RS_WRAP);
+       p->renderString(m_text.empty()?0:m_text.c_str(), RS_WRAP);
        
        eRect bbox = p->getBoundBox();
        return bbox.size();
        
        eRect bbox = p->getBoundBox();
        return bbox.size();
index 0b7b730..284776f 100644 (file)
@@ -427,7 +427,7 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
 
                                eTextPara *para = new eTextPara(tmp);
                                para->setFont(m_element_font[e]);
 
                                eTextPara *para = new eTextPara(tmp);
                                para->setFont(m_element_font[e]);
-                               para->renderString(text);
+                               para->renderString(text.c_str());
 
                                if (e == celServiceName)
                                {
 
                                if (e == celServiceName)
                                {