tell me why

Blitz3D Forums/Blitz3D Beginners Area/tell me why

RifRaf(Posted 2003) [#1]
Why in the code below, do I get entity does not exist after deleting an emitter. The emiiter is deleted because its parent is removed, I get the error at these lines below.

TurnEntity e\pivot, e\turnx#,e\turny#,e\turnz#
MoveEntity e\pivot,0,0,e\movespeed#

It should not try to move that e\pivot after its been
deleted. I removed that instance of e.emitter.

[\CODE]
Function handleemitters()
For e.emitter= Each emitter
FLAGD=False
If e\active Then
;decide if its time to spawn a dirt
If e\spawntimer#<(gametimer#) And dirtcount=<maxdirt Then
e\spawntimer#=(e\spawnrate#+gametimer#)
Dirtcount=dirtcount+1
;spawn dirt
d.dirt=New dirt
d\sprite=CopyEntity (e\hiddensprite)
ShowEntity d\sprite
d\xv#=e\xv#
d\yv#=e\yv#
d\zv#=e\zv#
PositionEntity d\sprite,EntityX(e\pivot,1)+Rnd(-e\area#,e\area#),EntityY(e\pivot,1)+Rnd(-e\area#,e\area#),EntityZ(e\pivot,1)+Rnd(-e\area#,e\area#)
d\forces=e\forces
d\rotationinc#=e\rot#
d\alpha#=e\alpha#
d\decay#=e\decay#
d\scalechange#=e\scalechange#
d\mass#=e\mass#
d\scale#=e\startscale#
d\lifespan#=e\plifespan#
d\lifetimer#=(gametimer#+d\lifespan#)

EndIf
;do turns movements on emitter
;if parented.. follow parent

TurnEntity e\pivot, e\turnx#,e\turny#,e\turnz#
MoveEntity e\pivot,0,0,e\movespeed#
;see if emitter has lifespan if so check to see if it has expired
EndIf ;IF ACTIVE

If e\lifetime#<>0 Then
If e\lifetime#<gametimer# Then
flagd=True
EndIf
EndIf

If e\parent Then
If GetParent(e\pivot)=0 Then
flagd=True
EndIf
EndIf

If flagd=True Then
FreeEntity e\HIDDENSPRITE
FreeEntity e\pivot
Delete e
EndIf
Next

End Function
[CODE\]


darklordz(Posted 2003) [#2]
pseuso code
if entityexhist=1 then
TurnEntity e\pivot, e\turnx#,e\turny#,e\turnz# 
MoveEntity e\pivot,0,0,e\movespeed#
endif


explenation you are trying to rotate an objext after it's been deleted, this will never work. cus it's been deleted.....


RifRaf(Posted 2003) [#3]
OK BUT HOW DOES IT GET TO THAT POINT AGAIN? after i delete e, the loop should go to the next e. correct? and then the next time i call this loop it would not include the deleted e. so can you explain for me. It seems to work also if I delete the NEXT e .. can you explain that.. here is the changed delete code

If flagd=True Then
FreeEntity e\HIDDENSPRITE
FreeEntity e\pivot
Delete After E
Delete e
EndIf
Next


That works with no problems.. why ?


Ross C(Posted 2003) [#4]
I hasd the sam problem with my asteroids. I'm pretty sure after you delete a type obkject, it goes to the end of the list. I had to create another type list, with a list of types to be deleted..or osmething.. i don't rememebr


RifRaf(Posted 2003) [#5]
It goes to the end of the list? So you are saying it doesnt get deleted at all? How then can you keep a type list under control ?


Rimmsy(Posted 2003) [#6]
This should work perfectly

type thing
  field a
end type

; create some
for i=1 to 5
  t.thing=new thing
  t\a=i
next

show()

; delete one
for t.thing=each thing
  if t\a=4 then delete t
next

show()
waitkey
end




function show()
 print "----------"
 for i.thing=each thing
   print j+" - "+i\a
   j=j+1
 next 
end function



Ross C(Posted 2003) [#7]
No, i mean the pointer goes to the end of the list. The item gets deleted, but the pointer to the current type goes to the edn of the list.


darklordz(Posted 2003) [#8]
Y? Well like i said once and object gets deleted and the program tries to move it an error occurs. Why because IT DOES NOT EXHIST ANYMORE! YOU DELETED IT! got that? am i clear enough?


RifRaf(Posted 2003) [#9]
dark, i know that, knew that.. i dont need help understanding that you cant move non existing entities, but I also deleted the instance of that type along with the actual entity, my question was how is blitz getting to a point where it would try to look at a type instance again after it had been deleted.


Floyd(Posted 2003) [#10]
I would guess you are deleting a pivot which is needed later.

Suppose two emitters share a pivot, and you do 'FreeEntity e\pivot' with one of them.

The pivot entity is now gone. A later 'TurnEntity e\pivot...', where e is the other emitter, is an error.


RifRaf(Posted 2003) [#11]
Im sure its simple.. each emitter has a seperate pivot. I cant seem to find the issue with it. ill rewrite the partical engine tomorrow. Thanks everyone, and Merry Christmas!


Ross C(Posted 2003) [#12]
RifRaf, my bad. I'm talking mince. It was when i added to the type list the pointer went to the end :) ops!

Ok, well, if you creating a particle system, it is wiser to NOT delete things. Just simply re-use them. Set there active flag to 0 if they aren't being used. When you goto update, check for all the type objects for being active. If so, then update that object, if not, skip it.

When it comes to generating a new object, look thru you list of particle objects to see if any aren't active. Then re-activate them. You will need to create the particles before hand tho, but it's is a good practice :)