Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5345 in orxonox.OLD


Ignore:
Timestamp:
Oct 10, 2005, 12:49:53 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: Text now does not segfault anymore, if Font could not be loaded

Location:
trunk/src/lib/graphics/text_engine
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/text_engine/text.cc

    r5344 r5345  
    8383  Vector tmpVec;
    8484
    85   tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, &fontSize);
    86   if (tmpFont != NULL)
    87   {
    88     if (this->font != NULL)
    89       ResourceManager::getInstance()->unload(this->font);
    90     this->font = tmpFont;
    91   }
    92 
    93   else
    94   {
    95     PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile);
    96     if (this->font != NULL)
    97       ResourceManager::getInstance()->unload(this->font);
    98     this->font = NULL;
     85  // unloading the Font if we alrady have one loaded.
     86  if (this->font != NULL)
     87    ResourceManager::getInstance()->unload(this->font);
     88  this->font = NULL;
     89
     90  // load a new Font
     91  if (fontFile != NULL)
     92  {
     93    tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, &fontSize);
     94    if (tmpFont != NULL)
     95      this->font = tmpFont;
     96    else
     97      PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile);
    9998  }
    10099}
     
    166165}
    167166
     167
    168168/**
    169169 *  creates a texture out of the given parameters
    170 
    171    this has to be called every time by the user, to if changes were made.
    172    this is only for TEXT_STATIC-mode
     170 *
     171 * this has to be called every time by the user, to if changes were made.
     172 * this is only for TEXT_STATIC-mode
    173173 */
    174174void Text::createTexture()
    175175{
    176   SDL_Surface* tmpSurf;
     176  SDL_Surface* tmpSurf = NULL;
    177177  if (this->texture)
    178178    glDeleteTextures(1, &this->texture);
     
    184184                                     theColor);
    185185  }
    186   if (tmpSurf)
     186  if (tmpSurf != NULL)
     187  {
    187188    this->texture = loadTexture(tmpSurf, &this->texCoord);
    188189
    189   this->width = tmpSurf->w;
    190   this->height = tmpSurf->h;
    191   SDL_FreeSurface(tmpSurf);
     190    this->width = tmpSurf->w;
     191    this->height = tmpSurf->h;
     192    SDL_FreeSurface(tmpSurf);
     193  }
    192194}
    193195
     
    289291////////////
    290292/**
    291  *  Loads a Font from an SDL_surface into a texture.
     293 * Loads a Font from an SDL_surface into a texture.
    292294 * @param surface The surface to make the texture of
    293295 * @param texCoord The texture coordinates of the 4 corners of the texture
  • trunk/src/lib/graphics/text_engine/text.h

    r5344 r5345  
    5959    Text(const char* fontFile, unsigned int fontSize = TEXT_DEFAULT_SIZE, TEXT_RENDER_TYPE type = TEXT_RENDER_DYNAMIC);
    6060    ~Text();
    61 
    6261    void init();
    6362
    6463    void setFont(const char* fontFile, unsigned int fontSize);
     64
    6565    void setType(TEXT_RENDER_TYPE type);
    6666    void setText(const char* text, bool isExtern = false);
     
    8484
    8585  private:
    86 
    87   private:
    8886    Font*             font;           //!< Font of this text
    8987
     
    9593
    9694  // placement in openGL
    97     GLuint            texture;        //!< A GL-texture to hold the text
     95    GLuint            texture;        //!< A GL-texture to hold the text (static Mode)
    9896    TexCoord          texCoord;       //!< Texture-coordinates @todo fix this to have a struct
    9997    float             height;
Note: See TracChangeset for help on using the changeset viewer.