aya-lang / aya

Pocket sized programs
MIT License
54 stars 3 forks source link

image.write fails unless image.read is called first. #94

Closed BlazingTwist closed 2 months ago

BlazingTwist commented 2 months ago

This program fails

{,
    2 :width;
    2 :height;
    [0 0 0 128 0 0 0 255 0 0 0 255] :data;
    "$(:{sys.wd})/test.bmp" :filename;
} :{image.write}

with this error:

An unhandled exception occurred. If this is a bug, please submit an issue to https://github.com/nick-paul/aya-lang/issues with the stacktrace below.
=== [ Stacktrace ] ===
java.lang.RuntimeException: java.lang.NullPointerException: Cannot invoke "aya.obj.symbol.Symbol.name()" because "key" is null
    at aya.obj.block.Block.eval(Block.java:169)
    at aya.Aya.run(Aya.java:323)
    at aya.Aya.run(Aya.java:258)
    at aya.Aya.run(Aya.java:103)
Caused by: java.lang.NullPointerException: Cannot invoke "aya.obj.symbol.Symbol.name()" because "key" is null
    at aya.exceptions.runtime.IndexError.<init>(IndexError.java:44)
    at aya.obj.dict.Dict.get(Dict.java:77)
    at aya.util.DictReader.getNumberListEx(DictReader.java:111)
    at aya.ext.image.AyaImage.fromDict(AyaImage.java:44)
    at aya.ext.image.WriteImageInstruction.execute(WriteImageInstruction.java:43)
    at aya.obj.block.Block.eval(Block.java:163)
    ... 3 more

The main problem lies here: https://github.com/aya-lang/aya/blob/29629d4c2d8538c5913166d239ef10b8be3a30c0/src/aya/ext/image/AyaImage.java#L44

These static fields are used before the constructor call initializes them

    private static Symbol DATA;
    private static Symbol WIDTH;
    private static Symbol HEIGHT;