• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[TextTags] Do we need to destroy them?

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,338
Hi,

So TextTags (TTs) can be given values that determine how long they last/how quick they fade out.

But as far as I know, TTs need to be destroyed otherwise they will cause a permanent leak, like any non-primitive type in WC3.

So suppose I have the following code, and I need to make sure at each loop iteration that I destroy the TT to avoid accumulating leaks.

JASS:
	loop
		if ... then
			set j = 0
			loop
				...
				if ... then
					set tt = CreateTextTag()
					call SetTextTagText(tt, "Exp +" + I2S(R2I(expGain)), 0.02)
					call SetTextTagVisibility(tt, true)
					call SetTextTagPosUnit(tt, m, 0)
					call SetTextTagColor(tt, 190, 0, 255, 255)
					call SetTextTagVelocity(tt, 0, 0.04)
					call SetTextTagPermanent(tt, false)
					call SetTextTagLifespan(tt, 3)
					call SetTextTagFadepoint(tt, 2)
					//call DestroyTextTag(tt)
					set tt = null
				endif
				set j = j + 1
			endloop
		endif
		set i = i + 1
	endloop

If I uncomment the line that destroys the TT, the TT never actually gets displayed. This is obviously because it's destroyed before it gets to appear on the screen (or at least no human can see it in between the time that it's displayed and the microseconds that it gets destroyed).

So how would I proceed here? I am not willing to write up a timer or hash table the TT and then figure out smartly how to delete it. That is too much overhead for what should have a very simply solution (i.e. a one liner that calls the destroy).

Or is that the only real solution?
 
If memory serves me right, setting its lifespan is equivalent to destroying it after X seconds. So in that case, you don't actually have to use DestroyTextTag. The fact that it has: (1) a lifespan (2) is not permanent; already handles the memory associated with the texttag.

If you destroy it right away, then nothing will be displayed.
 
Status
Not open for further replies.
Top