Jump to content
  • Advertisement
Sign in to follow this  
Timptation

debugging ideas

This topic is 2713 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

Without posting a huge function (edit: posted some code in next reply below), I'm having some trouble and would like to get some thoughts on what the issue might be. During a function that reads in a text file (279KB), I seem to be leaving the function prematurely on a line that is just an assignment, retrieving the value from an array (which is indexed within bounds). I'm not sure what could make something do this. The function worked fine at first (its an .obj model loader) with smaller files, but then I tried a bigger file and now I'm not sure what the deal is. I'm coding in objective-c for an iPhone game, and although memory is tight, it shouldn't be so tight that I can't load in a 279KB text file... (come to think of it, I don't know how much memory I have to work with... but still). Could this even be a memory issue? I'm just not sure what kind of problems could allow for this kind of behavior....

Share this post


Link to post
Share on other sites
Advertisement
Did you get any error messages - if so, what did they say? Did you try stepping through your function with the debugger? If so, did you see anything suspicious? Can you load that particular .obj file in a modeling program or with another loader? Did you write the .obj loading code yourself or did you use an existing library? The more information you can get, the easier it will be to pinpoint the source of the problem.

Share this post


Link to post
Share on other sites
You said "huge function", then you may refactor to split to small functions. That doesn't help to solve the bug, but it helps to scope down the problem.
Also, if it stops at weird place, maybe you can try to remove that line (for test only) to see what happens. If it works, then try change that line in other way.

But it will be quite helpful if you can post piece of problematical code.

Share this post


Link to post
Share on other sites
I don't have any error messages, console or otherwise, and when I step through the code, I end up just exiting the function at the line with marked below with [color="#1C2837"]/* RETURNS: */ as if I had hit a return statement and the code continues. 'i' in the for loop is 3000+ at the time of the return. Here is a portion of the function where it leaves prematurely:
EDIT: starting to look like a bad array index. Not sure how that led to returning from the function, but there you have it. Any thoughts?

[color="#7340a3"] NSMutableArray[color="#000000"]* finalData = [[NSMutableArray [color="#3f217c"]alloc[color="#000000"]] [color="#3f217c"]initWithCapacity[color="#000000"]:[color="#2832cf"]0[color="#000000"]];

[color="#7340a3"][color="#000000"] NSMutableArray[color="#000000"]* finalIndecies = [[NSMutableArray [color="#3f217c"]alloc[color="#000000"]] [color="#3f217c"]initWithCapacity[color="#000000"]:[color="#2832cf"]0[color="#000000"]];




[color="#008326"][color="#000000"] [color="#bf2e9d"]unsigned [color="#bf2e9d"]int[color="#000000"] facesCount = [theFaces [color="#3f217c"]count[color="#000000"]];// Is actually a vert data component count...

[color="#4b8186"]VertexData_VTN tempVertData;

[color="#7340a3"]NSValue* boxedVertData;

[color="#7340a3"]NSNumber* tempIndexWrapper;

[color="#bf2e9d"][color="#000000"] unsigned short[color="#000000"] newIndex;



[color="#bf2e9d"]for([color="#bf2e9d"]int i = [color="#2832cf"]0; i < facesCount; i +=[color="#2832cf"]3)

{

[color="#008326"][color="#000000"] // Set up a vertData from face indecies (remember .obj files are 1 based, so use face index - 1)

tempVertData.[color="#4b8186"]vertex.[color="#7340a3"]x = [[theVerts [color="#3f217c"]objectAtIndex: ([[theFaces [color="#3f217c"]objectAtIndex: i] [color="#3f217c"]unsignedIntValue] - [color="#2832cf"]1) * [color="#2832cf"]3] [color="#3f217c"]floatValue];

tempVertData.[color="#4b8186"]vertex.[color="#7340a3"]y = [[theVerts [color="#3f217c"]objectAtIndex: ([[theFaces [color="#3f217c"]objectAtIndex: i] [color="#3f217c"]unsignedIntValue] - [color="#2832cf"]1) * [color="#2832cf"]3 + [color="#2832cf"]1] [color="#3f217c"]floatValue];

tempVertData.[color="#4b8186"]vertex.[color="#4b8186"]z = [[theVerts [color="#3f217c"]objectAtIndex: ([[theFaces [color="#3f217c"]objectAtIndex: i] [color="#3f217c"]unsignedIntValue] - [color="#2832cf"]1) * [color="#2832cf"]3 + [color="#2832cf"]2] [color="#3f217c"]floatValue];

tempVertData.[color="#4b8186"]UVs.[color="#7340a3"]x = [[theUVs [color="#3f217c"]objectAtIndex: ([[theFaces [color="#3f217c"]objectAtIndex: i + [color="#2832cf"]1] [color="#3f217c"]unsignedIntValue] - [color="#2832cf"]1) * [color="#2832cf"]2] [color="#3f217c"]floatValue];

tempVertData.[color="#4b8186"]UVs.[color="#7340a3"]y = [[theUVs [color="#3f217c"]objectAtIndex: ([[theFaces [color="#3f217c"]objectAtIndex: i + [color="#2832cf"]1] [color="#3f217c"]unsignedIntValue] - [color="#2832cf"]1) * [color="#2832cf"]2 + [color="#2832cf"]1] [color="#3f217c"]floatValue];

[color="#008326"][color="#000000"] tempVertData.[color="#4b8186"]UVs[color="#000000"].[color="#7340a3"]y[color="#000000"] = [color="#3f217c"]fabs[color="#000000"]( [color="#2832cf"]1.0f[color="#000000"] - tempVertData.[color="#4b8186"]UVs[color="#000000"].[color="#7340a3"]y[color="#000000"] );// Images are stored upside-down on the iPhone.

/* RETURNS: */ tempVertData.[color="#3f217c"]normal.[color="#7340a3"]x = [[theNormals [color="#3f217c"]objectAtIndex: ([[theFaces [color="#3f217c"]objectAtIndex: i + [color="#2832cf"]2] [color="#3f217c"]unsignedIntValue] - [color="#2832cf"]1) * [color="#2832cf"]3] [color="#3f217c"]floatValue];

tempVertData.[color="#3f217c"]normal.[color="#7340a3"]y = [[theNormals [color="#3f217c"]objectAtIndex: ([[theFaces [color="#3f217c"]objectAtIndex: i + [color="#2832cf"]2] [color="#3f217c"]unsignedIntValue] - [color="#2832cf"]1) * [color="#2832cf"]3 + [color="#2832cf"]1] [color="#3f217c"]floatValue];

tempVertData.[color="#3f217c"]normal.[color="#4b8186"]z = [[theNormals [color="#3f217c"]objectAtIndex: ([[theFaces [color="#3f217c"]objectAtIndex: i + [color="#2832cf"]2] [color="#3f217c"]unsignedIntValue] - [color="#2832cf"]1) * [color="#2832cf"]3 + [color="#2832cf"]2] [color="#3f217c"]floatValue];



[color="#008326"][color="#000000"] // Get index either as new vert, or one that already exists

newIndex = [finalData [color="#3f217c"]count];

[color="#bf2e9d"]for([color="#bf2e9d"]int j = [color="#2832cf"]0; j < [finalData [color="#3f217c"]count]; j++)

{

[color="#bf2e9d"]if([color="#2e595d"]isSameVertex(&tempVertData, ([color="#4b8186"]VertexData_VTN*)[finalData [color="#3f217c"]objectAtIndex: j]))

{

newIndex = j;

[color="#bf2e9d"]break;

}

}



tempIndexWrapper = [[color="#7340a3"]NSNumber [color="#3f217c"]numberWithUnsignedShort: newIndex];

[finalIndecies [color="#3f217c"]addObject:tempIndexWrapper];



[color="#008326"][color="#000000"] // Add the vert if it isn't a duplicate (wasn't found, so newIndex should still == [finalData count])

[color="#bf2e9d"]if(newIndex == [finalData [color="#3f217c"]count])

{

boxedVertData = [[color="#7340a3"]NSValue [color="#3f217c"]valueWithBytes:&tempVertData [color="#3f217c"]objCType:[color="#bf2e9d"]@encode([color="#4b8186"]VertexData_VTN)];

[finalData [color="#3f217c"]addObject: boxedVertData];

}

}

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!