openplanet-nl / issues

Issue tracker for Openplanet.
10 stars 0 forks source link

Shared class issue (definition not cleared on plugin reload) related to exceptions #451

Open XertroV opened 5 months ago

XertroV commented 5 months ago

I've been having a few issues developing some shared class stuff recently where the definitions don't update till I restart the game (and sometimes I will get errors about mismatching shared classes, but sometimes it compiles fine just not updated).

This might be related to exceptions, especially exceptions during hooks (but I am not sure if this is relevant).

For example, changing the following code didn't update when reloading the plugin (I forgot to add @ to the beginning of this.block = block and this.item = item). After reloading, I got the same exceptions and no compile errors (the exception was null ptr exception b/c it was probably looking for .opAssign):

    shared class SetSkinSpec : NetworkSerializable {
        string fgSkin;
        string bgSkin;
        BlockSpec@ block;
        ItemSpec@ item;

        SetSkinSpec(BlockSpec@ block, const string &in fgSkin, const string &in bgSkin) {
            this.block = block;
            this.fgSkin = fgSkin;
            this.bgSkin = bgSkin;
        }

        SetSkinSpec(ItemSpec@ item, const string &in skin, bool isForegroundElseBackground) {
            this.item = item;
            if (isForegroundElseBackground) {
                this.fgSkin = skin;
            } else {
                this.bgSkin = skin;
            }
        }
    }
codecat commented 2 months ago

I am unable to reproduce this 🧐

Is the shared class used by any other dependant plugins? I just tested it with main() copy to a separate dependant plugin and it still works for me.

My test code:

shared class NetworkSerializable{}
shared class BlockSpec{}
shared class ItemSpec{}

shared class SetSkinSpec : NetworkSerializable {
    string fgSkin;
    string bgSkin;
    BlockSpec@ block;
    ItemSpec@ item;

    SetSkinSpec(BlockSpec@ block, const string &in fgSkin, const string &in bgSkin) {
        @this.block = block;
        this.fgSkin = fgSkin;
        this.bgSkin = bgSkin;
    }

    SetSkinSpec(ItemSpec@ item, const string &in skin, bool isForegroundElseBackground) {
        @this.item = item;
        if (isForegroundElseBackground) {
            this.fgSkin = skin;
        } else {
            this.bgSkin = skin;
        }
    }
}
void Main()
{
    SetSkinSpec test(BlockSpec(), "", "");
    SetSkinSpec test2(ItemSpec(), "", false);
}
XertroV commented 2 months ago

Is the shared class used by any other dependant plugins?

Yes, and I reload the dependency plugin (which should reload both)

I think changing a function body but not signature will not trigger an error but the old function logic applies. Changing function signatures does produce an error (these are function signatures of methods of the shared class)