Progress Update #9
Bugs Beget Bugs
In the process of fixing a recent bug I have inadvertently discovered many more.
The issue that I just fixed had to do with biomes, and has existed since I implemented biome blending. The issue being that if you had more than 2 biomes the material would freak out and band the biomes around latitude lines quite strangely.
Here are some pictures to help explain what I'm talking about:
To try to debug this problem I first tried ol' reliable; the print string. I set up a UE_LOG in the
BiomePercentFromPoint()
function to see what it was returning. The weird thing was it was supposed to return something between 0-1 but it was always returning either 0, a really large number in the billions, or the same large number but negative. Something was clearly amiss so I dug deeper with breakpoints. I set a breakpoint at the end of the function so I could see every value as it would be right before the function returned. What was strange was that the return value should have been, in this case, the BiomeIndex / 2. When I watched BiomeIndex it was showing some value around 10 to 11 and so the function should have been returning 5ish but the UE_LOG was still showing the same values as before. I started to disregard the values I got from the UE_LOG because something was messing with it. That something may have been Visual Studio's "optimization measures".
While I was trying to see the values of all the variables when in the breakpoint, some would say "Variable is optimized away and not available" and wouldn't show the value. Some quick googling told me that Visual Studio has some optimization techniques that speed up execution in debug mode, one of which is "moving local variables to locations the debugger does not understand".
To get around this is actually quite easy. User Temaran on the Unreal Engine forums shows how you can use the preprocessor directive
#pragma optimize("", off)
to turn off this optimization and see the values you want. Once I did this, I could see that my weight variable which should have been between 0 and 1 was being set anywhere up to 11. Doing a quick
FMath::Clamp<float>()
fixed this in a jiffy (and is how I got the screenshot for the expected outcome), but I would still like to do some more debugging to know why the value is getting blown up so much more than it should. Now that that was fixed I went to add more biomes to the Earth-like planet. I did 5 total: 2 arctic biomes with one at each pole, 1 desert biome across the equator, and one 'default' biome on each side of the desert. When I tried to generate this though it crashed the editor. The engine was complaining that the texture it was trying to create for the planet had a size that wasn't a power of 2. This was true as the texture is always 256 long but the height is equal to the number of biomes, in this case 5 which is not a power of 2. Not really sure why 3 worked then with the Martian planet before but whatever.
The hacky fix is to duplicate any of the biomes until there is a power of 2 number total. Not clean, user-friendly, or efficient, but 'it works for now™' and allows me to get screenshots like this:
So in the end I'm one bug down, way more than one to go.
Comments
Post a Comment