{"author_name":"GFM","cat":"LD #33","comments":[{"author_name":"","time":"August 22, 2015 12:04 pm","epoch":1440263040,"text":"&#8220;Guys! Look what you&#8217;re doing here! You&#8217;re dereferencing a null pointer! Open your eyes!&#8221;<br \/>\n &#8211;Bret &#8216;the Hitman&#8217; hart","spam":"N"},{"author_name":"","time":"August 22, 2015 1:58 pm","epoch":1440269880,"text":"Are you using valgrind? Use valgrind!","spam":"N"}],"epoch":1440262920,"likes":3,"metadata":{"p_key":"15106","p_author":"GFM","p_authorkey":"7375","p_urlkey":"50375","p_title":"\u2026","p_cat":"LD #33","p_event":"LD33","p_time":"1440262920","p_likes":"3","p_comments":"2","p_status":"UPD5","us_key":"7375","us_name":"GFM","us_username":"\/author\/gfm\/","event_start":"1440115200","event_key":"29","event_name":"LD33"},"text":"<p>So&#8230; Just now, all of a sudden, my game wouldn&#8217;t\u00a0run anymore. I though it was weird, since I shouldn&#8217;t have modified anything that would make things explode at random times&#8230; Well, since gdb wasn&#8217;t helping a lot, I tried to see how much free memory I still had&#8230; Just&#8230; look at the print screen:<\/p>\n <p><img class=\"aligncenter size-large wp-image-482624\" src=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2015\/08\/gfm_ld33_0003-550x76.png\" alt=\"gfm_ld33_0003\" width=\"550\" height=\"76\" srcset=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2015\/08\/gfm_ld33_0003-300x41.png 300w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2015\/08\/gfm_ld33_0003-550x76.png 550w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2015\/08\/gfm_ld33_0003.png 660w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/p>\n <p>125 MBs free&#8230;<\/p>\n <p>Since it was the first I was streaming, chronolapse was on, two browsers were open, a few GIMP windows were also open and was coding my game, I blamed all the softwares\u00a0(and not the stupid person that started &#8217;em all) for the lack of memory. No big deal, after restarting the computer everything should be normal again&#8230;<\/p>\n <p>Or not&#8230;<\/p>\n <p>My game still wouldn&#8217;t run and gdb was still breaking in random places. Now I had to admit it was something on my code that was causing it. After trying to make in run again and fixing a unrelated bug, I noticed the it started to happen after I added a new &#8220;object&#8221;.<\/p>\n <p>When I looked into its initialization function, it was quite clear what was wrong. This is how it looked at the time:<\/p>\n <pre>gfmRV mob_getNew(mob **ppMob) {\n gfmRV rv;\n \n ASSERT(ppMob, GFMRV_ARGUMENTS_BAD);\n ASSERT(!(*ppMob), GFMRV_ARGUMENTS_BAD);\n \n *ppMob = (mob*)malloc(sizeof(ppMob)); \/\/ &lt;---- pay attention to this line\n ASSERT(*ppMob, GFMRV_ALLOC_FAILED);\n \n rv = GFMRV_OK;\n __ret:\n return rv;\n }<\/pre>\n <p>Instead of alloc&#8217;ing enough memory for the object, I was only alloc&#8217;ing enough for the object&#8217;s pointer. So, when\u00a0the game tried to update it, it would modify random places in the memory. This was the cause to the random crashes.<\/p>\n <p>Well, lesson learned (once again). Coding in C can be <a href=\"http:\/\/dwarffortresswiki.org\/index.php\/DF2014:Losing\" target=\"_blank\">*fun*<\/a>.<\/p>\n <p>&nbsp;<\/p>","time":"August 22nd, 2015 12:02 pm","title":"\u2026"}