marcrobledo / RomPatcher.js

An IPS/UPS/APS/BPS/RUP/PPF/xdelta ROM patcher made in HTML5.
https://www.marcrobledo.com/RomPatcher.js/
Other
653 stars 133 forks source link

[fix] `rec` can be undefined in `IPS.prototype.export` #64

Closed Destitute-Streetdwelling-Guttersnipe closed 9 months ago

Destitute-Streetdwelling-Guttersnipe commented 10 months ago

this PR fix the error in browser console:

Uncaught TypeError: Cannot read properties of undefined (reading 'truncate')
    at IPS.export (ips.js:66:9)
    at self.onmessage (worker_create.js:48:31)
marcrobledo commented 10 months ago

Hello! First of all, thank you for your contribution.

Can you provide an example or a patch that was failing before your fix?

Destitute-Streetdwelling-Guttersnipe commented 9 months ago

This error happens in creator mode when the user select the same file as original ROM and modified ROM by mistake. If the user choose IPS, there would be an error message: image There's no error with other patch types.

Another case I see this error is when the modified ROM is created by truncating something from the end of the original ROM. image This only happens with IPS, not with other patch types.

marcrobledo commented 9 months ago

Thank you @Destitute-Streetdwelling-Guttersnipe, I see the error now.

But, code would be still wrong, since IPS records have no truncate property. That's a property for the IPS class. It was my mistake from the start :-( I figure no one reported this since the IPS creation patch where the edited ROM is smaller than the original is a very uncommon case. Definitively, the code has been incorrect since first version.

The correct code would be:

    if(this.truncate)
        tempFile.writeU24(this.truncate);

Wanna fix it in this PR yourself? You found the bug after all and deserve credit :-)

Destitute-Streetdwelling-Guttersnipe commented 9 months ago

Thanks @marcrobledo for your explanation and your generosity. I updated my patch using this.truncate.

marcrobledo commented 9 months ago

Thanks to you :-)