{"action":"created","issue":{"url":"https://api.github.com/repos/nim-lang/sdl2/issues/37","labels_url":"https://api.github.com/repos/nim-lang/sdl2/issues/37/labels{/name}","comments_url":"https://api.github.com/repos/nim-lang/sdl2/issues/37/comments","events_url":"https://api.github.com/repos/nim-lang/sdl2/issues/37/events","html_url":"https://github.com/nim-lang/sdl2/issues/37","id":65820867,"number":37,"title":"Calling the 'close' closure member of RWopsPtr throws an illegal storage access error","user":{"login":"G4MR","id":4134947,"avatar_url":"https://avatars.githubusercontent.com/u/4134947?v=3","gravatar_id":"","url":"https://api.github.com/users/G4MR","html_url":"https://github.com/G4MR","followers_url":"https://api.github.com/users/G4MR/followers","following_url":"https://api.github.com/users/G4MR/following{/other_user}","gists_url":"https://api.github.com/users/G4MR/gists{/gist_id}","starred_url":"https://api.github.com/users/G4MR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/G4MR/subscriptions","organizations_url":"https://api.github.com/users/G4MR/orgs","repos_url":"https://api.github.com/users/G4MR/repos","events_url":"https://api.github.com/users/G4MR/events{/privacy}","received_events_url":"https://api.github.com/users/G4MR/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-04-02T02:26:00Z","updated_at":"2015-04-03T13:12:47Z","closed_at":"2015-04-03T13:12:47Z","body":"Error:\r\n\r\n    example.nim(33)          :anonymous\r\n    image.nim(90)            close\r\n    image.nim(93)            close\r\n    SIGSEGV: Illegal storage access. (Attempt to read from nil?)\r\n    Error: execution of an external program failed\r\n\r\nSource:\r\n\r\n    import sdl2, sdl2.image as img\r\n    import helpers\r\n\r\n    import typetraits\r\n\r\n    type Image* = ref object\r\n        rw*: RWopsPtr\r\n        format: string\r\n        loaded: bool\r\n        surface: SurfacePtr\r\n        texture: TexturePtr\r\n        src_rect: Rect\r\n        dst_rect: Rect\r\n\r\n    method getFormat*(self: Image): string =\r\n        if isNil(self.format):\r\n            \"none\"\r\n        else:\r\n            self.format\r\n\r\n    method isLoaded*(self: Image): bool = \r\n        self.loaded\r\n\r\n    method setDimensions*(self: Image; src, dst: Rect) =\r\n        self.src_rect = src\r\n        self.dst_rect = dst\r\n\r\n    method setDimensions*(self: Image; src, dst: tuple[x, y: int; w, h: int]) =\r\n        self.setDimensions(toRect(src), toRect(dst))\r\n\r\n    method setSrc*(self: Image, src: Rect) =\r\n        self.src_rect = src\r\n\r\n    method setSrc*(self: Image, src: tuple[x, y: int; w, h: int]) =\r\n        self.setSrc(toRect(src))\r\n\r\n    method setDst*(self: Image, dst: Rect) =\r\n        self.dst_rect = dst\r\n\r\n    method setDst*(self: Image, dst: tuple[x, y: int; w, h: int]) =\r\n        self.setDst(toRect(dst))\r\n\r\n    method load*(self: Image, file: cstring, render: RendererPtr) =\r\n\r\n        self.loaded = false\r\n        self.rw = sdl2.rwFromFile(file, \"rb\")\r\n\r\n        if not isNIl(self.rw):\r\n            if img.isGIF(self.rw) == 1:\r\n                self.format = \"gif\"\r\n            elif img.isPNG(self.rw) == 1:\r\n                self.format = \"png\"\r\n            elif img.isJPG(self.rw) == 1:\r\n                self.format = \"jpg\"\r\n            elif img.isBMP(self.rw) == 1:\r\n                self.format = \"bmp\"\r\n            elif img.isWEBP(self.rw) == 1:\r\n                self.format = \"webp\"\r\n            else:\r\n                self.format = nil\r\n\r\n        if isNil(self.rw):\r\n            echo \"yes...\"\r\n\r\n        if not isNil(self.format):\r\n\r\n            # try loading surface\r\n            self.surface = img.load_RW(self.rw, 1)\r\n            if isNil(self.surface):\r\n                #throw exception\r\n                return\r\n\r\n            #try loading texture\r\n            self.texture = sdl2.createTextureFromSurface(render, self.surface)\r\n            if isNil(self.texture):\r\n                #throw exception\r\n                return\r\n\r\n            self.loaded = true\r\n\r\n    method draw*(self: Image, render: RendererPtr) =\r\n        \r\n        if isNil(self.texture):\r\n            return\r\n\r\n        # draw font to screen\r\n        sdl2.copy(render, self.texture, addr(self.src_rect), addr(self.dst_rect))\r\n\r\n    # Release any resources used by the stream and free RWopsPtr memory\r\n    method close*(self: Image) =\r\n\r\n        if not isNil(self.rw):\r\n            let close_rw = self.rw.close(self.rw)\r\n            #echo \"closed successfully\"\r\n\r\n        if not isNil(self.surface):\r\n            destroy self.surface\r\n\r\n        if not isNil(self.texture):\r\n            destroy self.texture\r\n\r\nUsage:\r\n\r\n    var img = Image()\r\n    img.load(\"example.jpg\", sdl_renderer)\r\n\r\n    .. loop ..\r\n\r\n    img.close()"},"comment":{"url":"https://api.github.com/repos/nim-lang/sdl2/issues/comments/89284624","html_url":"https://github.com/nim-lang/sdl2/issues/37#issuecomment-89284624","issue_url":"https://api.github.com/repos/nim-lang/sdl2/issues/37","id":89284624,"user":{"login":"G4MR","id":4134947,"avatar_url":"https://avatars.githubusercontent.com/u/4134947?v=3","gravatar_id":"","url":"https://api.github.com/users/G4MR","html_url":"https://github.com/G4MR","followers_url":"https://api.github.com/users/G4MR/followers","following_url":"https://api.github.com/users/G4MR/following{/other_user}","gists_url":"https://api.github.com/users/G4MR/gists{/gist_id}","starred_url":"https://api.github.com/users/G4MR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/G4MR/subscriptions","organizations_url":"https://api.github.com/users/G4MR/orgs","repos_url":"https://api.github.com/users/G4MR/repos","events_url":"https://api.github.com/users/G4MR/events{/privacy}","received_events_url":"https://api.github.com/users/G4MR/received_events","type":"User","site_admin":false},"created_at":"2015-04-03T13:12:47Z","updated_at":"2015-04-03T13:12:47Z","body":"oh my god, I'm retarded.  Thanks.  "}}