[fixed] Memory leak in FINDPATH() function

Bug Reports relating to the 097 core are moved to this forum once solved.

Moderator: POL Developer

Locked
coltain
Grandmaster Poster
Posts: 159
Joined: Tue Mar 20, 2007 7:17 am
Location: Poland

[fixed] Memory leak in FINDPATH() function

Post by coltain » Fri Dec 07, 2007 3:19 am

I finally found what caused memory allocation problem.

Simple test:
AI script is simple [find me and run to me (by runtoward)]
I summon instantly 300 mobiles and thay run to me (no problems, all is fine)

When I change AI script to first find a path (path:=FINDPATH(bla bla) ) and next follow this path using runtowardlocation() an allocation problem is shown... I then kill mobiles but the allocation problem still is present.

I like FINDPATH function co please fix it.
Last edited by coltain on Fri Dec 07, 2007 3:59 am, edited 1 time in total.

User avatar
OldnGrey
POL Expert
Posts: 657
Joined: Sat Feb 04, 2006 6:26 pm

Post by OldnGrey » Fri Dec 07, 2007 3:32 am

Can you please post the lines you are using for findpath() and runtowardlocation() showing how you are using the array returned by findpath in the runtowardlocation function.

I was a bit confused when you posted runtowardlocation(path[2].x,path[2].y)

coltain
Grandmaster Poster
Posts: 159
Joined: Tue Mar 20, 2007 7:17 am
Location: Poland

Post by coltain » Fri Dec 07, 2007 3:58 am

sorry, I was to exited to write it propetly

code form movement.inc (brainAI):

Code: Select all

.
.
.
		NEMOVE_RUN:
			case( ev.direction )
				NEMOVE_AWAY:
					repeat
						RunAWayFrom(ev.source);
						SleepMS(3);
					until ( !MoveLoopCheck(ev) );
				NEMOVE_TOWARD:
					repeat
                                       szukaj_sciezki(ev.source); //advanced run
						//RunToward(ev.source);  // simple run
						//SleepMS(3);                  // simple run
					until ( !MoveLoopCheck(ev) );
			endcase

//test
function szukaj_sciezki(cel)
    if(!cel || cel.dead)
        return;
    endif
    var sciezka := FindPath(self().x,self().y,self().z,cel.x,cel.y,cel.z,self().realm,0,25);
    if(sciezka)
        foreach wpis in (sciezka)
            RunTowardLocation(wpis.x,wpis.y);
            sleepms(3);
        endforeach    
    endif 
    return 1;
endfunction

Searching for path works, I have no trouble with it

User avatar
OldnGrey
POL Expert
Posts: 657
Joined: Sat Feb 04, 2006 6:26 pm

Post by OldnGrey » Fri Dec 07, 2007 4:46 am

Have you printed out the sciezka array to see what's in it?
I am now a big fan of testing for errortext from functions so I'd be modifying the function a bit to catch any errors. I haven't looked at the contents of the return array before but the doco does imply it's a struct per coord with .x and .y properties.

As a test:

Code: Select all

if ( sciezka && !sciezka .errortext ) 
  foreach wpis in (sciezka) 
    RunTowardLocation(wpis.x,wpis.y); 
    sleepms(3); 
  endforeach    
elseif (sciezka .errortext ) 
 PrintTextAbove(cel, sciezka.errortext);
endif

I've noticed that there has been a LOT of discussion about findpath over the last year. I have been avoiding it I must admit.

So where is the memory allocation error occuring? At what line? In findpath or in the RunTowardLocation?

Also, I'd be really careful about having a searchskirt as big as 25. That's going to be a huge attempt. The default is 5, I'd be looking to start with 5 and see.

These are just some thoughts, given my total lack of experience with findpath. Good luck narrowing it down.

Locked