How are my arguments getting corrupted?

So I recently took it upon myself to learn Lua for the game project I'm working on(targeting Windows 7 using Visual Studio 2010 and the Ogre3D engine), at around the same time I started implementing the library of choice for our GUI system, QuickGUI. I decided to outsource font loading to lua as a learning experience and began to run into errors. Thinking it was my inexperience with lua, I spent several days researching what the problem might be, but then upon reproducing the error in pure C++, I've run into the same issue.

To start up QuickGUI's FontManager, I first create an instance of the skin effect managers and resource managers, then use those to create the QuickGUI::Core object, then call the static singleton function to get a pointer to the FontManager object. I then create a useable font by passing it a string with the requested name of the font, an Image object representing the rendered font in a *.png, an int to determine the baseline, and the name of an associated XML file describing the individual characters. As follows:

      GUIResourceManager* mGuiResourceManager = new GUIResourceManager();
      GUISkinEffectManager* skinEffectMgr = new GUISkinEffectManager();

      QuickGUI::Core* GUICore = new QuickGUI::Core(mGuiResourceManager, skinEffectMgr);

      QuickGUI::FontManager* fontMgr = QuickGUI::FontManager::getSingletonPtr();

      fontMgr->createFont("TimesNewRoman.14", mGuiResourceManager->getImage("TimesNewRoman.14.png"), 10,"fonts/TimesNewRoman.14.xml");

Here is the relevant function from the QuickGUI::FontManager class:

Font* FontManager::createFont(const std::string& name, Image* i, unsigned int baseline, const std::string& fontXMLFile)
{
    if(mFontMap.find(name) != mFontMap.end())
    {
        Log::exception("FontManager::createFont : A font with name "" + name + "" already exists!");

        return NULL;
    }

    TiXmlDocument xmlDoc;
    xmlDoc.LoadFile(fontXMLFile);

    TiXmlElement* root = xmlDoc.LastChild()->ToElement();

    Font* newFont = new Font(name,i,baseline,root);

    mFontMap[name] = newFont;

    return newFont;
}

The QuickGUI library uses TinyXML for parsing. My program was crashing on the xmlDoc.LastChild()->ToElement() call, as the xml was invalid. Upon investigating, I find something strange in debugging: my strings are somehow not making it into the createFont() function. These are the values of the arguments after I set a breakpoint in the beginning of the above function:

    Font* FontManager::createFont(const std::string& name, Image* i, unsigned int baseline, const std::string& fontXMLFile)

name = "¤ð/"
i = 0x0308a738{mName="TimesNewRoman.14.png" mOgreImage=0x00ca3d28}
baseline = 10
fontXMLFile = "|ð/"

Once I noticed this, I first thought it might be trying to interpret a pointer as literal string data; the two values change from runtime to runtime, but they're always only off by each other by a single char. There were two problems with this, first, that Visual Studio was indicating they were strings with the "" markings, and second, that the Image object being created was getting its string just fine, and it accepted the same const std::string& type as an argument. I then thought it might be an issue with my project and Ogre being compiled with Multi-Byte Character Set switched on, and QuickGUI having Unicode instead. I recompiled, re-ran--same issue.

At this point, I don't know what to do. It's not an issue I can see with my call syntax, I've looked through the QuickGUI code (available here), I've double, triple, quadruple-checked my compiling settings, investigated potential compiler-specific issues with implementation of std::string, and overall beaten my brain on this issue for nearly a week to no avail. If anyone would be able to offer insight as to why in God's green earth my string's value is changing erratically like this, I would be most appreciative.

链接地址: http://www.djcxy.com/p/95454.html

上一篇: Ruby sandboxing与整合脚本语言

下一篇: 我的论点如何被破坏?