Page MenuHome

Tentative Python initialization of bge submodules

Authored by Inês Almeida (brita_) on Jun 21 2014, 7:44 PM.



Tentative Python initialization of bge submodules for T40132
The current problems are left as comments in the diff.
I filled a stackoverflow question to try to get some answers:

Diff Detail

Event Timeline

I'm having a bit of deja vu here. Isn't it kinda the same change you landed recently?

This change seems to introduce problems when the game engine is started more than once. In the attached Blend file

, the following code is called from a Python controller logic brick:

import bge

# Just shortening names here
keyboard = bge.logic.keyboard

def update(ctrl):
    if[] in ACT:
        print('V key pressed')

This works fine at the first run of the BGE. However, when you press [ESC] to stop and [P] to start the BGE again, this exception is shown:

Python script error - object 'Cube', controller 'Python':
Traceback (most recent call last):
  File "/home/sybren/workspace/blender-git/bge-reloading-test.blend/", line 10, in update
SystemError: Blender Game Engine data has been freed, cannot use this python variable

Using "git bisect" I found that this issue was introduced in commit 2699866720e75adc2aaba5079f87b705ceda9eab.

@Sergey Sharybin (sergey) yes, it is the same thing. At the time of GSoC, I was told to drop this, so I made this task with what I had. Now that I committed I forgot to close this.
Sybren's comment is a new thing, though.

@Campbell Barton (campbellbarton) the error seems to be called because when the logic module already exists, it does not replace it's inner variables with the engine's new runtime ones:$1586

Removing the return solves the issue, but then I'd say that instead of importing and doing nothing, we should be recreating and replacing the module assuring also that trash that may have gotten into the module's dictionary is thrown away.

I suggest D1070