{"id":76,"date":"2008-08-13T11:17:53","date_gmt":"2008-08-13T09:17:53","guid":{"rendered":"https:\/\/blogs.scummvm.org\/buddha\/?p=76"},"modified":"2022-04-15T12:41:35","modified_gmt":"2022-04-15T10:41:35","slug":"memory-corruption-hunting","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/buddha\/2008\/08\/13\/memory-corruption-hunting\/","title":{"rendered":"Memory corruption hunting"},"content":{"rendered":"<p>Hi! I\u2019ve been fixing lots of things in Operation Stealth. I started using <a href=\"http:\/\/valgrind.org\/\">Valgrind<\/a> because the <a href=\"http:\/\/wiki.scummvm.org\/index.php\/Cine\">Cine<\/a> engine corrupted memory and I didn\u2019t know where to start fixing it. I\u2019ve now got Valgrind running ScummVM under <a href=\"http:\/\/www.ubuntu.com\/\">Ubuntu<\/a> 8.04 which I\u2019m running in <a href=\"http:\/\/www.virtualbox.org\/\">VirtualBox<\/a>. A virtual machine (VirtualBox) running a virtual machine (Valgrind), yay! One could think that it\u2019d be dead slow, but actually it runs ok.<\/p>\n<p>So I recommend trying out <a href=\"http:\/\/valgrind.org\/\">Valgrind<\/a> if you\u2019ve got memory corruption problems with a program you\u2019re developing even if you don\u2019t run Linux natively, it can be used through a virtual machine like <a href=\"http:\/\/www.virtualbox.org\/\">VirtualBox<\/a>, <a href=\"http:\/\/bellard.org\/qemu\/\">QEMU<\/a> or <a href=\"http:\/\/www.vmware.com\/products\/player\/\">VMWare<\/a>. I already got some memory corruption problems fixed with Valgrind\u2019s help.<\/p>\n<p><!--more--><\/p>\n<h3>Stuff done since last update:<\/h3>\n<h4>Bugfixes:<\/h4>\n<ul>\n<li>Fixed popup boxes blocking animation (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/b8bfd5d04f0436b685ea36a845439e20bb756766\" target=\"_blank\" rel=\"noopener\">r33686<\/a>)<\/li>\n<li>Partially fixed Adlib volume setting (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/70760a77fdb42a18ea9997f7a3c74b613c589af6\" target=\"_blank\" rel=\"noopener\">r33700<\/a> trunk, r33701 0.12.0)<\/li>\n<li>Fixed \u2018text hard to read\u2019 problems (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/96a1ca17090eb17157707a9e989eec3ebb7c94fc\" target=\"_blank\" rel=\"noopener\">r33792<\/a>)<\/li>\n<li>Fixed inventory showing (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/811e4b3128de561289a19806c854ea05a9ab96b5\" target=\"_blank\" rel=\"noopener\">r33795<\/a>)<\/li>\n<li>Fixed verb handling bug (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/eb9633ee1e085df0ce7fc747a5ee58891c2aa986\" target=\"_blank\" rel=\"noopener\">r33805<\/a>)<\/li>\n<\/ul>\n<h4>New functionality:<\/h4>\n<ul>\n<li>Implemented game speed changing by pressing \u2013 or + (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/092d7224b95d611414c2940bf48b095ade6dcf40\" target=\"_blank\" rel=\"noopener\">r33689<\/a>)<\/li>\n<li>Added moving using keyboard (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/5cb08bd1e5aca23f685caee0544a77d4824cec15\" target=\"_blank\" rel=\"noopener\">r33698<\/a> &amp; <a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/36e6bb27b5c5fed7f304e80801afc4b8fa292ccd\" target=\"_blank\" rel=\"noopener\">r33710<\/a>)<\/li>\n<li>Basic support for CD Future Wars (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/c0701bfcb670e43cf4a26bfefb94bf82a76f62b9\" target=\"_blank\" rel=\"noopener\">r33703<\/a> trunk, r33705 0.12.0)<\/li>\n<li>Added drawing of type 22 overlays as filled rectangles (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/e02f94d3922b39bdc8d0333c2e9fd602aeb40ef6\" target=\"_blank\" rel=\"noopener\">r33713<\/a>)<\/li>\n<li>Preliminary drawing of type 21 overlays (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/0f0759218471cb79c0e15c67f248ca83176b918d\" target=\"_blank\" rel=\"noopener\">r33721<\/a> &amp; <a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/3e5e5f5342c60f7b48ea451751937c214d61dca9\" target=\"_blank\" rel=\"noopener\">r33722<\/a>). WIP!<\/li>\n<li>Implemented transparent cutscene textboxes (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/88ec480cef8d637c2fd69b8197ab3c7de39ede8b\" target=\"_blank\" rel=\"noopener\">r33790<\/a>)<\/li>\n<\/ul>\n<figure id=\"attachment_77\" aria-describedby=\"caption-attachment-77\" style=\"width: 640px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-77\" src=\"https:\/\/blogs.scummvm.org\/buddha\/wp-content\/uploads\/sites\/16\/2022\/04\/scummvm-operation_stealth-transparent_cutscene_textboxes_working.png\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/blogs.scummvm.org\/buddha\/wp-content\/uploads\/sites\/16\/2022\/04\/scummvm-operation_stealth-transparent_cutscene_textboxes_working.png 640w, https:\/\/blogs.scummvm.org\/buddha\/wp-content\/uploads\/sites\/16\/2022\/04\/scummvm-operation_stealth-transparent_cutscene_textboxes_working-300x225.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><figcaption id=\"caption-attachment-77\" class=\"wp-caption-text\">Cutscene textboxes working in ScummVM<\/figcaption><\/figure>\n<h4>Memory corruption and out of bounds access related changes:<\/h4>\n<ul>\n<li>Fixed rectangle drawing (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/853f4dbbe00afb8d857c821dd6c0ef3aed4733f2\" target=\"_blank\" rel=\"noopener\">r33687<\/a> &amp; <a href=\"http:\/\/scummvm.svn.sourceforge.net\/scummvm\/?rev=33811&amp;view=rev\">r<\/a><a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/954244d3502343cc945f730bddd116f1e461d46f\" target=\"_blank\" rel=\"noopener\">33811<\/a> trunk, r33814 0.12.0)<\/li>\n<li>Added sanity tests to background scrolling (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/da84a546943bd28615ccc6e4999e697c855e58d6\" target=\"_blank\" rel=\"noopener\">r33688<\/a>)<\/li>\n<li>Converted objectTable to Common::Array (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/09119829549c13c06aa5af80ca01197eb8ce7cda\" target=\"_blank\" rel=\"noopener\">r33725<\/a>)<\/li>\n<li>Converted animDataTable to Common::Array (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/983a4f21e51814d4f2a65480c6e571ca5a6fb0c3\" target=\"_blank\" rel=\"noopener\">r33726<\/a>)<\/li>\n<li>Converted zoneData &amp; zoneQuery to Common::Array (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/ef3b72d5e4a7b1772799224fe94ade279ea2fb5a\" target=\"_blank\" rel=\"noopener\">r33727<\/a>)<\/li>\n<li>Converted partBuffer to Common::Array (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/2d5a140725194f8a44d98091b510469f5889275a\" target=\"_blank\" rel=\"noopener\">r33783<\/a>)<\/li>\n<li>Converted palPtr to Common::Array (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/8aaba9d38e8a0c2259cf7617bb1b07c725a49b0b\" target=\"_blank\" rel=\"noopener\">r33785<\/a>)<\/li>\n<li>Fixed fontParamTable freeing (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/36e0d2eab8bc920d337d8e6f1436e057049ffac6\" target=\"_blank\" rel=\"noopener\">r33786<\/a>)<\/li>\n<li>Converted commandBuffer to Common::String (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/c935a09ef53a594f408d3279cd30c783bade9ed1\" target=\"_blank\" rel=\"noopener\">r33793<\/a>)<\/li>\n<li>Fixed handling of incorrect input data in loadMsg (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/00cbedb25f891ef508e71c49ffa0f9973361ba60\" target=\"_blank\" rel=\"noopener\">r33810<\/a>)<\/li>\n<li>Fixed initialization of instrument data (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/582104752b337adcc2f51b3fa4842a0b8a5b42db\" target=\"_blank\" rel=\"noopener\">r33812<\/a> trunk, r33813 0.12.0)<\/li>\n<\/ul>\n<h4>Cleanup:<\/h4>\n<ul>\n<li>Removed unnecessary textDataPtr (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/d6dde4b85f3f32fe0f602270b9223eaa299db91c\" target=\"_blank\" rel=\"noopener\">r33784<\/a>)<\/li>\n<\/ul>\n<p>And as Valgrind noticed some memory problems in the <a href=\"http:\/\/wiki.scummvm.org\/index.php\/AGI\">AGI<\/a> engine\u2019s sound engine I committed some fixes related to them (<a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/be9192687b22e11bee2fe98f5e06a7a2dd623fd1\" target=\"_blank\" rel=\"noopener\">r33816<\/a> &amp; <a href=\"https:\/\/github.com\/scummvm\/scummvm\/commit\/09762ac7a6c7e201b44466b8286aa1e53e7fadaa\" target=\"_blank\" rel=\"noopener\">r33822<\/a> trunk, r33820 &amp; r33823 0.12.0). I had previously noticed that the AGI engine\u2019s sound engine sometimes crashed when starting the first sound in an AGI game, so hopefully that\u2019s fixed now.<\/p>\n<h3>What next?<\/h3>\n<p>Well, I got to the part where the player character is dropped into the sea with a woman, but I\u2019m currently stuck there. After sorting out the memory corruption problems and testing the original game\u2019s behaviour in this particular part it seems the problem is somehow related to incorrect character moving. The character should first swim near the girl and then try \u201cOperate Girl\u201d to untie her ropes (It works that way in the original). Here\u2019s a picture of the thing working in DOSBox:<\/p>\n<figure id=\"attachment_78\" aria-describedby=\"caption-attachment-78\" style=\"width: 320px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-78\" src=\"https:\/\/blogs.scummvm.org\/buddha\/wp-content\/uploads\/sites\/16\/2022\/04\/dosbox-operation_stealth-untying_girls_ropes.png\" alt=\"\" width=\"320\" height=\"200\" srcset=\"https:\/\/blogs.scummvm.org\/buddha\/wp-content\/uploads\/sites\/16\/2022\/04\/dosbox-operation_stealth-untying_girls_ropes.png 320w, https:\/\/blogs.scummvm.org\/buddha\/wp-content\/uploads\/sites\/16\/2022\/04\/dosbox-operation_stealth-untying_girls_ropes-300x188.png 300w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><figcaption id=\"caption-attachment-78\" class=\"wp-caption-text\">Freeing the girl in DOSBox<\/figcaption><\/figure>\n<p>But alas in ScummVM currently the player character can only be moved to the left and he automatically moves upwards almost all the time. So I can\u2019t get to the girl to untie her and they both drown. With the memory corruption problems out of the way I\u2019m looking into fixing this character moving problem next.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi! I\u2019ve been fixing lots of things in Operation Stealth. I started using Valgrind because the Cine engine corrupted memory and I didn\u2019t know where to start fixing it. I\u2019ve now got Valgrind running ScummVM under Ubuntu 8.04 which I\u2019m running in VirtualBox. A virtual machine (VirtualBox) running a virtual machine (Valgrind), yay! One could [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-76","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/posts\/76","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/comments?post=76"}],"version-history":[{"count":3,"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/posts\/76\/revisions"}],"predecessor-version":[{"id":107,"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/posts\/76\/revisions\/107"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/media?parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/categories?post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/tags?post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}