{"id":647,"date":"2011-12-14T11:40:23","date_gmt":"2011-12-14T11:40:23","guid":{"rendered":"http:\/\/41j.com\/blog\/?p=647"},"modified":"2011-12-14T11:40:23","modified_gmt":"2011-12-14T11:40:23","slug":"sdl_blitsurface-causes-memory-leak-on-macos-x","status":"publish","type":"post","link":"https:\/\/41j.com\/blog\/2011\/12\/sdl_blitsurface-causes-memory-leak-on-macos-x\/","title":{"rendered":"SDL_BlitSurface causes memory leak on MacOS X"},"content":{"rendered":"<p>When I use SDL_BlitSurface on Mac OS X it seems to cause a memory leak, it&#8217;s probably in some way related to the way I&#8217;m using Blit but anyway I needed a quick hack to get round the problem, performance is not really an issue so I just wrote a function to write the points to the screen one by one:<\/p>\n<p>There are a bunch of things this version doesn&#8217;t do that SDL_BlitSurface does, so beware. It ignores src_rec (just like SDL_BlitSurface would if it were NULL), and it does no conversion to insure source and dest are the same format (so you&#8217;ll have to convert the surfaces first).<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nvoid SlowBlitSurface(SDL_Surface *source,SDL_Rect *src_rec,SDL_Surface *dest,SDL_Rect *dest_rec) {\r\n\r\n  int sbpp = source-&gt;format-&gt;BytesPerPixel;\r\n  int dbpp = dest-&gt;format-&gt;BytesPerPixel;\r\n  for(size_t x=0;x&lt;source-&gt;w;x++) {\r\n    for(size_t y=0;y&lt;source-&gt;h;y++) {\r\n      Uint8 *p = (Uint8 *)source-&gt;pixels + (((y * source-&gt;w) + x) * sbpp);\r\n      Uint32 pval = *(Uint32 *) p;\r\n      Uint8 *d = (Uint8 *)dest-&gt;pixels   + ((((dest_rec-&gt;y+y) * (dest-&gt;w)) + (dest_rec-&gt;x+x)) * dbpp);\r\n      *((Uint32 *) d) = pval;\r\n    }\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>When I use SDL_BlitSurface on Mac OS X it seems to cause a memory leak, it&#8217;s probably in some way related to the way I&#8217;m using Blit but anyway I needed a quick hack to get round the problem, performance is not really an issue so I just wrote a function to write the points [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-647","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1RRoU-ar","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/647","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/comments?post=647"}],"version-history":[{"count":1,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/647\/revisions"}],"predecessor-version":[{"id":648,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/647\/revisions\/648"}],"wp:attachment":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/media?parent=647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/categories?post=647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/tags?post=647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}