Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
objc_util ObjCBlock. __call__ method makes reference to unassigned variable (self.func)
-
@omz I was trying to implement a block function for
GLKTextureLoader.textureWithContentsOfFile_options_queue_completionHandler_
however it keeps crashing every time I test it (this could be more my fault in code than anything else but.) and in an attempt to test each part individually I noticed that in theObjCBlock
class the__call__
method references a unassigned value.def ___call__(self, *args): return self.func(*args)
However
self.func
is never actually set. -
Thanks, didn't notice that. The
__call__
implementation is basically just there for completion's sake because one might expect anObjCBlock
object to be callable... -
Welcome and ok.
Will do a bit more research into why the crash is occurring then.
Current codeclass CBlock(ObjCBlock): def __init__(self, func, restype=None, argtypes=None): super(CBlock, self).__init__(func, restype=None, argtypes=None) self.func = func type_encodings['@?'] = CBlock default_opt = { 'GLKTextureLoaderApplyPremultiplication': 0, 'GLKTextureLoaderGenerateMipmaps': 0, 'GLKTextureLoaderOriginBottomLeft': 0, 'GLKTextureLoaderGrayscaleAsAlpha': 0, 'GLKTextureLoaderSRGB': 0 } DEFAULTS = ns(default_opt) class GLKTextureLoader: def __init__(self, sharegroup=None): if sharegroup is None: sharegroup = currentContext().sharegroup print sharegroup tl = ObjCClass('GLKTextureLoader') self._loader = tl.alloc().initWithSharegroup_(sharegroup._sharegroup) def textureFromFile(self, path): callback = CBlock(GLKTextureLoaderCallback, restype=None, argtypes=[ctypes.c_void_p, ctypes.c_void_p]) print dir(self._loader) print DEFAULTS # self._loader.textureWithContentsOfFile_options_queue_completionHandler_(path, DEFAULTS, None, callback)
Note
currentContext()
is just a wrapper forEAGLContext.currentContext()
where EAGLContext has not been allocated or initialised.