Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-14-2011, 11:08 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 122
architectpianist is on a distinguished road
Default OpenGL EXC_BAD_ACCESS

Hi,
I have a bit of a jumble of code that I'm trying to use to cobble together some dynamic 3D rendering. I've been using Jeff LaMarche's tutorials (here).
The code is here:
Code:
NSArray *row = [plane objectAtIndex:index];
GLushort connectionStrips[[row count] * 2];
		
if (index % 2 == 0)	//Even = on the mark, so the one above is off the mark
{
	int enterIndex = 0;
	for (int i = 0; i < [row count]; i++) 
	{
		connectionStrips[enterIndex] = index * [row count] + i + [row count];
		connectionStrips[enterIndex + 1] = index * [row count] + i;
		enterIndex += 2;
	}
}
else				//Odd
{
	int enterIndex = 0;
	for (int i = 0; i < [row count]; i++) 
	{
		connectionStrips[enterIndex] = (index * [row count]) + i;
		connectionStrips[enterIndex + 1] = (index * [row count]) + i + [row count];
		enterIndex += 2;
	}
}
glDrawElements(GL_TRIANGLE_STRIP, sizeof(connectionStrips) / sizeof(connectionStrips[0]), GL_UNSIGNED_SHORT, connectionStrips);
The EXC_BAD_ACCESS is on the very last line. The connectionStrips array is properly populated. Any ideas what might be causing this code to go astray?
Thanks!
architectpianist is offline   Reply With Quote
Old 06-15-2011, 02:36 AM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

post the entire crash log, however maybe you are going outside index of plane, or maybe plane is a released object.....
__________________
dany_dev is offline   Reply With Quote
Old 06-15-2011, 03:33 AM   #3 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Paris, France
Posts: 946
7twenty7 is on a distinguished road
Default

Quote:
Originally Posted by architectpianist View Post
glDrawElements(GL_TRIANGLE_STRIP, sizeof(connectionStrips) / sizeof(connectionStrips[0]), GL_UNSIGNED_SHORT, connectionStrips);
Are you also using a call to glVertexPointer? glDrawElements reads from the currently enabled vertex/color/texture/etc arrays.

glDrawElements will march through the arrays used in glVertexPointer (et all), so if those are set up incorrectly, you'll get an error when you call glDrawElements.

But yes, I think more of the crash log is in order.
7twenty7 is offline   Reply With Quote
Old 06-15-2011, 09:14 AM   #4 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 122
architectpianist is on a distinguished road
Default

Thanks for the replies
Actually, the crash log doesn't really say anything except
Code:
[Switching to process 30113 thread 0x207]
which I don't think is part of the crash log. Also the green bar in Xcode 4 with the "Program received signal: EXC_BAD_ACCESS" message points to the glDrawElements line. I am calling glVertexPointer as well.
I don't think I should post the entire vertices set as it has 65,536 objects
architectpianist is offline   Reply With Quote
Old 06-15-2011, 09:39 AM   #5 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Paris, France
Posts: 946
7twenty7 is on a distinguished road
Default

Quote:
Originally Posted by architectpianist View Post
Thanks for the replies
Actually, the crash log doesn't really say anything except
Code:
[Switching to process 30113 thread 0x207]
which I don't think is part of the crash log. Also the green bar in Xcode 4 with the "Program received signal: EXC_BAD_ACCESS" message points to the glDrawElements line. I am calling glVertexPointer as well.
I don't think I should post the entire vertices set as it has 65,536 objects
Are you using just glVertexPointer or other pointers as well (color/texcoord)? If just glVertexPointer are you sure you aren't enabling any arrays that you are NOT using?

If you're actually trying to draw a triangle strip with 65k+ verts, I'd recommend just trying a strip of 3 verts (yes, one triangle), just so you can verify all the data properly without your head exploding.

Usually a bad access from glDrawElements means its reading into one of the bound arrays (verts/color/texcoords) past the valid memory. For example, if you bound 3 verts, but then told it to draw a triangle strip using glDrawElements and one of the indices was something greater than 2, it would blow up.
7twenty7 is offline   Reply With Quote
Old 06-15-2011, 09:55 AM   #6 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 122
architectpianist is on a distinguished road
Default

I'm not using color arrays, but I am also using normal arrays.
I did as 7twenty7 advised (sort of) and I found that the EXC_BAD_ACCESS only shows up on and after the fifth loop (the code I posted is inside a for loop). I have 65,536 vertices, but in each loop I'm doing one row of triangle strips to make a sort of mesh. The connectionStrips[] array in the fifth loop is properly populated, and I'm using sizeof instead of a static number.
architectpianist is offline   Reply With Quote
Reply

Bookmarks

Tags
dynamic, exc_bad_access, opengl, triangle strip

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 315
6 members and 309 guests
chemistry, Dnnake, iOS.Lover, lendo, Leslie80, pbart
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:23 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0