From f6a4037af427da22d619a64ece1e2db787b8ced0 Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Sun, 19 Apr 2020 17:14:04 +0200 Subject: [PATCH] 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 --- tools/VmaDumpVis/VmaDumpVis.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/VmaDumpVis/VmaDumpVis.py b/tools/VmaDumpVis/VmaDumpVis.py index f5a38b1..519ee30 100644 --- a/tools/VmaDumpVis/VmaDumpVis.py +++ b/tools/VmaDumpVis/VmaDumpVis.py @@ -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')