0 registered members (),
1,173
guests, and 0
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
crash in my function, why?
#330428
06/27/10 14:51
06/27/10 14:51
|
Joined: Nov 2008
Posts: 196 the wrong place
Muhsin
OP
Member
|
OP
Member
Joined: Nov 2008
Posts: 196
the wrong place
|
Hi!
I have tried to convert the Stratego 2 code from AUM11 to lite-c. but I get an crash in function "multiple_selection()". I think I have converted it wrong. can someone please help?
here is the original function: -------------------------------- function multiple_selection() { while (1) { if (mouse_left == 1) { upper_left.visible = on; upper_right.visible = on; lower_left.visible = on; lower_right.visible = on; if (first_click == 0) // make sure that this "if" branch is executed only once { first_click = 1; upper_left.pos_x = pointer.x; // store panel's position upper_left.pos_y = pointer.y; } lower_right.pos_x = pointer.x; // store panel's position lower_right.pos_y = pointer.y;
lower_left.pos_x = upper_left.pos_x; // store panel's position lower_left.pos_y = lower_right.pos_y;
upper_right.pos_x = lower_right.pos_x; // store panel's position upper_right.pos_y = upper_left.pos_y;
} else // finished multiple selection { upper_left.visible = off; upper_right.visible = off; lower_left.visible = off; lower_right.visible = off; first_click = 0;
upleft_coords.x = upper_left.pos_x; // project upper_left's panel coords on the map upleft_coords.y = upper_left.pos_y; upleft_coords.z = camera_height; vec_for_screen (upleft_coords, camera);
upright_coords.x = upper_right.pos_x; // project upper_left's panel coords on the map upright_coords.y = upper_right.pos_y; upright_coords.z = camera_height; vec_for_screen (upright_coords, camera);
downleft_coords.x = lower_left.pos_x; // project upper_left's panel coords on the map downleft_coords.y = lower_left.pos_y; downleft_coords.z = camera_height; vec_for_screen (downleft_coords, camera);
downright_coords.x = lower_right.pos_x; // project upper_left's panel coords on the map downright_coords.y = lower_right.pos_y; downright_coords.z = camera_height; vec_for_screen (downright_coords, camera); } wait (1); } } --------------------------------
and here is how I converted it:
-------------------------------- function multiple_selection() { while(1) { if(mouse_left == 1) { set(upper_left, SHOW); set(upper_right, SHOW); set(lower_left, SHOW); set(lower_right, SHOW); if(first_click == 0) { first_click = 1; upper_left.pos_x = mouse_cursor.x; //pointer upper_left.pos_y = mouse_cursor.y; } lower_right.pos_x = mouse_cursor.x; //pointer lower_right.pos_y = mouse_cursor.y; lower_left.pos_x = upper_left.pos_x; lower_left.pos_y = lower_right.pos_y; upper_right.pos_x = lower_right.pos_x; upper_right.pos_y = upper_left.pos_y; } else { reset(upper_left, SHOW); reset(upper_right, SHOW); reset(lower_left, SHOW); reset(lower_right, SHOW); first_click = 0; upleft_coords.x = upper_left.pos_x; upleft_coords.y = upper_left.pos_y; upleft_coords.z = camera_height; vec_for_screen(upleft_coords, camera); upright_coords.x = upper_right.pos_x; upright_coords.y = upper_right.pos_y; upright_coords.z = camera_height; vec_for_screen(upright_coords, camera); downleft_coords.x = lower_left.pos_x; downleft_coords.y = lower_left.pos_y; downleft_coords.z = camera_height; vec_for_screen (downleft_coords, camera);
downright_coords.x = lower_right.pos_x; downright_coords.y = lower_right.pos_y; downright_coords.z = camera_height; vec_for_screen (downright_coords, camera); } wait(1); } } --------------------------------
can someone please help?
thanks!
- Muhsin Kaymak
Come and play my new browsergame - Valley Of Wolves: http://www.mafiacreator.com/ValleyOfWolvesHurry and be the first to take over the different business' in the Valley Of Wolves, before anybody else does it! And be the most feared MafiaBoss in the World!!
|
|
|
Re: crash in my function, why?
[Re: Muhsin]
#330437
06/27/10 17:05
06/27/10 17:05
|
Joined: Dec 2008
Posts: 1,218 Germany
Rackscha
Serious User
|
Serious User
Joined: Dec 2008
Posts: 1,218
Germany
|
try this:
comment out everythng INSIDE the function.
And then put it in step by step.
MY Website with news of my projects: (for example my current Muliplayer Bomberman, GenesisPrecompiler for LiteC and TileMaster, an easy to use Tile editor) Sparetime-Development
|
|
|
Re: crash in my function, why?
[Re: Rackscha]
#330448
06/27/10 18:16
06/27/10 18:16
|
Joined: Nov 2008
Posts: 196 the wrong place
Muhsin
OP
Member
|
OP
Member
Joined: Nov 2008
Posts: 196
the wrong place
|
I found out that if I comment out this part: ----------- upleft_coords.x = upper_left.pos_x; upleft_coords.y = upper_left.pos_y; upleft_coords.z = camera_height; vec_for_screen(upleft_coords, camera); upright_coords.x = upper_right.pos_x; upright_coords.y = upper_right.pos_y; upright_coords.z = camera_height; vec_for_screen(upright_coords, camera); downleft_coords.x = lower_left.pos_x; downleft_coords.y = lower_left.pos_y; downleft_coords.z = camera_height; vec_for_screen (downleft_coords, camera);
downright_coords.x = lower_right.pos_x; downright_coords.y = lower_right.pos_y; downright_coords.z = camera_height; vec_for_screen (downright_coords, camera); ----------- then the engine stops working, but if I comment out everything else and don't comment that part, then the crash happens.
what can be wrong?
thanks!
- Muhsin Kaymak
Come and play my new browsergame - Valley Of Wolves: http://www.mafiacreator.com/ValleyOfWolvesHurry and be the first to take over the different business' in the Valley Of Wolves, before anybody else does it! And be the most feared MafiaBoss in the World!!
|
|
|
Re: crash in my function, why?
[Re: Muhsin]
#330449
06/27/10 18:22
06/27/10 18:22
|
Joined: Dec 2008
Posts: 1,218 Germany
Rackscha
Serious User
|
Serious User
Joined: Dec 2008
Posts: 1,218
Germany
|
so, the part above is the part with the crash reason? (your sentence is a bit confusing^^)
MY Website with news of my projects: (for example my current Muliplayer Bomberman, GenesisPrecompiler for LiteC and TileMaster, an easy to use Tile editor) Sparetime-Development
|
|
|
Re: crash in my function, why?
[Re: Rackscha]
#330452
06/27/10 18:27
06/27/10 18:27
|
Joined: Nov 2008
Posts: 196 the wrong place
Muhsin
OP
Member
|
OP
Member
Joined: Nov 2008
Posts: 196
the wrong place
|
yes and sorry for my bad english
Come and play my new browsergame - Valley Of Wolves: http://www.mafiacreator.com/ValleyOfWolvesHurry and be the first to take over the different business' in the Valley Of Wolves, before anybody else does it! And be the most feared MafiaBoss in the World!!
|
|
|
Re: crash in my function, why?
[Re: Muhsin]
#330471
06/27/10 19:41
06/27/10 19:41
|
Joined: Oct 2004
Posts: 4,134 Netherlands
Joozey
Expert
|
Expert
Joined: Oct 2004
Posts: 4,134
Netherlands
|
How did you define the vectors? They may not be pointers.
Last edited by Joozey; 06/27/10 19:41.
Click and join the 3dgs irc community! Room: #3dgs
|
|
|
Re: crash in my function, why?
[Re: Muhsin]
#330489
06/27/10 21:01
06/27/10 21:01
|
Joined: Aug 2007
Posts: 1,922 Schweiz
Widi
Serious User
|
Serious User
Joined: Aug 2007
Posts: 1,922
Schweiz
|
VECTOR* unit_speed = 2; --> ??? VECTOR* upleft_coords; --> here you define a pointer to a vector and not the vector itself. VECTOR upleft_coords; --> use this instead.
EDIT: remove all "*" by all VECTOR`s and it no more crashes
Last edited by Widi; 06/27/10 21:05.
|
|
|
Re: crash in my function, why?
[Re: Widi]
#330505
06/27/10 21:49
06/27/10 21:49
|
Joined: Nov 2008
Posts: 196 the wrong place
Muhsin
OP
Member
|
OP
Member
Joined: Nov 2008
Posts: 196
the wrong place
|
thank you very much. it works now!
thanks!
- Muhsin Kaymak
Come and play my new browsergame - Valley Of Wolves: http://www.mafiacreator.com/ValleyOfWolvesHurry and be the first to take over the different business' in the Valley Of Wolves, before anybody else does it! And be the most feared MafiaBoss in the World!!
|
|
|
Re: crash in my function, why?
[Re: Muhsin]
#330636
06/28/10 21:06
06/28/10 21:06
|
Joined: Oct 2004
Posts: 4,134 Netherlands
Joozey
Expert
|
Expert
Joined: Oct 2004
Posts: 4,134
Netherlands
|
Do you know why? It's important to know . When random crashes occur, you can be pretty sure it's a pointer issue. For everyone else having the same problem, here explanation: You defined the vectors as pointers, but pointers do not yet point to the actual object. You either need to make an object and assign the pointer:
VECTOR *upleft_coords;
upleft_coords = vector(0, 0, 0);
Or dont make a pointer: When you do not make a pointer (latter example), be absolutely sure you do NOT read the values before setting them:
VECTOR upleft_coords;
my.x = upleft_coords.x;
//this will definitely cause troubles which are not easy to find!
//the vector has not yet assigned a value, and holds random pointer values.
//using those will cuase these strange values to flow into your functions ;)
This is the correct way:
VECTOR upleft_coords;
vec_set( upleft_coords, nullvector );
my.x = upleft_coords.x;
Click and join the 3dgs irc community! Room: #3dgs
|
|
|
|