Page 1 of 1

Random macro ending prob.

Posted: Wed Jul 07, 2004 3:56 pm
by wolf5
I have a macro that sometimes just get a "Macro has ended" out of the blue.

http://halsvik.net/d/?/public/nbh.mac

I do not think I have functions that call eachother ending in stacking overflow.

I read it might be eating of memory.

I can not think of anything that might cause that besides my dynamic (increasing) array sub. It copies the old array to a temp array, deletes the old array. Then it creates a new array with 1 size larger, copies the data from the temp array and fills in the new element:

Code: Select all

|----------------------------------------------------------------------------
|SUB: AddToArray - Dynamically adds elements to an array.
|----------------------------------------------------------------------------
Sub AddToArray(string varname, string vartype, targID)
	/declare i int local
	/declare copyofarr[0] ${vartype} local
    /if (${Defined[${varname}]}) { 
        /deletevar copyofarr

		/declare copyofarr[${${varname}.Size}] ${vartype} local

		/for i 1 to ${${varname}.Size}
			/varset copyofarr[${i}] ${${varname}[${i}]}
		/next i
		
        /deletevar ${varname}
	    /declare ${varname}[${Math.Calc[${copyofarr.Size}+1]}] ${vartype} outer
    	/for i 1 to ${Math.Calc[${copyofarr.Size}]}
			|/echo varset ${varname}[${i}] ${copyofarr[${i}]}
			/varset ${varname}[${i}] ${copyofarr[${i}]}
	    /next i
		/varset ${varname}[${${varname}.Size}] ${targID}
    } else {
    	/declare ${varname}[1]}] ${vartype} outer
		/varset ${varname}[1]}] ${targID}
    }

/return
Would that create a memory problem?
Is there a way to debug the memory usage to maybe pinpoint a memory leakage?



I have read through the manual, but is there an undocumented array that would allow for redimensioning keeping the data? (ala VisualBasics Redim Preserve)

Or just a nice ArrayList implementation would be nice :-) (for those aggro list, ignore lists etc..)

-Wolf5

Posted: Wed Jul 07, 2004 5:26 pm
by dont_know_at_all
Run dbgview from sysinternals.com. There is a bunch of debug information that will get printed in dbgview window. You should be able to tell what is happening from that.

Posted: Wed Jul 07, 2004 5:55 pm
by wolf5
Thanks. Will check that one out.

-Wolf5

Posted: Thu Jul 08, 2004 1:24 pm
by dman
From what I read of your macro, I believe your randomly ending macro problem is in this set of code of your Mainsub.

Code: Select all

   |If we get attacked while running to our target, we just got ourselves a new one instead
    /if ( ${Spawn[${TargetID}].Distance} > TARGET_RADIUS ) {
        |If we get attack on the way, assist pet every 4 sec
        /varcalc cnt1 ${cnt1}+1
	    /if ( ${cnt1} > 40 ) {
            /call AssistPet "mainattackloop"
	        /if ( ${Target.ID} && ${Target.Type.Equal[NPC]}) {
	        	/call ClearTarget "MAL"
	        	/call SetTarget "mainattack"
        	    /return 0
            }
            /varset cnt1 0
        }
   	}
If I follow the flow of the macro right, this section when you get attacked enroute to your initial target and all the ifs line up right, you will assist your pet to obtain a target, clear your old target, and set the newtarget. At this point your MainSub /returns to Sub Main, which then immediately returns ending the macro.

Posted: Thu Jul 08, 2004 1:42 pm
by wolf5
YAY. Thanks. Didn't see that. Must've been a leftover from moving the if block out of a Sub into this one :-)

Thank you very much. Finally the code is stable.

-Wolf5

Posted: Thu Jul 08, 2004 9:37 pm
by Drumstix42
Nice catch.