FlagBrew / PKSM-Scripts

General purpose scripts to use with PKSM.
58 stars 14 forks source link

Bug Report - Crash running Munchlax Trees Checker script (Platinum) #44

Closed i8sigmapi closed 3 months ago

i8sigmapi commented 1 year ago

Describe the bug Attempting to run the script to determine which trees can give you Munchlax in Platinum version crashes the device.

To Reproduce Steps to reproduce the behavior:

  1. Open Platinum version save
  2. Select Scripts
  3. Press Y for universal scripts
  4. Scroll down to DPPt - Munchlax Trees Checker.c and select it
  5. Advance through opening text
  6. Crash occurs

Expected behavior The script should run as intended and inform me of which Honey Trees can contain Munchlax without crashing.

Information about your environment

Additional context Tested on both a dump save and a cartridge save. Happens in both cases.

SpiredMoth commented 1 year ago

I've done some testing on my own Pt save file and can confirm intermittent crashing. The location names for the first pair of trees always displayed fine. The times when I didn't crash had gibberish shown for the second pair of trees.

The crash seems to be the result of an out-of-bounds read by line 47, or line 48 trying to display the result.

sprintf(message, "%s\n%s", trees[res[2]], trees[res[3]]);
gui_warn(message);

I'll try a DP save later but suspect the results will be the same.

As DPPt - Honey Tree Manipulator.c uses the same tree determination and location name lookup logic and didn't crash, this narrows the cause to:

GriffinG1 commented 1 year ago

Transferring to Scripts repo.

SpiredMoth commented 1 year ago

This is definitely a spooky bug. I have tried 3 different DPPt saves so far, each with different results:

In hopes that the fix might be this easy, @i8sigmapi can you test something for me?

  1. extract this zip to the root of your SD card DPPt_Munchlax.zip
  2. Load your crashing Pt save in PKSM
  3. Go to Scripts, press Y then X
  4. Run the listed DPPt - Munchlax Trees Checker.c script

If this works, then I'll commit the fix so it'll be in the next PKSM release.

i8sigmapi commented 1 year ago

ahh, i'm so sorry i didn't see this until now!

unfortunately, it still crashes. it hasn't ever even displayed the first pair of trees for me.

[edit] could the varying behavior be tied to which trees it's trying to detect? [edit 2] actually i am now realizing that's probably kind of a ridiculous idea [edit 3] tested with my cartridge save too, since that's distinct from the one i use with twilight menu. same behavior. [edit 4] using the honey tree manipulator, the munchlax trees for these two crashing saves are:

[edit 5] restoring my shame (the first two edits). like you said, obviously it's probably string related

SpiredMoth commented 1 year ago

I should have made this post nearly a month ago (1ba4238) but the script is now fixed.

Instead of being a string issue like I thought, the problem ended up being that IDs were being pulled from the save file as signed int but the code was expecting unsigned int.

The fixed version of the script will be bundled in the next release of PKSM. If you want to use the script before then, extract the attached zip to the root of your SD card and run the script by doing the following:

  1. Open Scripts menu
  2. press Y to bring up the Universal scripts
  3. press X to bring up the scripts on your SD card
  4. select DPPt - Munchlax Trees Checker.c

DPPt_Munchlax_Checker.zip