Patching Blender
Patching means that we will take code that can do something in Blender that isn’t yet in the cvs and incorporate it into the existing source code. Patches for Blender can be found at the Blender Patch Tracker. They are usually in either a diff (.diff) or patch (*.patch) format. They both have the same information which is code that will be added to/replace/or remove code from the Blender source.
THE TORTOISE SVN WAY
Once the Blender source went to SVN, it became much easier to patch, especially if you are using TortoiseSVN. You can find how to Apply patches using Tortoise SVN here.
THE OLD WAY
PART 1
First you will need to download the source files. You can see PART 2 of my Blender build tutorial for two options to do this. You can go patch tracker any time to see if there is a patch that you would like to test. Keep in mind that the patches are still being worked on and might have updates every so often. Download the latest version of the patch at the bottom of the patch description page. Place the file under %Your Blender Source Folder%/blender/.
PART 2
There are two ways to patch: Downloading patch.exe or downloading Cygwin and getting the patch utilities from there. I use the patch utilities from Cygwin because it works for me, so I will discuss Cygwin here.
Click on setup.exe and select “Install from Internet.” Pick a place on your machine where you want Cygwin packages installed, then hit the Next a bunch of times. It will then ask you to pick a mirror to download the packages from. Any should do. After that’s picked, you will come to a list of packages you can install. Click the plus sign to expand the groups to see the packages. If you have already used Cygwin to get mingw, gcc, etc. to build blender as per Scons Refactoring, you’ve been here before. To get the patch utilities open the “Devel” group and scroll done to the patchutils package. Click on the word “Skip,” which should cause a version number to appear. If it says “Keep” instead of skip, you already have it installed so you can just close out Cygwin. If it said “Skip” and you clicked on it to get the current version, hit the next button to install it. After the install process, Cygwin will leave an install folder on the desktop (which you can delete if you want to).
PART 3
After you’ve installed, inside the Cygwin install folder, you’ll find cygwin.bat. This is where the magic happens. Open this up and you’ll be in a command prompt like environment. Navigate to the blender sources by using linux-like commands. So if the blender sources are in C:\bf-blender\blender\ then you will navigate to it using the following commands:
Step 1: cd C:/%Your Blender Source Folder% (note I use the forward slash and not the standard Windows backslash for directory listings)
Step 2: cd blender (I’ve found that you have to do each folder one at a time to get to where you need to go)
In your blender source directory, use the following command:
patch -p0 < patchname.txt
It will then say whether or not you are successful or not. If you are you’re ready to compile and build!
You can also undo the patch with the following command when you are in the blender source directory:
patch -p0 -R < mypatch.txt
PATCHING DIDN’T WORK?
If you are not successful, there might be several issues, but here are a few:
- The source files the patch is attempting to change have themselves been changed, so the patch doesn’t understand where things should go and fails. You can check by looking at the patch text and seeing what version of each file the patch is going to modify and then checking if those files in the source are the same version. If this is the reason for the failure, check the patch tracker to see if there is an update of the patch or contact the author of it if this is the case.
- The patch itself isn’t made correctly. This is a rare event however there are rare cases when an author updates the script and breaks it. Check the patch tracker to ensure you have the latest, and if you do, ask the author. I’m sure they would want to know if there are issues!
- For the old way: You might have the patch in the wrong place, be using the patch command in the wrong place, or you might be using the wrong file name. Ensure you’ve got everything in the right place (using the instuctions above). Also, make sure you are using the right filename of the patch. I use .txt above, but the patch you’re using might be .patch.
If you have any troubles patching, fell free to contact me and we can work through it together!
