'module' object has no attribute 'blurtex'

The script with this problem is refreshing a videotexture.

Script:

from bge import logic as gfrom bge import texture
from mathutils import *
from math import *
import bgl


cont = g.getCurrentController()
own = cont.owner
scene = g.getCurrentScene()
objlist = scene.objects


texsize = 128 #refraction tex dimensions


activecam = scene.active_camera
rendercam = objlist['rendercam1']




#setting lens nad projection to watercamera
#rendercam.lens = activecam.lens
#rendercam.projection_matrix = activecam.projection_matrix


#disable visibility for the water surface during texture rendering
own.visible = False




###REFRACTION####################


#initializing camera for refraction pass
#rendercam.position = activecam.position
#rendercam.orientation = activecam.orientation




#rendering the refraction texture in tex channel 1
if not hasattr(g, 'tex'):
    g.tex = texture.Texture(own, 0, 0)
    g.tex.source = texture.ImageRender(scene,rendercam)
    g.tex.source.capsize = [texsize,texsize]
    g.tex.source.background = [100,100,100,0]


g.tex.refresh(True)


g.blurtex.refresh(True)
own.visible = True

The problem is with the second to last line:

g.blurtex.refresh(True)

Is there something wrong with the syntax?

I’m using 2.74

blend: lensflare.blend (1.39 MB)

Thanks

WTF is g.blurtex? You never initialize it anywere. g.tex works becouse you initialize it in g.tex = texture.Texture(own, 0, 0). If you are initializing it somewhere (another script), make sure it is before this one or check if the attribute exists before trying to use it. You do that with the if hasattr(g, ‘blurtex’): g.blurtex.refresh()

Great that seemed to solve the problem, maybe the scripts were being initialized before the game textures were loaded, resulting in an error for the first frame.

for anyone else:

replace g.blurtex.refresh(True) with:

if hasattr(g, 'blurtex'):
g.blurtex.refresh(True)

The samples for VideoTexture are not the best architecture. I really do not see why a custom object is stored as singleton at a build-in module. This restricts your code to a single object.

I suggest to store a newly created bge.texture.Texture() in a property at the object the object that creates it.
e.g.



def setupTexture():
     texture = bge.texture.Texture(...)
     ...
     owner = ...
     owner["texture"] = texture

def refresh():
     owner = ...
     owner["texture"].refresh(True)

This binds the objects to a specific game object. This means you can use this code for other objects and other textures too.