Random macro ending prob.

Need help with a macro you are writing? Ask here!

Moderator: MacroQuest Developers

wolf5
a ghoul
a ghoul
Posts: 89
Joined: Wed Jun 02, 2004 12:58 pm

Random macro ending prob.

Post by wolf5 » Wed Jul 07, 2004 3:56 pm

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

User avatar
dont_know_at_all
Developer
Developer
Posts: 5450
Joined: Sun Dec 01, 2002 4:15 am
Location: Florida, USA
Contact:

Post by dont_know_at_all » Wed Jul 07, 2004 5:26 pm

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.

wolf5
a ghoul
a ghoul
Posts: 89
Joined: Wed Jun 02, 2004 12:58 pm

Post by wolf5 » Wed Jul 07, 2004 5:55 pm

Thanks. Will check that one out.

-Wolf5

dman
a hill giant
a hill giant
Posts: 181
Joined: Fri Dec 05, 2003 12:54 pm

Post by dman » Thu Jul 08, 2004 1:24 pm

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.

wolf5
a ghoul
a ghoul
Posts: 89
Joined: Wed Jun 02, 2004 12:58 pm

Post by wolf5 » Thu Jul 08, 2004 1:42 pm

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

Drumstix42
a grimling bloodguard
a grimling bloodguard
Posts: 808
Joined: Mon May 03, 2004 4:25 pm

Post by Drumstix42 » Thu Jul 08, 2004 9:37 pm

Nice catch.