2 registered members (AndrewAMD, Ayumi),
903
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
empty pointer... need help
#287556
09/01/09 11:55
09/01/09 11:55
|
Joined: Mar 2009
Posts: 276 Cebu City, Philippines
boyax
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 276
Cebu City, Philippines
|
I encounter a crash/error in my game which states: "empty pointer in vec_randomize" As i've investigated, it would crash when I use already the two effects (water splash & dust particles), and i'm not sure why? Hope someone could help/point me out the problem. Here's my code: player.c
VECTOR* vecDust =
{
x=0; y=0; z=0;
}
//--------------------------------------------------------------------
// Action: Player
//--------------------------------------------------------------------
action act_player()
{
...
player = my; //I'm the player
player.emask |= (ENABLE_IMPACT | ENABLE_ENTITY);
player.event = bounce_wall;
...
while(1)
{
HandleMovement();
HandleCamera();
wait(1);
}
}
//--------------------------------------------------------------------
// Event- Hit on the wall/water
//--------------------------------------------------------------------
function bounce_wall()
{
if(you != NULL)
{
if( /*hit in the points*/ )
{
//do nothing...
}
else //hit in the wall & water entities
{
vecDust.x = hit.x; //i started in here so I know what vertex of the player hit the wall... hit.vertex
vecDust.y = hit.y;
vecDust.z = hit.z;
//play some effects...
VECTOR tempVel,tempNormal;
vec_set(tempVel, vector(0,0,5));
vec_set(tempNormal,normal);
var count = 0;
while(count < 3)
{
vec_randomize(tempVel,10); //make sure the dust goes away from the impact position
vec_normalize(tempNormal,2 + random(5));
vec_add(tempVel,tempNormal);
if( str_cmpi(strWaterSkin,hit.texname) ) //water splash
{
effect_local(splash, 1, vecDust, tempVel);
}
else //dust
{
effect_local(dust, 1, vecDust, tempVel);
}
count += 1;
wait(1);
}
}
wait(1);
}
}
environment.c
//--------------------------------------------------------------------
// helper function: sets the vector to random direction and length
//--------------------------------------------------------------------
function vec_randomize (VECTOR* vec, var range)
{
vec_set(vec, vector((random(5) - 1) * 0.3, (random(5) - 1) * 0.3, (random(2.5) + 1) * 0.2) );
vec_normalize(vec,random(range));
}
//--------------------------------------------------------------------
// DUST PARTICLE EFFECTS
//--------------------------------------------------------------------
function dust(PARTICLE *p)
{
p.alpha = 5 + random(5);
p.bmap = bmp_dust;
p.size = 100;
p.skill_a = vec_length(p.vel_x); //remember the current speed
p.lifespan = 10;
set(p, MOVE);
p.event = fade_dust;
}
//-------------------------------------------------------
function fade_dust(PARTICLE *p)
{
p.size += 15 * time_step;
p.alpha -= 0.3 * time_step;
if (p.alpha < 0) { p.lifespan = 0;}
p.skill_a -= time_step*4; //make sure the particle gets slower while maintaining the same direction.
vec_normalize(p.vel_x,p.skill_a);
}
//--------------------------------------------------------------------
// Water Splash
//--------------------------------------------------------------------
function splash(PARTICLE *p)
{
p.alpha = 5 + random(5);
p.bmap = bmp_splash;
p.size = 10;
p.skill_b = vec_length(p.vel_x); //remember the current speed
p.lifespan = 10;
set(p, MOVE);
p.event = fade_splash;
}
//-------------------------------------------------------
function fade_splash(PARTICLE *p)
{
p.size += 15 * time_step;
p.alpha -= 0.3 * time_step;
if (p.alpha < 0) { p.lifespan = 0;}
p.skill_b -= time_step*4; //make sure the particle gets slower while maintaining the same direction.
vec_normalize(p.vel_x,p.skill_b);
}
Thanks
|
|
|
Re: empty pointer... need help
[Re: boyax]
#287579
09/01/09 13:31
09/01/09 13:31
|
Joined: Apr 2006
Posts: 737 Ottawa, Canada
Ottawa
User
|
User
Joined: Apr 2006
Posts: 737
Ottawa, Canada
|
Hi!
I was looking at :
VECTOR tempVel,tempNormal;
Is it your intention to redefine tempVe1 each time you go through the loop?
Hope this helps! Ottawa Ver 7.86.2 Pro and Lite-C
|
|
|
Re: empty pointer... need help
[Re: Ottawa]
#287682
09/02/09 04:13
09/02/09 04:13
|
Joined: Mar 2009
Posts: 276 Cebu City, Philippines
boyax
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 276
Cebu City, Philippines
|
@Ottawa: yeah, I don't want to declare much global variables.. anyway, I try also your suggestion to declare it as global variable in player.h
VECTOR* tempVel =
{
x=0; y=0; z=0;
}
VECTOR* tempNormal =
{
x=0; y=0; z=0;
}
but still I got the error.
|
|
|
Re: empty pointer... need help
[Re: badapple]
#287689
09/02/09 06:17
09/02/09 06:17
|
Joined: Mar 2009
Posts: 276 Cebu City, Philippines
boyax
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 276
Cebu City, Philippines
|
@badapple: Vector declaration seems fine... I've just learned it in here vector declaration Anyway, I've put already the vectors tempVel,tempNormal as global variable vectors as posted above... still, I encounter the crash...
|
|
|
Re: empty pointer... need help
[Re: boyax]
#287693
09/02/09 07:20
09/02/09 07:20
|
Joined: Mar 2009
Posts: 276 Cebu City, Philippines
boyax
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 276
Cebu City, Philippines
|
Thanks all for the help. I've already figured it out... It seems it is a deadlock problem... I just remove the wait(1) function inside the while loop statement and that would fix the problem.
//--------------------------------------------------------------------
// Event- Hit on the wall/water
//--------------------------------------------------------------------
function bounce_wall()
{
if(you != NULL)
{
if( /*hit in the points*/ )
{
//do nothing...
}
else //hit in the wall & water entities
{
vecDust.x = hit.x; //i started in here so I know what vertex of the player hit the wall... hit.vertex
vecDust.y = hit.y;
vecDust.z = hit.z;
//play some effects...
VECTOR tempVel,tempNormal;
vec_set(tempVel, vector(0,0,5));
vec_set(tempNormal,normal);
var count = 0;
while(count < 3)
{
vec_randomize(tempVel,10); //make sure the dust goes away from the impact position
vec_normalize(tempNormal,2 + random(5));
vec_add(tempVel,tempNormal);
if( str_cmpi(strWaterSkin,hit.texname) ) //water splash
{
effect_local(splash, 1, vecDust, tempVel);
}
else //dust
{
effect_local(dust, 1, vecDust, tempVel);
}
count += 1;
}
}
wait(1);
}
}
|
|
|
|