omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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)

    Pythonista
    2
    3
    2834
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Cethric
      Cethric last edited by

      @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 the ObjCBlock class the __call__ method references a unassigned value.

      def ___call__(self, *args):
          return self.func(*args)
      

      However self.func is never actually set.

      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        Thanks, didn't notice that. The __call__ implementation is basically just there for completion's sake because one might expect an ObjCBlock object to be callable...

        1 Reply Last reply Reply Quote 0
        • Cethric
          Cethric last edited by

          Welcome and ok.
          Will do a bit more research into why the crash is occurring then.
          Current code

          class 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 for EAGLContext.currentContext() where EAGLContext has not been allocated or initialised.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors