[Bug] imageToArray returns a NoneType

I’ve been using the tutorial at the BGE Python documentation, but I’ve run into trouble with the imageToArray method. Hitting P results in the following console output:

Blender Game Engine Started
0
object_texture =
<VideoTexture.Texture object at 0x10a773768>
Url =
/Users/username/Desktop/Blender/Projects/Shark Game Project/shaderTest512.png
New source =
<VideoTexture.ImageFFmpeg object at 0x10f8cd228>
logic.object_texture.source =
<VideoTexture.ImageFFmpeg object at 0x10f8cd228>
<VideoTexture.ImageFFmpeg object at 0x10f8cd228>
None
Failed again!
None
Python script error - object ‘Plane’, controller ‘Python’:
Traceback (most recent call last):
File “ImageLength”, line 58, in <module>
TypeError: object of type ‘NoneType’ has no len()
Blender Game Engine Finished

The script is as followes:

from bge import texturefrom bge import logic
import math
cont = bge.logic.getCurrentController()


own = cont.owner


scene = bge.logic.getCurrentScene()


def createTexture(cont):#much of this function was stolen from the Blender Python online documentation
    """Create a new Dynamic Texture"""
    
    obj = cont.owner
    
    # get the reference pointer (ID) of the internal texture
    ID = texture.materialID(obj, "MAMaterial")
    print(ID)
    # create a texture object
    object_texture = texture.Texture(obj, ID)
    print("object_texture =")
    print(object_texture)
    
    if object_texture is None:
        print("Whoops")
    # create a new source with an external image
    #shaderTest512.png is the name of the file I am using
    url = logic.expandPath("//" + "shaderTest512.png")
    print("Url = ")
    print(url)
    new_source = texture.ImageFFmpeg(url)
    print("New source =")
    print(new_source)
    # the texture has to be stored in a permanent Python object
    logic.object_texture = object_texture
    
    # update/replace the texture
    logic.object_texture.source = new_source
    print("logic.object_texture.source =")
    print(logic.object_texture.source)
    #data = texture.source.image
    logic.object_texture.refresh(False)
    #data = tex.source.image
    return logic.object_texture


tex = createTexture(cont)
if tex is None:
    print("Fail!")


#print(tex.size)
print(tex.source)
print(tex.source.image)
arr = texture.imageToArray(tex.source, 'RGB')


if arr is None:
    print("Failed again!")


print(arr)
mvLength = len(arr)#at this point I get an error message thlling me that: object of type 'NoneType' has no len()

Attachments

ImageLength.blend (492 KB)


Script is fine. No image. If you rewrite
url = logic.expandPath("//" + “shaderTest512.png”)

to just

url = “c:\directory\image.png”

it works fine.

I tried replacing the text as you suggested, but I still get the same result. I then tried using “c:\directory\shaderTest512.png” without any luck. The shaderTest512.png file is located inside the same folder as the blend file. I probably should have mentioned this earlier, but I’m using Blender 2.70a (I checked the change logs of the more recent versions to see if there was a bugfix that corresponded to my problem. No dice.) and OSX 10.7.5.