Fix T45742: Drivers in Game Engine don't work for Spawned objects... Warning this fix doesn't work with the given example file (I don't know why exactly, but works with this: http://www.pasteall.org/blend/38719 and this: http://www.pasteall.org/blend/38785 (I just removed what was is the layer 2, duplicate the armature and the cube in layer 1 and moved it to layer 2, and change the addObject actuator "object"))
Details
Diff Detail
Event Timeline
It doesn't work with more than one object.
| source/gameengine/Converter/BL_ArmatureObject.cpp | ||
|---|---|---|
| 438 | normally when the armature is duplicated a new pose is created, but you don't free it before set the old one = memory leak. | |
Ok I'll try to free old pose before. It's weird, it doesn't crash for me.
On my computer it works with several objects... Could you upload an example that shows the issue with multiple objects @Porteries Tristan (panzergame), please?
Normally, I think game_copy_pose (BL_ArmatureObject.cpp) has to be called to copy poses for game objects. However, when you call BKE_object_copy, another function (copy_object_pose in object.c) is called...
The pose is not created correctly: BKE_object_copy > BKE_object_copy_ex (object.c) > copy_object_pose (object.c) > BKE_pose_copy_data (action.c) > BLI_duplicatelist(&outPose->chanbase, &src->chanbase); line seems not working... (if you replace this line with outPose->chanbase = src->chanbase, the drivers works again for spawned objects but Blender crashes when you escape the game)
That's the reason why I copied old pose before calling BKE_object_copy and applied this pose to the new armaObj (m_objArma->pose = tmpPose;)
My PC has only 4Gb of ram which fills up very fast when I run Visual Studio, Git, and the web browser. So if there Is a memory leek Blender will crash much earlier as on other PC's.
Actually I can run it only one time. Mostly it will crash at the second run, when I stop while the animation is playing.
But I am not sure if Blender will not crash if the animation is not playing, because catching every time the right moment to exit is very difficult.
@Thomas Szepe (hg1): Thanks for your answer :) The memory leak is still there with BKE_pose_free(m_objArma->pose); ? EDIT: Sorry if I misanderstood something, I don't know how memory is used in programmation... I'm very noob... I have to read a c++ tutorial :)
It is better now, but sometime Blender still crash. ShapeKeyTest (2).blend crash sometimes. ShapeKeyTest2.blend crashed 2 times but always after I started it after ShapeKeyTest (2).blend has crashed. The crashes comes definitely from this path, there are no crashes without this patch.
@Thomas Szepe (hg1): Ok thanks. So I don't know what is wrong... And the .blend doesn't crash for me. So I think I couldn't fix this without the help of someone more experienced than me :) (unless we have to free m_pose too? And what if we use game_copy_pose(m_objArma->pose, tmpPose, 1) ?)
Another test file: http://www.pasteall.org/blend/38797 (with this I can crash Blender on my computer. Yeeeha :) and we see the problem mentionned by Tristan ) So let's find another fix... (All was working right in 2.70)
I paste again the link of the problematic commit: https://developer.blender.org/rBfe05f97841c0ee3e2a6e15f2252ad160fefc3509
@Thomas Szepe (hg1) && @Mitchell Stokes (moguri): Could you tell me if with this file: http://www.pasteall.org/blend/38809, when you press P, wait ~20 seconds (or more), then escape the game, it crashes Blender with a 2.76 normal Blender's version? Could it be linked to BL_ArmatureObject::ProcessReplica too? Have you got an idea to solve the issue? (Tristan has tested but can't reproduce the bug... On my computer it crashes)
I tested it wit the original Blender 2.76 release, my build from yesterday and an actual build (all builds are 32 bit) there is no crash.
Maybe you have some changes left in your build or you don't actualized all sub modules or you need to make a fresh build.
Try build from the buildbot.
@Thomas Szepe (hg1): Thanks for the test. I tested with blender 2.76 64 official version from blender.org and I just tested with last buildbot release, and the crash still happens (I had to test 3 times before the crash). I'm on windows 10 64. I'll make a git bisect to see if that concerns the same commit... (I already tested with 2.70 and I can't crash it)
OK. I have done some additional tests with official Blender 2.76 64 bit and again with the my latest 32 bit build and both crash, but after approx 80s seconds and more then ~8ms logic load.
Then I have tested it with the official Blender 2.75 three times with 140s ~108ms logic load stopped because frame rate drops to 9 fps, no crash.
@Thomas Szepe (hg1): Thanks for the tests :) . I made tests too and this bug is not related to the current bug. (And what is weird is that the crash happens with official releases but not when I build Blender myself (I only build the game engine and few things...))
About the "drivers" bug, I tried 100 different things but without results. Tristan made also some tries but we don't understand what is wrong... I don't know how to rebuild/duplicate the pose correctly... I suspected it was a problem with bPoseChannels duplication but I'm not sure and this is too complex for me. Or when we duplicate something, perhaps we have to relink replicas to the new armature or something like that? I don't understand enough...