Bug Summary

File:c:\siege\siege/src/modules/physics/collision.c
Location:line 90, column 75
Description:Access to field 'body' results in a dereference of a null pointer (loaded from variable 'shape1')

Annotated Source Code

1/*
2 Copyright (c) 2007 SIEGE Development Team
3 All rights reserved.
4
5 This file is part of libSIEGE.
6
7 This software is copyrighted work licensed under the terms of the
8 2-clause BSD license. Please consult the file "license.txt" for
9 details.
10
11 If you did not recieve the file with this program, please email
12 Tim Chas <darkuranium@gmail.com>.
13*/
14
15#define SG_BUILD_MODULE
16#include <siege/physics/collision.h>
17#include <siege/core/entity.h>
18
19#include <stdlib.h>
20
21#include <chipmunk/chipmunk.h>
22
23/* TODO: Return value */
24void SG_CALL__cdecl _sg_cbPhysicsCollisionBegin(SGPhysicsShape* shape1, SGPhysicsShape* shape2, void* handle)
25{
26 SGPhysicsCollision coll;
27 coll.handle = handle;
28 coll.shape1 = shape1;
29 coll.shape2 = shape2;
30
31 if(shape1 && shape1->body->entity)
32 {
33 if(shape1->body->entity->lcCollisionBegin)
34 shape1->body->entity->lcCollisionBegin(shape1->body->entity, shape2->body->entity, &coll);
35 if(shape1->body->entity->lcCollisionOneBegin)
36 shape1->body->entity->lcCollisionOneBegin(shape1->body->entity, shape2->body->entity, &coll);
37 }
38 if(shape2 && shape2->body->entity)
39 {
40 if(shape2->body->entity->lcCollisionBegin)
41 shape2->body->entity->lcCollisionBegin(shape2->body->entity, shape1->body->entity, &coll);
42 if(shape2->body->entity->lcCollisionTwoBegin)
43 shape2->body->entity->lcCollisionTwoBegin(shape2->body->entity, shape1->body->entity, &coll);
44 }
45}
46void SG_CALL__cdecl _sg_cbPhysicsCollisionPreSolve(SGPhysicsShape* shape1, SGPhysicsShape* shape2, void* handle)
47{
48 SGPhysicsCollision coll;
49 coll.handle = handle;
50 coll.shape1 = shape1;
51 coll.shape2 = shape2;
52
53 if(shape1 && shape1->body->entity)
54 {
55 if(shape1->body->entity->lcCollision)
56 shape1->body->entity->lcCollision(shape1->body->entity, shape2->body->entity, &coll);
57 if(shape1->body->entity->lcCollisionOne)
58 shape1->body->entity->lcCollisionOne(shape1->body->entity, shape2->body->entity, &coll);
59 }
60 if(shape2 && shape2->body->entity)
61 {
62 if(shape2->body->entity->lcCollision)
63 shape2->body->entity->lcCollision(shape2->body->entity, shape1->body->entity, &coll);
64 if(shape2->body->entity->lcCollisionTwo)
65 shape2->body->entity->lcCollisionTwo(shape2->body->entity, shape1->body->entity, &coll);
66 }
67}
68void SG_CALL__cdecl _sg_cbPhysicsCollisionPostSolve(SGPhysicsShape* shape1, SGPhysicsShape* shape2, void* handle) /// \TODO TODO
69{
70}
71void SG_CALL__cdecl _sg_cbPhysicsCollisionSeparate(SGPhysicsShape* shape1, SGPhysicsShape* shape2, void* handle)
72{
73 SGPhysicsCollision coll;
74 coll.handle = handle;
75 coll.shape1 = shape1;
76 coll.shape2 = shape2;
77
78 if(shape1 && shape1->body->entity)
1
Assuming pointer value is null
79 {
80 if(shape1->body->entity->lcCollisionEnd)
81 shape1->body->entity->lcCollisionEnd(shape1->body->entity, shape2->body->entity, &coll);
82 if(shape1->body->entity->lcCollisionOneEnd)
83 shape1->body->entity->lcCollisionOneEnd(shape1->body->entity, shape2->body->entity, &coll);
84 }
85 if(shape2 && shape2->body->entity)
2
Taking true branch
86 {
87 if(shape2->body->entity->lcCollisionEnd)
3
Taking false branch
88 shape2->body->entity->lcCollisionEnd(shape2->body->entity, shape1->body->entity, &coll);
89 if(shape2->body->entity->lcCollisionTwoEnd)
4
Taking true branch
90 shape2->body->entity->lcCollisionTwoEnd(shape2->body->entity, shape1->body->entity, &coll);
5
Access to field 'body' results in a dereference of a null pointer (loaded from variable 'shape1')
91 }
92}
93
94void SG_CALL__cdecl sgPhysicsCollisionIgnore(SGPhysicsCollision* coll)
95{
96 cpArbiterIgnore(coll->handle);
97}
98
99size_t SG_CALL__cdecl sgPhysicsCollisionGetNumContacts(SGPhysicsCollision* coll)
100{
101 return cpArbiterGetCount(coll->handle);
102}
103void SG_CALL__cdecl sgPhysicsCollisionGetPoint(SGPhysicsCollision* coll, size_t index, float* x, float* y)
104{
105 float t;
106 if(!x) x = &t;
107 if(!y) y = &t;
108
109 cpVect v = cpArbiterGetPoint(coll->handle, index);
110 *x = v.x;
111 *y = v.y;
112}
113void SG_CALL__cdecl sgPhysicsCollisionGetNormal(SGPhysicsCollision* coll, size_t index, float* x, float* y)
114{
115 float t;
116 if(!x) x = &t;
117 if(!y) y = &t;
118
119 cpVect v = cpArbiterGetNormal(coll->handle, index);
120 *x = v.x;
121 *y = v.y;
122}
123float SG_CALL__cdecl sgPhysicsCollisionGetDepth(SGPhysicsCollision* coll, size_t index)
124{
125 return cpArbiterGetDepth(coll->handle, index);
126}
127void SG_CALL__cdecl sgPhysicsCollisionGetImpulse(SGPhysicsCollision* coll, float* x, float* y, SGbool friction)
128{
129 float t;
130 if(!x) x = &t;
131 if(!y) y = &t;
132
133 cpVect v;
134 if(friction)
135 v = cpArbiterTotalImpulseWithFriction(coll->handle);
136 else
137 v = cpArbiterTotalImpulse(coll->handle);
138 *x = v.x;
139 *y = v.y;
140}
141SGPhysicsShape* SG_CALL__cdecl sgPhysicsCollisionGetShapeOne(SGPhysicsCollision* coll)
142{
143 return coll->shape1;
144}
145SGPhysicsShape* SG_CALL__cdecl sgPhysicsCollisionGetShapeTwo(SGPhysicsCollision* coll)
146{
147 return coll->shape2;
148}