Hooman,
I spent some time on this problem today. VS2017 can compile OP2Editor successfully in ReleaseMinSize and Debug. Both compilations allow Mapper2.exe to properly execute and load a map. However, whenever I try to attach the VS2017 debugger to Mapper2.exe, Mapper2.exe will crash when attempting to load a map. The program appears to work fine on load, but after a map is selected, it crashes.
VS2017 will indicate symbols are loaded properly when the PDB file is placed next to op2editor.dll. However, the presence of the PDB file does not affect whether it crashes or not, as the crash occurs whenever debugging is attached.
I'd bet that if the bug is from OP2Editor, it is coming from the function CTileSet::CalcMiniMapColors. By manipulating the values of R, B, and B in this function, I am able to change the color of the minimap in the mapper. I haven't figured out what the combo needs to be in order to fix the minimap.
I wonder if we need some sort of switch here that changes how the minimap is displayed based on if the BMP is Outpost 2 specific or generic.
The repo currently contains a post build event that copies op2editor.dll into the program files for debugging. This forces VS2017 to run in Administrator mode to work. This should probably be documented on the ReadMe or the post build event removed from the project. (Your welcome for its existence.)
There are 6 different solution configurations available in VS2017 to build. What do you think of dropping that down to just Debug and Release? Perhaps renaming ReleaseMinSize to just Release.
I'm going to leave it here for now, but let me know if you want help on anything else in general, committing to the repository or testing as I know you may not be able to test on Linux. Hopefully this helps.
// **TODO** Remove
void CTileSet::CalcMiniMapColors(int startTile, int endTile)
{
int tileByteSize = scanlineByteWidth*headInfo.width; // Note: assume square tiles
int tilePixelSize = headInfo.width*headInfo.width;
int pixelDataOffset;
RGBQUAD *rgbQuad;
int red, green, blue;
int tileNum, x, y;
int temp;
// Calculate minimap color of all tiles in given range
for (tileNum = startTile; tileNum <= endTile; tileNum++)
{
// Initialize color components
red = green = blue = 0;
// Calculate the minimap color of this tile (sum over all pixels in tile)
for (y = 0; y < headInfo.width; y++) // Note: assume square tiles
{
for (x = 0; x < headInfo.width; x++)
{
// Add the color components of this pixel
pixelDataOffset = tileNum*tileByteSize +
y*scanlineByteWidth +
((x*headInfo.bitDepth) >> 3);
switch(headInfo.bitDepth)
{
case 8:
temp = pixelData[pixelDataOffset];
rgbQuad = &bmInfo->bmiColors[temp];
// FIX: flip R and B colors around (they are stored backwards!)
//red += rgbQuad->rgbRed;
red += rgbQuad->rgbBlue;
green += rgbQuad->rgbGreen;
//blue += rgbQuad->rgbBlue;
blue += rgbQuad->rgbRed;
break;
case 16: // Assume 5/5/5 for RGB components **TODO** test this code
temp = *(short*)(pixelData+pixelDataOffset);
blue += (temp & 0x1F) << 3;
green += (temp & 0x3E0) >> 2;
red += (temp & 0x7C00) >> 7;
break;
default:
// Do nothing. Pixels will appear black
break;
}
}
}
// Scale color components by the number of pixels in the tile
red /= tilePixelSize;
green /= tilePixelSize;
blue /= tilePixelSize;
// Store the tile minimap color
rgbQuad = &miniMapColors[tileNum];
rgbQuad->rgbRed = red;
rgbQuad->rgbGreen = green;
rgbQuad->rgbBlue = blue;
rgbQuad->rgbReserved = 0;
}
}
Thanks,
Brett
EDIT
-----
Pulled out some extraneous info and improved readability.