Author Topic: Something is wrong, can't see it, no exceptions...  (Read 1965 times)

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
Something is wrong, can't see it, no exceptions...
« on: January 16, 2007, 06:00:56 AM »
It's been a while since I had a technical question regarding BC, but this is the one thing (so far found) that is keeping a new release of BP Core (and related things).

It's the Animated Texture Maps. These maps are scripted animated maps, and it's original implementation was correct, but performance wise totally unacceptable. And it had a dependency with FoundationTechnologies (not a bad thing, but it's not widely used) which was optional (that aspect simply didn't work otherwise:P).

The new approach is way better, performance wise. No noticeable lag on my machine, at least, no additional. :lol: My BC is a bit bloated. ^_^'



Ok, back to the problem at hand.

When animated maps are called, it starts swapping them from within the scripts, the current approach is to use a sequence for this. Looping is achieved by reconstructing the sequence at it's end. This works, and isn't really important here.

What does work, correctly, is stopping them. Sure the animation is stopped (btw, if anyone knows a fool proof way to stop a sequence without crashing BC, it would be appreciated, the current system simply lets the sequence die off by earlier outing (this too will need to be thinked a bit through, mostlikely an extra identifier, more on this later, I think).

But it doesn't leave the map system in a state where it functions properly.
The map system works by storing the new texture name under the original texture name.
The texture name is different from the texture path.
For instance, this texture path:
Data/Models/Sets/EBridge/High/A_Particular.Map.tga
This is valid. This is it's name:
A_Particular.Map

The function that does this is called DistillNewMapName, and you see it in the functions below here and there.

If the map "A_OriginalMap" is swapped by A_Particular.Map then it needs to store the new name in the Map System, otherwise, subsequent swaps wouldn't know where to swap it. So they all refer to A_OriginalMap, but in fact, they change the real map name underneath and swap it with that.


Back to the problem at hand, the animation system doesn't leave the map system in a continual state (ie. other maps can successfully swap new maps). But if you rerun the sequence it works fine, but not directly. It's almost as if it doesn't set the right map.



You can be sure of that these functions are correctly called.

First possible function, SwitchAnimatedMaps, this function is called when the texture swap mechanism detects an animated texture. The list is stored, so that the Texture swap mechanism can detect it later on (so that it's also stopped). It basically sets stuff up and sets things in motion.
Code: [Select]
def SwitchAnimatedMaps(sOldMap, lNewMaps):
global oBridgeInfo
if oBridgeInfo.dTextureAnimations.has_key(sOldMap):
#print "Animation already present"
StopAnimatedMaps(sOldMap)

oBridgeInfo.Maps["CurrentMaps"][sOldMap] = lNewMaps

bLooping = 0
dTrack = {}

if type(lNewMaps) == types.ListType:
bLooping = lNewMaps[0]
dTrack = lNewMaps[-1]
else:
if not lNewMaps.has_key("dTrack"):
dTrack = lNewMaps
else:
bLooping = lNewMaps.get("bLooping", 0)
dTrack = lNewMaps["dTrack"]

dAnimation = {}
oBridgeInfo.dTextureAnimations[sOldMap] = dAnimation

lMapNames = []
for value in dTrack.values():
lMapNames.append(DistillNewMapName(value))

dAnimation["MapNames"] = lMapNames
dAnimation["MapPaths"] = dTrack.values()
dAnimation["dTrack"] = dTrack
dAnimation["bLooping"] = bLooping
dAnimation["CurrentIndex"] = 0
dAnimation["Length"] = len(lMapNames)
dAnimation["sOldMap"] = ""+sOldMap
dAnimation["AniName"] = sOldMap

ConstructSeqFromDict(dAnimation)

Also not the issue, I think. But it starts the sequence.
Code: [Select]
def ConstructSeqFromDict(dAnimation):

# Construct a sequence of texture switches
pSequence = App.TGSequence_Create()
pSequence.SetSkippable(1)
dAnimation["Sequence"] = pSequence
iSub = 0
for index, map in dAnimation["dTrack"].items():
pSequence.AddAction(App.TGScriptAction_Create(__name__, "SwitchAniMapsAction", dAnimation["AniName"]), App.TGAction_CreateNull(), index)
iSub = index
pSequence.Play()

The function that does things. Not sure if it's causing it or not, but unlikely, since it successfully swaps maps.
Code: [Select]
def SwitchAniMapsAction(pAction, sName):
global oBridgeInfo
if not oBridgeInfo.dTextureAnimations.has_key(sName):
return 0
dAnimation = oBridgeInfo.dTextureAnimations[sName]

index = dAnimation["CurrentIndex"] + 1
sOldMap = dAnimation["sOldMap"]
if index+1 == dAnimation["Length"]:
if dAnimation["bLooping"]:
dAnimation["CurrentIndex"] = 0
ConstructSeqFromDict(dAnimation)
return 0
# Now I need to write the last map back
StopAnimatedMaps(sName)
return 0
sNewMap = dAnimation["MapPaths"][index]
DirectSwitchMaps(sOldMap, sNewMap)
dAnimation["CurrentIndex"] = index
dAnimation["sOldMap"] = DistillNewMapName(sNewMap)
return 0

This function is mostlikely the cause. Since this function is responsible for setting the map system right again.
Code: [Select]
def StopAnimatedMaps(sKey):
#print "Stopping", sKey
global oBridgeInfo
if not oBridgeInfo.dTextureAnimations.has_key(sKey):
return
dAnimation = oBridgeInfo.dTextureAnimations[sKey]
print dAnimation["sOldMap"]
oBridgeInfo.CurrentMaps[sKey] = dAnimation["sOldMap"]
del oBridgeInfo.dTextureAnimations[sKey]
return


And here is an issue I mentioned above, just thought of it. Dangling sequences.
If a sequence is aborted then it becomes what I like to call a "dangling sequence", it isn't referred to anymore, and it, shouldn't, do(esn't) any more work. Now, if you quickly stop and start a sequence, before the sequence can run out, then it creates a dangling sequence (in the current method) because it doesn't actually abort/stop the sequence (I haven't been able to do that without crashing BC). The symptoms of this (in this system) is fast(er) texture changes, since each step is basicly done twice (especially noticable in looping animations).

Now, 2 sollutions, find a way to stop/abort/skip the sequence (if you know a way, it should be possible, but haven't been able to do it). This way is preferable.
The other, is to assign id's to sequences, and use that instead of the "name" (sName in the action function).



I hope you the reader has made it until this (not fallen asleep:P), and have seen the problem.
Please post it if you do!
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.

Offline El

  • Master Hardpointer
  • Retired Administrator
  • Posts: 653
  • Cookies: 123
  • Former Vice Admin
Re: Something is wrong, can't see it, no exceptions...
« Reply #1 on: January 16, 2007, 06:34:59 PM »
I think I see the problem, although my python knowledge isn't very extensive.

To stop a sequence;
Put some type of flag at the beginning of the sequence.

When the flag is true the sequence runs.
When its false it stops, but only after it has completed that cycle

So your basically waiting for the sequence to finish (in the case of looped sequences) and you can't stop it part way through.

I think that's what your getting at?

Offline Bren

  • DS9FX Team
  • Posts: 750
  • Cookies: 33
  • 6EQUJ5
Re: Something is wrong, can't see it, no exceptions...
« Reply #2 on: January 16, 2007, 08:20:35 PM »
But will that stop memory leaking, or is that an issue?
"The sky calls to us, if we do not destroy ourselves, we will, one day, venture to the stars." - Carl Sagan

Klingon Academy now works on XP/Vista/Win 7 thanks to one dude's patches, click here for details. I highly recommend it!

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
Re: Something is wrong, can't see it, no exceptions...
« Reply #3 on: January 17, 2007, 03:29:40 AM »
I think I see the problem, although my python knowledge isn't very extensive.

To stop a sequence;
Put some type of flag at the beginning of the sequence.

When the flag is true the sequence runs.
When its false it stops, but only after it has completed that cycle

So your basically waiting for the sequence to finish (in the case of looped sequences) and you can't stop it part way through.

I think that's what your getting at?
In a way, that's what I'm already doing (and also is the cause of the "dangling sequences" problem I mentioned, though that's more my implementation).

But will that stop memory leaking, or is that an issue?
Well, I haven't noticed it yet. Which can be a good sign. ^_^
I suppose a small beta will have to find that out.

To think about it, it was JediFX (flames and such) that caused the memory leaks (since it reloaded every sound each time it was used).
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.

Offline Bren

  • DS9FX Team
  • Posts: 750
  • Cookies: 33
  • 6EQUJ5
Re: Something is wrong, can't see it, no exceptions...
« Reply #4 on: January 20, 2007, 12:42:47 PM »
*casts a sideways glance at LJ*
"The sky calls to us, if we do not destroy ourselves, we will, one day, venture to the stars." - Carl Sagan

Klingon Academy now works on XP/Vista/Win 7 thanks to one dude's patches, click here for details. I highly recommend it!

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
Re: Something is wrong, can't see it, no exceptions...
« Reply #5 on: January 20, 2007, 12:45:19 PM »
*casts a sideways glance at LJ*
I believe it's fixed now.


Let's try not to deviate from the real problem shall we?

To reinterate, it's not the dangling sequences that is the problem, it's how the final map is written back into the system that isn't correct.
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.

Offline LJ

  • Retired Staff
  • Posts: 1661
  • Cookies: 1139
Re: Something is wrong, can't see it, no exceptions...
« Reply #6 on: January 20, 2007, 01:51:59 PM »
I assume it has the right data?  And if you take yourself through the process, step by step in the console it all works?

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
Re: Something is wrong, can't see it, no exceptions...
« Reply #7 on: January 20, 2007, 04:18:58 PM »
I assume it has the right data?  And if you take yourself through the process, step by step in the console it all works?
I tried that, but it's rather, headache causing and it clutters the console a lot.
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
Re: Something is wrong, can't see it, no exceptions...
« Reply #8 on: January 22, 2007, 06:19:54 PM »
I had a little time debugging it, and I think I know the cause of the problem.

I do this:

oBridgeInfo.CurrentMaps[sKey] = dAnimation["sOldMap"]


But in the end, it didn't change it.

Of course, dAnimation is going to be deleted, but how could it store it's previous value?


Also, dAnimation["sOldMap"] points to the right map, otherwise the entire system wouldn't work.:P
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.