1 registered members (AndrewAMD),
1,248
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
code crash after level_load
#455603
10/25/15 13:42
10/25/15 13:42
|
Joined: Oct 2010
Posts: 73 0110111
CodeMaster
OP
Junior Member
|
OP
Junior Member
Joined: Oct 2010
Posts: 73
0110111
|
hi all i'm not expert for physics and i have a few questions how to use physx in my game, of course on the proper way everything works pretty well until the moment when i need to load second level and then return in the first i get crash e1513 script crash in physX_open i tried to clean up the pointers with ent_remove but is still something wrong in this code when i change level over five times script crash (when i put this code in my game i get crash fist time when i back in level where is physic object)
#include <default.c>
#include <ackphysX.h>
#include <mtlFX.c>
ENTITY *pole;
action flag(){
my.material = mtl_twosided_alpha;
// attach flag to pole
c_setminmax(pole);
c_setminmax(my);
vec_set(my.x,vector(pole.x, pole.y+(my.max_y-my.min_y)/2, pole.z+pole.max_z-(my.max_z-my.min_z)/2));
// setup flag cloth
var cloth_options[40];
memcpy(cloth_options,CLOTH_DEFAULT,40*sizeof(var));
vec_set(cloth_options[25],vector(-10,20,0)); // external acceleration
vec_set(cloth_options[28],vector(5,10,5)); // random wind acceleration
cloth_options[9] = 4; // Tear Factor
cloth_options[37] |= NX_CLF_GRAVITY|NX_CLF_BENDING|NX_CLF_COLLISION_TWOWAY|NX_CLF_SELFCOLLISION|NX_CLF_TEARABLE|NX_CLF_BENDING_ORTHO;
pXent_cloth(my,pole,NX_CLOTH_ATTACHMENT_TWOWAY,0,0,cloth_options);
}
action flag_pole(){
pole = me;
vec_set(pole.scale_x,vector(0.2,0.2,40));
vec_set(pole.pan,vector(0,0,0));
vec_set(pole.blue,COLOR_GREY);
pXent_settype(pole,PH_STATIC,PH_BOX);
}
action act_flag_creator(){
set(my,INVISIBLE);
ent_create(CUBE_MDL,vector(my.x,my.y,my.z),flag_pole);
ent_create("clothflag.mdl",NULL,flag);
}
function main(){
fps_max = 60;
level_load("test1.wmb");
physX_open();
while(1){
if(key_1){ level_load("test1.wmb");}
if(key_2){ level_load("test2.wmb");}
wait(1);
}
}
can someone show me where i wrong and explain what happens to physic objects after level load?
|
|
|
Re: code crash after level_load
[Re: CodeMaster]
#455607
10/25/15 18:09
10/25/15 18:09
|
Malice
Unregistered
|
Malice
Unregistered
|
well there is this Call physX_open() before loading the first level. This automatically registers level geometry and static models as physics obstacles. However you open after level_load http://www.conitec.net/beta/pX_intro.htmManual example
#include <default.c>
#include <ackphysx.h>
function main()
{
physX_open();
level_load(""); // load an empty level
vec_set(camera.x,vector(-100,0,30));
pXent_settype(NULL,PH_STATIC,PH_PLANE); // create a static plane at groundlevel zero
ENTITY* ball = ent_create(SPHERE_MDL,vector(0,0,100),NULL);
pXent_settype(ball,PH_RIGID,PH_SPHERE ); // create a ball
pXent_setelasticity(ball,50);
pXent_addvelcentral(ball,vector(0,-10,0)); // make it jump and roll sidewards
while(1){
pX_pick(); // pick and move the ball with the cursor
wait(1);
}
}
Last edited by Malice; 10/25/15 18:09.
|
|
|
Re: code crash after level_load
[Re: CodeMaster]
#455613
10/25/15 19:06
10/25/15 19:06
|
Malice
Unregistered
|
Malice
Unregistered
|
If you open physX after the level_load - than this does not happen This function in ackphysX.h starts the physics simulation loop, and sets up level_load and ent_remove events for automatically registering and unregistering static objects. Which would mean you are not unreg objects with level_load try running http://www.conitec.net/beta/physX_destroy.htmphys_open level_load // new levels physX_destroy ( ) level_load(...new level..) physX_open /// next time physX_destroy ( ) level_load(...new level..) physX_open ---However I'm troubleshooting guessing Also while() if(key) level_load .. Will cause many calls to level_load. No matter how fast you touch the "key" the engine will read the key-press many time in one second. Bad code
Last edited by Malice; 10/25/15 19:09.
|
|
|
Re: code crash after level_load
[Re: ]
#455614
10/25/15 19:30
10/25/15 19:30
|
Malice
Unregistered
|
Malice
Unregistered
|
As a note - Just using your function main() and replacing the levels with my own... I can not repeat this error.. Would lead me to believe the error is elsewhere or with one of the levels themselves.
function main(){
fps_max = 60;
level_load("test1.wmb");
physX_open();
while(1){
if(key_1){ level_load("my_test1.wmb");}
if(key_2){ level_load("my_test2.wmb");}
wait(1);
}
}
Possible - Loading a level the exceeds the current nexus limit..
|
|
|
Re: code crash after level_load
[Re: ]
#455615
10/25/15 19:35
10/25/15 19:35
|
Joined: Feb 2012
Posts: 371
Dico
Senior Member
|
Senior Member
Joined: Feb 2012
Posts: 371
|
I think the problem from the actions you need to add this in bigining of action flag While(!pole){wait(1);}
We add this bec if action flag created before action pole this produce a crash
Last edited by Dico; 10/25/15 19:40.
|
|
|
Re: code crash after level_load
[Re: Dico]
#455622
10/25/15 22:16
10/25/15 22:16
|
Joined: Oct 2010
Posts: 73 0110111
CodeMaster
OP
Junior Member
|
OP
Junior Member
Joined: Oct 2010
Posts: 73
0110111
|
thank you guys with physX_destroy() and level change, crash e1513 in physX_open() is gone but now i can't run physX_open again and i don't know why? the manual say make sure to call physX_destroy at the end of the program, or when you don't need the physics engine anymore what this mean when is said "when you don't need the physics engine anymore"? did is possible after physx_destroy open physics engine again?
|
|
|
Re: code crash after level_load
[Re: CodeMaster]
#455627
10/26/15 00:27
10/26/15 00:27
|
Malice
Unregistered
|
Malice
Unregistered
|
Level_load removes all ents then loads the new level
If physX_open is called first then you should not need ph--destroy Like I said I used your main() with my levels and could not repeat the error.
physX_open() level_load(...)
if(!key && lock ==1) lock =0; if(key && lock==0) { lock=1; level_load(..) } press key 20 times, no issue... You'r problem seems elsewhere.
|
|
|
|