VmaDumpVis: Gracefully handle cases where there is nothing to put on the image, e.g. the stats string was generated without detailed map enabled

Message is printed in that case and 1 is returned instead of division by zero error.
Closes #125
This commit is contained in:
Adam Sawicki 2020-04-19 17:14:04 +02:00
parent 115d2971ae
commit f6a4037af4

View File

@ -66,6 +66,20 @@ def GetDataForMemoryType(iMemTypeIndex):
return newMemTypeData
def IsDataEmpty():
global data
for dictMemType in data.values():
if 'DedicatedAllocations' in dictMemType and len(dictMemType['DedicatedAllocations']) > 0:
return False
if 'DefaultPoolBlocks' in dictMemType and len(dictMemType['DefaultPoolBlocks']) > 0:
return False
if 'CustomPools' in dictMemType:
for lBlockList in dictMemType['CustomPools'].values():
if len(lBlockList) > 0:
return False
return True
# Returns tuple:
# [0] image height : integer
# [1] pixels per byte : float
@ -204,6 +218,10 @@ if 'Pools' in jsonSrc:
for sBlockId, objBlock in objBlocks.items():
ProcessBlock(dstBlockArray, int(sBlockId), objBlock, sAlgorithm)
if IsDataEmpty():
print("There is nothing to put on the image. Please make sure you generated the stats string with detailed map enabled.")
exit(1)
iImgSizeY, fPixelsPerByte = CalcParams()
img = Image.new('RGB', (IMG_SIZE_X, iImgSizeY), 'white')