aaron-casper / mapmaker

a tool for deploying map "prefabs" in besiege
0 stars 0 forks source link

map-reset (f4) feature causes crash #2

Open aaron-casper opened 4 years ago

aaron-casper commented 4 years ago

reset feature clears map UI, clears list of objects, closes file, but fails to reopen file. error returned "I/O operation on closed file object".

aaron-casper commented 4 years ago
Traceback (most recent call last):
  File "C:\Users\aaron\Desktop\besiege\mapmaker.py", line 404, in <module>
    f.write(brickwall_horiz.bricklayer(objID,scale,30,objX,Y,objY))
ValueError: I/O operation on closed file.``
aaron-casper commented 4 years ago

Poor handling of the file object by me. Now the call to mapReset not only gets provided the file object to close, it also generates the new file object as it's own instance and returns it. Lastly, the calling function applies that returned object over the existing object.

def mapReset (f):

    f.flush()

    os.fsync(f.fileno())

    print("file sync'd")

    f.close()

    print("file closed")

    try:

        f2 = open(mapName, "w")

    except Exception as e:

        print("IO Error: " + str(e))

    print("new file opened " + str(f.closed))

    f2.write(XMLheader)

    print("writing XML header")

    objects.clear()

    print("map memory cleared")

    headerBuffer.append("map reset")

    print("all done resetting the map")

    return f2

and

            if whichkey == "285":

                #print("map reset broken, issue on github")

                 f = mapReset(f)