Skip to main content
gamedev.net
🔒 Locked

Problems loading textures

Started by KILE Jul 31, 2001 at 12:26 PM 0 replies 300+ views
Original Post
KILE
KILE
Hi all, I''m writing some spanish tutorial about OpenGL based on the Nehe''s tutorials. I have a problem when I load textures, basically I do the same that Nehe and this run good in my computer and others computer''s friends, but some people talk to me that they can run this tutorial because this craft at the start with de "Debug assertion failed" windows or "Internal error", tracing when loading texture. Why? Here is the implementation of the CTextura object: //--------------------------------------------------------------- // Nombre: Constructor // Descripcion: Constructor de la clase. Inicializa las variables // Parametros: Ninguno //--------------------------------------------------------------- CTextura::CTextura() { m_nID=0; } //--------------------------------------------------------------- // Nombre: Destructor // Descripcion: Destructor de la clase. Elimina la textura // Parametros: Ninguno //--------------------------------------------------------------- CTextura::~CTextura() { Elimina(); } //--------------------------------------------------------------- // Nombre: Crear // Descripcion: Establece los parámetros GL para cargar // Parametros: // char* szNombreFichero: Nombre del fichero a cargar //--------------------------------------------------------------- bool CTextura::Crear(char* szNombreFichero) { Elimina(); // Copiamos el nombre de fichero unsigned long int nszLon = strlen(szNombreFichero); // Generamos la ID de la textura glGenTextures(1, &m_nID); m_nID++; // Usamos un offset de +1 para diferenciar del estado no-inicializado glBindTexture(GL_TEXTURE_2D, m_nID-1); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); return true; } //--------------------------------------------------------------- // Nombre: Elimina // Descripcion: Elimina la textura // Parametros: Ninguno //--------------------------------------------------------------- void CTextura::Elimina() { if( m_nID ) { m_nID--; glDeleteTextures(1, &m_nID); m_nID=0; } } //--------------------------------------------------------------- // Nombre: Usa // Descripcion: Usa la textura actual // Parametros: Ninguno //--------------------------------------------------------------- void CTextura::Usa() { glBindTexture(GL_TEXTURE_2D, m_nID-1); } //--------------------------------------------------------------- // Nombre: CargarBMP // Descripcion: Carga un fichero BMP y almacena los datos // Parametros: Ninguno //--------------------------------------------------------------- bool CTextura::CargarBMP(char *szNombreFichero) { FILE *hFichero; AUX_RGBImageRec *Imagen; bool bResultado=false; if (szNombreFichero) // Comprobamos que el nombre de fichero sea correcto { hFichero=fopen(szNombreFichero,"r"); // Comprobamos si el fichero existe (Si podemos abrirlo) if (hFichero) // ¿Existe el fichero? { fclose(hFichero); // Cerramos el handle Crear(szNombreFichero); Imagen=auxDIBImageLoad(szNombreFichero); // Cargamos el BMP m_nAncho=Imagen->sizeX; m_nAlto=Imagen->sizeY; glTexImage2D(GL_TEXTURE_2D, 0, 3, m_nAncho, m_nAlto, 0, GL_RGB, GL_UNSIGNED_BYTE, Imagen->data); bResultado=true; } } delete Imagen->data; delete Imagen; return bResultado; } All the code can be found in: http://usuarios.tripod.es/andromeda_studios/descarga/tutoriales/tutorial_7b.zip Thanks and sorry about my poor english
Ben_
Ben_
Hello,

Perhaps, you should use
free(Imagen->data);
and
free(Imagen);
instead of
delete Imagen->data;
and
delete Imagen;

Its right that new and delete should be preferred, but here you free sth that was allocated with malloc() before, so you MUST free it with free().

Greetings Ben

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.