acknex .exe crashing on ent_remove!!!

Posted By: Bullshark

acknex .exe crashing on ent_remove!!! - 01/12/09 00:04

Hello!

Iīm having a serious problem that I havenīt been able to solve, whenever I use ent_remove or ptr remove acknex.exe crashes (Windows diplays a "acknex.exe has stopped working" sign).

Any ideas on how to fix this?

Here's an example code, just in case I'm using them wrong:

Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <mtlFX.c>
///////////////////////////////
ENTITY* star_ent;

function star_event() 
{
	switch (event_type)
	{
		case EVENT_ENTITY:
				beep();
				ent_remove(me);
				wait(1);	
			return;
		
		case EVENT_BLOCK:
				beep();
				ent_remove(me);
				wait(1);			
			return;
		
	}
}

action star_fall()
{
	my.emask |= IGNORE_PASSABLE | ENABLE_BLOCK | ENABLE_ENTITY ;
	my.event = star_event;
}

function main()
{
	level_load("Test.WMB");
	wait(2);
	star_ent = ent_create("star.mdl",vector(0,0,300),star_fall); 
	phent_settype(star_ent, PH_RIGID, PH_POLY);
	phent_setgroup( star_ent, 1 ); 
	phent_setmass(star_ent,0.1,PH_BOX);	
	phent_setdamping (star_ent, 15, 0 );
	phent_enable( star_ent, 1 );
	ph_setgravity(vector(0,0,-100));
	ph_selectgroup( 1 );
	while(1)
	{
		wait(1);
	}
}


The wmb file only has a block to act as the ground for collision.

Thanks in advance for your help.

----------------------------
System:
* Windows Vista Pro 64 bits
* Core 2 Duo 2.13 Ghz Processor
* 5 Gb RAM
* nvidia 8800GTS video card
----------------------------
Posted By: Pappenheimer

Re: acknex .exe crashing on ent_remove!!! - 01/12/09 00:25

I don't know anything about physics because I never used it. But, what are all your waits for? The manual as a "common mistakes" section although I don't know how they named it. It might be helpful for you.
There shouldn't be any wait(1); in an event function. I guess those are the reason for the crash.
And, whatfor is the while loop in the main function? That makes no sense.
Posted By: Bullshark

Re: acknex .exe crashing on ent_remove!!! - 01/12/09 01:02

Hi Pappenheimer, unfortunately even without the waits or the while it still crashes at ent_remove(me).

I have even replaced ent_remove(me) for ent remove(star_ent) just to make sure the pointer was right. Still same result.

Any more ideas on how to fix this or what could be causing it?

Thanx.
Posted By: Quad

Re: acknex .exe crashing on ent_remove!!! - 01/12/09 01:10

try if this removes it:

if(me!=NULL) ent_remove(me);
Posted By: Bullshark

Re: acknex .exe crashing on ent_remove!!! - 01/12/09 01:41

nope, still crashes! but thanks anyway Quadraxas.
Posted By: testDummy

Re: acknex .exe crashing on ent_remove!!! - 01/12/09 02:59

Some or all of following may be inaccurate or erroneous.
...wait(1) before ent_remove(ENTITY*) in event (else instance = dangerous instruction)?
......wait(1);
......if (me != NULL) { ent_remove(me); }
...(below) removal in action not event
Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <mtlFX.c>
///////////////////////////////

#define _hit skill38

ENTITY* star_ent;

function star_event() 
{
	switch (event_type)
	{
		case EVENT_ENTITY:
				beep();
				my._hit = 1;
				my.event = NULL;
			return;
		
		case EVENT_BLOCK:
				beep();
				my._hit = 1;
				my.event = NULL;
			return;
		
	}
}

action star_fall()
{
	my.emask |= IGNORE_PASSABLE | ENABLE_BLOCK | ENABLE_ENTITY ;
	my.event = star_event;
	while(me != NULL) {
		if (my._hit == 1) {
			break;
		}
		wait(1);
	}
	if (me != NULL) {
		phent_enable(me, 0);
		ent_remove(me);
	}
}

function main()
{
	level_load("Test.WMB");
	wait(2);
	star_ent = ent_create("star.mdl",vector(0,0,300),star_fall); 
	phent_settype(star_ent, PH_RIGID, PH_POLY);
	phent_setgroup( star_ent, 1 ); 
	phent_setmass(star_ent,0.1,PH_BOX);	
	phent_setdamping (star_ent, 15, 0 );
	phent_enable( star_ent, 1 );
	ph_setgravity(vector(0,0,-100));
	ph_selectgroup( 1 );
	
}

Posted By: Bullshark

Re: acknex .exe crashing on ent_remove!!! - 01/12/09 03:09

WOW! that worked!!! thank you very much testDummy!!! Just one more question, does the entity become NULL after ent_remove?

Thank you all for your help, I really apreciate it.
Posted By: Bullshark

Re: [SOLVED]acknex .exe crashing on ent_remove!!! - 01/12/09 04:03

Nevermind, I got everything up and running. Thanks again to everyone for your help.
Posted By: HPW

Re: acknex .exe crashing on ent_remove!!! - 01/12/09 09:45

Originally Posted By: Pappenheimer
... There shouldn't be any wait(1); in an event function. I guess those are the reason for the crash. ...


This is not true.
You can have wait(1) in your event functions.
To avoid crashes you should set the wait(1) before the ent_remove.
This info was posted by JCL long time ago and I used it many times this way without crashes.

And here I found the description in the manual:
Quote:

If for some reason the event function must perform such 'critical instructions', they must be preceded by a wait(1) for delaying them to the next frame. Then it's safe.

© 2024 lite-C Forums