Getting endpoints from cpSegmentShapeGetA()

Discuss any Chipmunk bugs here.

Getting endpoints from cpSegmentShapeGetA()

Postby teamnine » Sun Feb 24, 2013 4:05 pm

Hello, the code I'm writing allows you to draw on the screen, then have your drawings interact using collision detection. The drawings are generated using Cairo under GTK, but the issue that I'm having is that when I draw the shapes, which are a bunch of segments, they begin falling correctly, but then it throws an error:
Code: Select all
 "Aborting due to Chipmunk error: shape is not a cpSegmentShape
   Failed condition: shape->klass == &cpSegmentShapeClass
   Source:/tmp/chipmunk-Vz8Z/slembcke-Chipmunk-Physics-14b5a4f/src/cpShape.c:341"


This error occurs in the cpSegmentShapeGetA() function here:
Code: Select all
void graphicsDrawFree(cairo_t* cr, cpShape* shape, gameBody *body)
{
    //Get the endpoints of the line -> Throws an assertion if shape is not a segment
    cpVect start = cpSegmentShapeGetA(shape);
    cpVect end = cpSegmentShapeGetB(shape);

    printf("GRAPHICS::GOT SEGMENT ENDS\n");
       
,

and after running through GDB, it appears that when this error is called, shape is a (cpShape *). The GDB output is below:
Code: Select all
Aborting due to Chipmunk error: shape is not a cpSegmentShape
   Failed condition: shape->klass == &cpSegmentShapeClass
   Source:/tmp/chipmunk-Vz8Z/slembcke-Chipmunk-Physics-14b5a4f/src/cpShape.c:341

Program received signal SIGABRT, Aborted.
0x00007fff81ec70b6 in __kill ()
(gdb) bt
#0  0x00007fff81ec70b6 in __kill ()
#1  0x00007fff81f679f6 in abort ()
#2  0x000000010000c5a7 in cpMessage ()
#3  0x0000000100015834 in cpSegmentShapeGetA ()
#4  0x000000010000415c in graphicsDrawFree (cr=0x10400fc00, shape=0x102547dfd, body=0x10254c710) at graphics.c:224
#5  0x0000000100003ac0 in graphicsDisplayBody (surface=0x1025487f0, body=0x10254c710) at graphics.c:97
#6  0x00000001000038ed in graphicsDisplayWorld (surface=0x1025487f0, space=0x1025672a0) at graphics.c:40
#7  0x00000001000027ae in guiDrawWorld (worldDisplay=0x1028c0830) at gui.c:216
#8  0x0000000100002732 in timerCB (worldDisplay=0x1028c0830) at gui.c:175
#9  0x0000000100ad5a6d in g_timeout_dispatch ()
#10 0x0000000100ad4f32 in g_main_context_dispatch ()
#11 0x0000000100ad6982 in g_main_context_iterate ()
#12 0x0000000100ad7ad5 in g_main_loop_run ()
#13 0x000000010014fadd in gtk_main ()
#14 0x00000001000038a4 in main (argc=1, argv=0x7fff5fbff7a8) at gui.c:694
(gdb) up
#1  0x00007fff81f679f6 in abort ()
(gdb) up
#2  0x000000010000c5a7 in cpMessage ()
(gdb) up
#3  0x0000000100015834 in cpSegmentShapeGetA ()
(gdb) up
#4  0x000000010000415c in graphicsDrawFree (cr=0x10400fc00, shape=0x102547dfd, body=0x10254c710) at graphics.c:224
224       cpVect start = cpSegmentShapeGetA(shape);
(gdb) up         
#5  0x0000000100003ac0 in graphicsDisplayBody (surface=0x1025487f0, body=0x10254c710) at graphics.c:97
97                       graphicsDrawFree(cr, body->arrayOfShapes[i], body);
(gdb) print body->arrayOfShapes[i]
$1 = (cpShape *) 0x102547dfd
(gdb) down
#4  0x000000010000415c in graphicsDrawFree (cr=0x10400fc00, shape=0x102547dfd, body=0x10254c710) at graphics.c:224
224       cpVect start = cpSegmentShapeGetA(shape);
(gdb) print shape
$2 = (cpShape *) 0x102547dfd


Not sure if I'm doing something wrong, or where to go from here.
teamnine
 
Posts: 1
Joined: Sun Feb 24, 2013 3:54 pm

Re: Getting endpoints from cpSegmentShapeGetA()

Postby slembcke » Sun Feb 24, 2013 5:30 pm

The two strongest possibilities I can think of are that the shape is not actually a segment shape, or that you have a dangling pointer.

To check the first case, cast the shape pointer to a cpSegmentShape pointer and print out the struct. If the core cpShape fields look valid, then you probably have a real cpShape pointer. If the cpSegmentFields look valid, then you have a cpSegmentShape pointer. If neither is true, then you probably have a dangling pointer.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm


Return to Bugs

Who is online

Users browsing this forum: No registered users and 1 guest

cron