Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Texture artifacts and std::map crash

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2014

    Texture artifacts and std::map crash

    I iterate an std::map to load textures into OGL, but it does crash after the end of an iteration and before the start of the next. It occurs after the same iteration every time for specific contents of the map, regardless of what element would come next. The problem does not occur without the code inside the loop, so the error likely happens within the loop.

    Code :
    // ...
    typedef std::list<RenderObject*> ObjectList;
    template <typename T> class Scene
    	typedef MipMap<T> Tex;
    	typedef std::map<std::string, Tex*, StringCompareCaseInsensitive> TexMap;
    	typedef std::map<std::string, GLuint, StringCompareCaseInsensitive> GLTexMap;
    	typedef std::pair<std::string, GLuint> GLTexMapPair;
    	// ...
    	void initToGL() {
    		std::cout << "Soft iteration:" << std::endl; // This iteration works fine
    		for (TexMap::iterator it = textures.begin(); it != textures.end(); it++) {
    			std::cout << "Texture: " << it->first << std::endl;
    		for (TexMap::iterator it = textures.begin(); it != textures.end(); it++) { // Crash right here
    			std::cout << "Making texture " << std::flush;
    			std::cout << it->first << "..." << std::endl;
    			MipMap<T>* mipMap = it->second;
    			GLuint texture;
    			glGenTextures(1, &texture);
    			glBindTexture(GL_TEXTURE_2D, texture);
    			std::cout << "Generated and bound GL textures." << std::endl;
    			// Make pure RGB texture from texture with palette
    			RGBTexture tex(mipMap->getWidth(0), mipMap->getHeight(0));
    			T* topMap = mipMap->getMipMap(0);
    			for (UINT x = 0; x < mipMap->getWidth(0); x++) {
    				for (UINT y = 0; y < mipMap->getHeight(0); y++) {
    					tex.setColorAt(x, y, topMap->getColorAt(x, y));
    			std::cout << "Built RGBTexture with dimensions " << tex.getWidth() << "x" << tex.getHeight() << std::endl;
    			gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB8, tex.getWidth(), tex.getHeight(),
    				GL_RGB, GL_UNSIGNED_BYTE, (void*) tex.getRawData());
    			std::cout << "Generated mipmaps." << std::endl;
    			glBindTexture(GL_TEXTURE_2D, 0);
    			std::cout << "Unbound texture." << std::endl;
    			glTextureList.emplace(GLTexMapPair(it->first, texture));
    			std::cout << "Emplaced texture." << std::endl;
    		std::cout << "Made textures." << std::endl;
    		for (ObjectList::iterator it = objectList.begin(); it != objectList.end(); it++) {
    	// ...
    	TexMap textures;
    	GLTexMap glTextureList;
    	ObjectList objectList;
    	UINT frameCount;
    	Camera* cam;

    The code works with certain (little) std::map contents, but will sometimes give me rendering artifacts (rainbow stripes):

    Any ideas, or do I have to show more code?

  2. #2
    Junior Member Newbie
    Join Date
    Jan 2014
    Fixed this. Was at some point multiplying with height instead of width.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts