Slowdown problems...

Blitz3D Forums/Blitz3D Programming/Slowdown problems...

elseano(Posted 2004) [#1]
I'm getting some terrible slowdown in my game but strangely enough, only towards the end...Can someone tell me why this is happening? Also, if left on for about five minutes, it comes up with a memory access violation. Why is this happening, too? Thanks in advance.


SoggyP(Posted 2004) [#2]
Hi Folks,

Have you got debuglog going?

Later,

Jes


electronin(Posted 2004) [#3]
Yeah, like SoggyP said, try it in debug mode.


SoggyP(Posted 2004) [#4]
Hi Folks,

I meant do you have debug enabled when creating the executable?

Later,

Jes


Shambler(Posted 2004) [#5]
Won't crash for me -.- where does it crash for you?

[edit] hold on 5 minutes? nothing new happens after about a minute -.-


ChrML(Posted 2004) [#6]
You're right. After playing for about 5-8 minutes, the FPS was down in 30 (it was 60).

I guess you forget releasing some of the models, so when enough are copied/loaded, it all gets slower. One rule: Everything you load, you must free, and never load two things onto the same handle, because then you loose the address. Like:

model=LoadMesh("test.x")
model=LoadMesh("test2.x")
FreeMesh model

Here you only get one of two loaded meshes freeed. Check that you haven't done errors like that.


elseano(Posted 2004) [#7]
Hmmm...
Haven't done that double-handle thing...I'm pretty sure I know why it's slowing down now, but I keep getting errors when I free entities. Look:

If nu\alpha<0 Or EntityX(nu\ent)>10 Or EntityX(nu\ent)<-10 Or EntityY(nu\ent)>10 Or EntityY(nu\ent)<-10 Then
	FreeEntity nu\ent
	HideEntity nu\ent
	Delete b.bullet
EndIf

If Not EntityInView(nu\ent,cam) Then
	FreeEntity nu\ent
	HideEntity nu\ent
	Delete b.bullet
EndIf



when I run this [by the way this is inside a function] it always returns a memory access violation...I've put everything as global... Why am I getting this error?? If you've downloaded the zip then you can check the full source code if you like.


Shambler(Posted 2004) [#8]
FreeEntity nu\ent
HideEntity nu\ent

Trying to hide an entity you just freed?


elseano(Posted 2004) [#9]
Oh yeah, good point. =)

EDIT:

Hey I tried this:


If nu\alpha<0 Or EntityX(nu\ent)>10 Or EntityX(nu\ent)<-10 Or EntityY(nu\ent)>10 Or EntityY(nu\ent)<-10 Then
	HideEntity nu\ent
	FreeEntity nu\ent
	Delete b.bullet
EndIf

If Not EntityInView(nu\ent,cam) Then
	HideEntity nu\ent
	FreeEntity nu\ent
	Delete b.bullet
EndIf


And that returns a Memory Acess Violation, too :/ Why?


Shambler(Posted 2004) [#10]
Maybe the first If/Endif deletes the nu/ent and the second If/Endif goes whaaa?


GNS(Posted 2004) [#11]
Taking a stab in the dark here but if the entity is hidden/freed in the first If/EndIf branch, once the second If/EndIf branch is evaluated and returns true (because the freed entity will certainly no longer be in view) then the program attempts to hide/free the same entity - resulting in an error.

If you comment out the second If/EndIf branch, does the program still give an error?

Edit: Doh! Too slow. ;D


electronin(Posted 2004) [#12]
I think it's because this bit:
If nu\alpha<0 Or EntityX(nu\ent)>10 Or EntityX(nu\ent)<-10 Or EntityY(nu\ent)>10 Or EntityY(nu\ent)<-10 Then
	HideEntity nu\ent
	FreeEntity nu\ent
	Delete b.bullet
EndIf

interferes with this bit:
If Not EntityInView(nu\ent,cam) Then
	HideEntity nu\ent
	FreeEntity nu\ent
	Delete b.bullet
EndIf

since it's possible for the first bit to have already deleted the type instance, when the second bit tries to access it, it is sometimes already deleted. I know that doesn't make much sense, but read it through a few times, and you might be able to translate it :P

Edit: Man, you beat me to it :)


Shambler(Posted 2004) [#13]
Hehe, witness the power that is 1 bottle of red wine ;)


elseano(Posted 2004) [#14]
Ok, thanks, I'm gonna check that now...


eBusiness(Posted 2004) [#15]
If the first statement is true, then you call a function with the entity that you just freed. After freeing nu\ent it does not any longer point to an entity.

Edit:
Dam it, I post too slowly.


elseano(Posted 2004) [#16]
Ok, this really beginning to bug me...I've commented out just about everything that has anything to do with deleting/hiding the bullet, except FreeEntity nu\ent:

nu\time=nu\time-1

;If nu\time<0 Then
;	HideEntity nu\ent
;	Delete b.bullet
;EndIf

;If nu\alpha<0 Or EntityX(nu\ent)>10 Or EntityX(nu\ent)<-10 Or EntityY(nu\ent)>10 Or EntityY(nu\ent)<-10 Then
	;FreeEntity nu\ent
	;Delete b.bullet
;EndIf

If Not EntityInView(nu\ent,cam) Then
	FreeEntity nu\ent
	;Delete b.bullet
EndIf


And I still get a Mem Access Violation as soon as one of the bullets leaves the screen...-_-
Why???


Shambler(Posted 2004) [#17]
Took this out too?

If nu\time<0 Then
	HideEntity nu\ent
	Delete b.bullet
EndIf



ChrML(Posted 2004) [#18]
nu\time=nu\time-1

;If nu\time<0 Then
;	HideEntity nu\ent
;	Delete b.bullet     ;here you delete the handle without freeing it, ergo memory access violation
;EndIf

;If nu\alpha<0 Or EntityX(nu\ent)>10 Or EntityX(nu\ent)<-10 Or EntityY(nu\ent)>10 Or EntityY(nu\ent)<-10 Then
	;FreeEntity nu\ent
	;Delete b.bullet
;EndIf

If Not EntityInView(nu\ent,cam) Then
	FreeEntity nu\ent
	;Delete b.bullet
EndIf


Why not check if exists first? Always when you free an entity, set it to 0, and when checking then, simple do:

if entity<>0 then
;the entity exists
else
;the entity does not exist
endif

Remember when freeing do this:
FreeEntity entity
entity=0

Btw, I must laught of the error above (first Free and then hide, LOL). Btw, why hide before killing? Killing hides it anyway,


ChrML(Posted 2004) [#19]
And btw, is the NU variable set? Sure it isn't an another 0 variable?


eBusiness(Posted 2004) [#20]
By the way, why creating and freeing bullets all the time, just make an array with a suitable number of bullets, and then hide them when they are not used.


ChrML(Posted 2004) [#21]
Good point.


Berserker [swe](Posted 2005) [#22]
And you cant
Delete b.bullet

you jave to
Delete b


as simple as that.


Shifty Geezer(Posted 2005) [#23]
ChrMl has explained it, but I'll just re-emphasize.
*Always*, whenever deleting an object, do a check if it exists first...

Eg. If you have a b.bullet object

If b
If NotVisible(b)
Delete b
b=0
Endif
Endif

Set your pointer to 0.
And as ChrMl said, you don't need to hide the entity. The graphics are only drawn when you call RenderWorld, so everything that happens before then doesn't have any feedback until then. If you were to right

HideEntity b
ShowEntity b
HideEntity b
ShowEntity b
HideEntity b
ShowEntity b
HideEntity b
ShowEntity b

it wouldn't draw a flickering object, would it? You're code can eliminate unneccesary processes. Some obvious optimisations are...
If nu
   nu\time=nu\time-1
   If nu\time<0 Then
      Delete stuff**
   Else If nu\alpha<0 Or EntityX(nu\ent)>10 Or EntityX(nu\ent)<-10 Or EntityY(nu\ent)>10 Or EntityY(nu\ent)<-10
      Delete stuff**
   Else If Not EntityInView(nu\ent,cam) Then
      Delete Stuff**
   EndIf
This way you don't perform the latter two tests if the first is fulfilled and the object(s) are destroyed.

Note, the Delete Stuff** lines, I'm confused as t what you're doing here. Nu is a custom type, as is b, right? And it's for controlling bullets, right? So you're calling For Every Nu/Bullet?

If Nu is a time for the bullet's lifespan, why don't you integrate it into the bullet type? From the above snippet it's unclear how b relates to nu and you may find one object exists without the other. You could be creating bullets without creating Nu's and so never delete the bullets objects which'll cause the memory leak. If you can, keep all the data regards an object inside it's own custom type.


big10p(Posted 2005) [#24]
Arrrrggghhhhhhhh!!!!!!!

Will people please stop replying to ancient threads, especially only to post incorrect information (Beserker). :/


Tom(Posted 2005) [#25]
LOL!