Deleting PhysX Objects

Posted By: Rei_Ayanami

Deleting PhysX Objects - 08/17/12 12:30

Hey,

I cannot delete PhysX objects. If I have a function that creates
an object with Raycasting wheels, and shortly after delete it, the
graphical representation is gone, but in the PhysX Debugger
everything stays and other objects still react on it.

If I call the function again, odd things happen. As if the same
memory part is used again. If I manually overwrite the before
deleted memory with zeros, at least this works.

Also, calling pXcon_remove on a PH_WHEEL makes the function crash.

Any ideas? Please?



I am seriously wondering if anybody really used PhysX in GS, when I see those problems...
Posted By: rojart

Re: Deleting PhysX Objects - 08/17/12 14:24

Show me your code, maybe forgotten with pXent_settype( myPhysXentity, 0, 0 ); ?

0 = unregister the entity from the physics system.
Posted By: 3run

Re: Deleting PhysX Objects - 08/17/12 15:07

some times unregistering before deleting doesnt work with PH CHAR too
Posted By: Rei_Ayanami

Re: Deleting PhysX Objects - 08/17/12 15:16

pXent_settype(ent, 0, 0) does nothing.

(I also checked the PhysX Debugger)

Furthermore, the event physX_ent_remove should do that.


However, pXent_enable works for me.


On the other hand, the PhysX implementation really sucks, sorry, but I even have to clean up the level entities myself with pXent_enable one by one...

(thanks for your help ;))
Posted By: HeelX

Re: Deleting PhysX Objects - 08/17/12 15:30

Originally Posted By: Rei_Ayanami
the PhysX implementation really sucks, sorry, but I even have to clean up the level entities myself with pXent_enable one by one...
It turns out that I have to use the ackphysx plugin again very soon for a customer, so I will change that, so that this part will be better.
Posted By: rojart

Re: Deleting PhysX Objects - 08/17/12 15:33

Of course, but please show me some code, that reproduce your issue for me.
Posted By: 3run

Re: Deleting PhysX Objects - 08/17/12 16:36

rojart@ if you need, I can send you a small example of the same problem with PH CHAR. I'm waiting for snakes plugin! I hope it will be much better than the one which implemented by jcl.
Posted By: rojart

Re: Deleting PhysX Objects - 08/17/12 16:53

It would be useful laugh
Posted By: rojart

Re: Deleting PhysX Objects - 08/18/12 07:59

3run: Yes, you can send me that example.

Rei_Ayanami: In the first post, I see beta 8.34.0b, try with new update 8.40.1 and give me the chance to see your code.
Posted By: 3run

Re: Deleting PhysX Objects - 08/18/12 08:30

Sorry for a delay, here is the demo for you all to try:
Download link
I've tried it with the latest beta version, still sucks.
Posted By: rojart

Re: Deleting PhysX Objects - 08/18/12 13:06

I make some changes so that it works really well.

Try this one:

Code:
///////////////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>
#include <ackphysx.h>
///////////////////////////////////////////////////////////////////////////////
STRING* map01_str = "map1.wmb";
///////////////////////////////////////////////////////////////////////////////
function main(){
	// show all errors:
	warn_level = 6;
	// limit FPS:
	fps_max = 60;
	// set video parameters:
	video_set(800, 600, 16, 0);
	video_aspect = 1.333;
	// run physX:
	physX_open();
	// load the level:
	freeze_mode = 1;
	level_load(map01_str);
	wait(3);
	freeze_mode = 0;
}
///////////////////////////////////////////////////////////////////////////////
action hero_act(){
	VECTOR temp;
	// make me physical object:
	pXent_settype(my, PH_CHAR, PH_CAPSULE);
	// camera setup:
	camera.arc = 80;
	// main loop:
	while(1){
		// gui:
		draw_text("press space key to remove objects", 5, 5, COLOR_WHITE);
		// move entity:
		temp.x = 15 * (key_w - key_s) * time_step;
		temp.y = 15 * (key_a - key_d) * time_step;
		temp.z = 0;
		pXent_move(my, temp, nullvector);
		wait(1);
	}
}
///////////////////////////////////////////////////////////////////////////////
function ghost_ent(){
	// flags:
	set(my, PASSABLE | TRANSLUCENT);
	// alpha parameters: 
	my.alpha = 50;
}
///////////////////////////////////////////////////////////////////////////////
action char_act(){
	// create passable but visible model, to show you the bbox:
	ent_create("bbox.mdl", my.x, ghost_ent);
	// make me physical object:
	pXent_settype(my, PH_CHAR, PH_CAPSULE);
	// wait till space key is pressed:
	while(!key_space){ wait(1); }
	// unregister object from physX:	
	for(you = ent_next(NULL); you; you = ent_next(you))
	{
		if (you != ent_for_name("bbox_mdl_134"))
		{
			pXent_settype(you,0,0);
		}
	}
	// wait for a while:
	wait(-1);
	// remove object:
	ent_remove(my);
}
///////////////////////////////////////////////////////////////////////////////


Posted By: 3run

Re: Deleting PhysX Objects - 08/18/12 16:15

Thank you mate, this is workaround that I use as well, but it should work the way I have made too
Posted By: HeelX

Re: Deleting PhysX Objects - 09/03/12 08:35

Hi, I just want to roll this up with a quick-fix:

in "ackphysx.h" there is an event "physX_ent_remove", which is called, when an entity is removed via ptr_remove. In that function, the DLL function pXent_settype is used to release the entity from the PhysX system. If you replace that call with

Code:
pXent_enable(ent, 0);



the entity is released from PhysX and the engine, all shapes are removed and the remaining PhysX system is stable.

So just replace the function in ackphysx.h with this one and it'll work:

Code:
function physX_ent_remove(ENTITY* ent)
{
    if (!NxPhysicsSDK)
        return;
        
    if (ent.body != NULL)
        pXent_enable(ent, 0);
        
    on_ent_remove_px(ent);
}



I am not 100% sure why this happens, but it works great for me: in the following pic you see a complex PhysX-setup in the engine and in the NVidia PhysX Visual Debugger:



When I remove all entities with ptr_remove and the above fix, the vehicle is removed correctly:



Without the fix, the entities are removed as well, but the shapes stay in place and all tree-trunks are flying into the sky.
Posted By: gri

Re: Deleting PhysX Objects - 09/05/12 06:09



hey thank you heelx for that



regards,
gri
© 2024 lite-C Forums