Thread: string question

  1. #1
    Registered User
    Join Date
    Jan 2011

    string question

    I am trying to load a file using a string as a file name. This is the class that uses the string to load in the file.
    class Texture
    	int m_width;					//width of the image
    	int m_height;					//height of the image
    	unsigned char* m_pixels;		//pixel data
    	Texture(std::string fileName);
    	int getWidth();
    	int getHeight();
    	unsigned char* getPixels();
    In the fuction for the drawer class, I create a new Texture, and supply a string for the file to load in. (only related code posted). m_currentLevel is a Level class.
    getFloorTexName() simply returns the string of the filename used for the floor texture.
    std::string texName = m_currentLevel->getFloorTexName();
    Texture* texture = new Texture(texName);
    GLuint ID = loadTexture(texture);
    Using this code, the program compiles just fine, but I get this error when I run it.
    Access violation reading location 0x00000018.
    The compiler is pointing to this function in the <xstring> header file.
    size_type size() const
    {	// return length of sequence
             return (this->_Mysize);
    Am I not using the string class correctly? What is causing this error?

  2. #2
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Sounds like the same kind of problem you asked about earlier today. Check your pointers to string objects. My guess is that it's in getFloorTexName.
    Consider this post signed

  3. #3
    Registered User
    Join Date
    Jan 2011
    I am not using pointer for my strings. getFloorTexName() returns a string object, not a pointer. I'm going to step through my code and see if I can't see anything wrong.

    EDIT- ok I know what the problem is, I just don't know how to fix it, but I think I will try it on my own. (Shouldn't be too hard to figure out if I look at it for awhile.)
    Last edited by insanoflex; 01-21-2011 at 11:19 AM. Reason: update response

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Reusing a string pointer question
    By chiefmonkey in forum C++ Programming
    Replies: 3
    Last Post: 05-06-2009, 04:53 PM
  3. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  4. String array question
    By gogo in forum C++ Programming
    Replies: 6
    Last Post: 12-08-2001, 06:44 PM