Jump to content
  • Advertisement
Sign in to follow this  
Michael2006

help with segmentation fault on MD2 file

This topic is 4401 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to display an array of MD2 characters in a world and I am getting a segmentation fault when building the mipmap for the skin file ................... CTargaImage image; image.Load(skinFile); glGenTextures(1,&m_texID); glBindTexture(GL_TEXTURE_2D,m_texID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGB,image.GetWidth(),image.GetHeight(),GL_RGB,GL_UNSIGNED_BYTE,image.GetImage()); ............................................ the gluBuild2DMipmap gives the segmentation fault as reported by gdb under Linux. the Meta properties for the Targa file are 432x142 pixels? 24bpp RGB Runlength encoded would this cause the problem? should the image be smaller 64x64 etc??

Share this post


Link to post
Share on other sites
Advertisement
Try resizing the image with dimensions of "power of 2" for example 512x128...
GFX cards (not some new ones) require the image to have dimensions that follow this.

EDIT: Oh and are you sure your CTargaImage::Load() function works correctly? You could get faulty data otherwise...

Share this post


Link to post
Share on other sites
Yea my thoughts exactly.
If your image.Load function failes, you are likely to get segmentation faults when accessing the image member functions later on

Share this post


Link to post
Share on other sites
I have a skybox and a textured landscape and my tga seems to be working for these
I scaled the images for the binding to 3Dmodel and still get a segmentation fault??
Any suggestions are welcome!

Share this post


Link to post
Share on other sites
Well...


gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGB,image.GetWidth(),image.GetHeight(),GL_RGB,GL_UNSIGNED_BYTE,image.GetImage());

Looking at MSDN i see that the second param is a value between 1-4, and GL_RGB isn't defined as 3 (but 0x1907) so try replacing the second param with a 3.

Try to not RLE your file, just to see if that's the problem.

Quote:

I have a skybox and a textured landscape and my tga seems to be working for these

Make sure the skybox and MD2 texture is the same format (no RLE and stuff). If the skybox works but not the texture, and they're not the same format, this could very well be a problem with CTargaImage::Load().


glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);

Try to set just GL_LINEAR on both. This has acted somewhat wierd for me at times. Just for debugging.

Share this post


Link to post
Share on other sites
I have tried the following
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGB,image.GetWidth(),image.GetHeight(),GL_RGB,GL_UNSIGNED_BYTE,image.GetImage());
^setting to 3

and still segmentation fault
my skybox code is
....................
CTargaImage image;

image.Load(top);
glGenTextures(1, &m_textures[SKY_TOP]);
glBindTexture(GL_TEXTURE_2D, m_textures[SKY_TOP]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, image.GetWidth(), image.GetHeight(), GL_RGB, GL_UNSIGNED_BYTE, image.GetImage());
image.Release();
......................
and I have tried using CLAMP_TO_EDGE and Im just plain stuck.
my Model load function goes like
.....................................
m_rhinoModel.Load("rhino/tris.md2","rhino/rhino.tga");
m_centaurModel.Load("centaur/tris.md2","centaur/centaur.tga";
m_demonModel.Load("nemocromicus/tris.md2","necromicus/necromicus.tga");
......................................
and the MD2 load is like where scale is set to a constant
bool CMD2Model::Load(const char *modelFile,const char *skinFile,GLfloat scale)
{
FILE *pF;
if((pF = fopen(modelFile,"rb"))==NULL){
return false;
}


fread(&m_info,sizeof(modelHeader_t),1,pF);

m_verts = new xyz_t[m_info.numXYZ * m_info.numFrames];



char *buffer = new char[m_info.numFrames * m_info.framesize];


//////////
// initialize member variables




fseek(pF,m_info.offsetFrames,SEEK_SET);
fread(buffer,m_info.numFrames,m_info.framesize,pF);

int i,j;
frame_t *frame;
xyz_t *pVerts;
m_miny = FLT_MAX;
GLfloat maxy = FLT_MIN;

for(j=0;j<m_info.numFrames;++j)
{
frame =(frame_t*)&buffer[m_info.framesize*j];
pVerts = (xyz_t*)&m_verts[m_info.numXYZ*j];
for(i=0;i<m_info.numXYZ;i++)
{
pVerts.x = scale*(frame->scale[0]*frame->fp.v[0]+frame->translate[0]);
pVerts.x = scale*(frame->scale[1]*frame->fp.v[1]+frame->translate[1]);
pVerts.x = scale*(frame->scale[2]*frame->fp.v[2]+frame->translate[2]);

if(j==0)
{
if(pVerts.y<m_miny)
m_miny = pVerts.y;
if(pVerts.y > maxy)
maxy = pVerts.y;
}
}
}
CalculateBoundingSphere(m_boundingSphere,m_miny,maxy);
// Move(0,0,0);

m_tris = new mesh_t[m_info.numTris];

fseek(pF,m_info.offsetTris,SEEK_SET);
fread(m_tris,m_info.numTris,sizeof(mesh_t),pF);

stIndex_t *stTemp = new stIndex_t[m_info.numST];
m_texCoords = new texCoord_t[m_info.numTris*3];

fseek(pF,m_info.offsetST,SEEK_SET);
fread(stTemp,m_info.numST,sizeof(stIndex_t),pF);

int index =0;
for(i=0;i<m_info.numTris;i++)
{
m_texCoords[index].s = (float)stTemp[m_tris.stIndex[0]].s / m_info.skinwidth;
m_texCoords[index++].t = 1.0f - (float)stTemp[m_tris.stIndex[0]].t / m_info.skinheight;
m_texCoords[index].s = (float)stTemp[m_tris.stIndex[1]].s / m_info.skinwidth;
m_texCoords[index++].t = 1.0f -(float)stTemp[m_tris.stIndex[1]].t / m_info.skinheight;
m_texCoords[index].s = (float)stTemp[m_tris.stIndex[2]].s / m_info.skinwidth;
m_texCoords[index++].t = 1.0f - (float)stTemp[m_tris.stIndex[2]].s / m_info.skinheight;
}

m_currentVerts = new xyz_t[m_info.numTris * 3];

//close file and free mem
fclose(pF);
//pFile.close();
delete[]buffer;

CTargaImage image;
image.Load(skinFile);
glGenTextures(1,&m_texID);
glBindTexture(GL_TEXTURE_2D,m_texID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGB,image.GetWidth(),image.GetHeight(),GL_RGB,GL_UNSIGNED_BYTE,image.GetImage());

image.Release();

m_currentFrame = 0;
m_nextFrame = 1;
m_interpol = 0.0;

//animate least 1 frame to make sure m_currentVerts get inited
SetAnimation(IDLE,IDLE);
Animate(0);

return true;
}

If you can suggest anything I would be willing to try it.
Thanks
Michael2006

Share this post


Link to post
Share on other sites
Did you try to remove the Run Length Encoding from your image files?

The only thing i can think of is that it really IS your CTargaImage::Load() func that dosn't work correctly.
You could try to load an image that you already know will load and display correctly, and use that for texture for now. If that should work then we know for sure. If not, perhaps it's something else that you havn't wrote...i mean with your compiler or something like that...

Share this post


Link to post
Share on other sites
As i said the skybox and texture loads fine which is Targa but my 3D model and texture wont load. As a last resort I bought the book on 3D model standards and am waiting for its delivery and that should get me started!.

Many Thanks
Michael2006

Share this post


Link to post
Share on other sites
Quote:

As i said the skybox and texture loads fine which is Targa

Yes, but as you also said the MD2 texture is RLE. Are you 100% sure the other images also are RLE? Did you try to load the skybox texture as the MD2 texture?
This is simple elimination.
Have you also stepped through your code during runtime, into every single little function (especially CTargaImage::Load()) and made sure< your data is correct?
Don't always trust that things will work in one place just because it did in another, until you have confirmed all data. =)

You said the gluBuild2DMipmaps() gave you the seg. fault, the you can hopefully rule out there's anything wrong woth your MD2 loading code (for now).

You could also see if you get any error returned from gluBuild2DMipmaps() (perhaps not very likely, but can't hurt to check all GL functions you have there).

int ret = gluBuild2DMimpaps();
if(ret)
char *str = gluErrorString(ret);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!