Community

SCI Programming => SCI Development Tools => Topic started by: MusicallyInspired on April 22, 2021, 01:00:01 AM

Title: SCI Companion Pic Editor saving bug?
Post by: MusicallyInspired on April 22, 2021, 01:00:01 AM
So I was creating a Picture resource for KQ2SCI on stream yesterday and towards the end I decided to test it. I saved it and loaded up the game and half my work wasn't showing up. The commands were all there in the Pic, but it wasn't working. I tried closing the Pic and reopening it and...it was all messed up. Most of my work was lost and only some of it persisted in being saved. Since I was streaming, though, I had all the commands listed on video so I painstakingly went through the video frame by frame and reimplemented each draw tool command from the draw command list on the video. That took ages. And then....it got even worse. Commands I didn't even make started garbling the screen in the Visual, Priority, and Control screens alike.

I narrowed the problem down to the Pen tool using the randomized pattern (specifically size 2). So I figure something isn't saving right when it comes to that specific draw command. It recorded two of the pen tool draw commands fine, but by the third it randomly decided to turn on the Visual tool and start painting on coordinates that aren't even on the picture (like in the thousands) and randomly appearing in a bunch of places on the screen and the entire rest of the picture ended up being corrupted. I had to remove the Randomized Pen Pattern tool commands entirely and it saved just fine.

This may be something we're already aware of I don't know. Now that I've run into it like this, though, I do remember running into it in the past and remembered trying to avoid using the randomized pattern pen tool. I've used it on other pictures in KQ2SCI, but with those I used SCI Studio to draw the pictures way back when. So I guess I'll have to use Studio sometimes for those details. I haven't nailed down exactly how or why it's corrupting but I intend to do further testing and experimenting with the SCI Pic resource file specs closeby.
Title: Re: SCI Companion Pic Editor saving bug?
Post by: gumby on April 23, 2021, 09:32:25 PM
Do you still have the original (broken) pic and attach it here for help troubleshooting?  Which version/build of Companion are you using?
Title: Re: SCI Companion Pic Editor saving bug?
Post by: MusicallyInspired on April 24, 2021, 09:47:40 AM
I'm using one of Kawa's builds from October 2018. Using a later build does the same thing though. And I recall this still being an issue way back before Companion 3 came out.

pic_hopefully.016 is the full corrupted image.
pic16_grass_test.016 was my attempt to save just the grass data with the random pattern pen tool. Same corruption.
Title: Re: SCI Companion Pic Editor saving bug?
Post by: gumby on April 25, 2021, 06:31:41 PM
Out of curiosity I did some testing with the random pattern tool.  I was able to get corruption multiple times with any size of random pen.  All I did was create a new pic, set the visual screen and just clicked a bunch of times with the random pen tool.  Saved and then went back into the pic and corruption was there in the form of off-screen lines (in the thousands), fill commands or set palette commands at the end of the command list.
Title: Re: SCI Companion Pic Editor saving bug?
Post by: troflip on April 26, 2021, 07:09:09 PM
This looks like the fix for that bug (January 2017):

https://github.com/icefallgames/SCICompanion/commit/b97e9c5c29b037cacb9bad1d02c659382194908c#diff-a65be7d67191b6bf6f9da1b8cbf0256927977ef8d8d229c1f585d56d125d8ede

A Kawa build from 2018 should have had that fix in it though...

Sorry you lost a bunch of work.
Title: Re: SCI Companion Pic Editor saving bug?
Post by: Kawa on April 27, 2021, 07:20:55 AM
That meshes with my fruitless attempts to reproduce the bug. So any build from 2018 onwards should be good.
Title: Re: SCI Companion Pic Editor saving bug?
Post by: MusicallyInspired on April 27, 2021, 11:41:41 PM
That meshes with my fruitless attempts to reproduce the bug. So any build from 2018 onwards should be good.

Then why does your recent Jan 19 2021 build with the Picture drawing GIF animation export feature still have the bug?
Title: Re: SCI Companion Pic Editor saving bug?
Post by: Kawa on April 28, 2021, 04:53:54 AM
That's a very interesting question. The bug was fixed by Phil in January 2017, far before I started my changes ("Commit ALL the changes!" is from October 2018), and the current version still has the changes from 2017 in it. According to the commit history for PicCommands.cpp, it goes "fix long-standing bug", "commit all the changes", irrelevant formatting jank, gif. Which means if there was a regression, it was in one of two other files which I'll check now.

And I insist I couldn't reproduce it when I tried.


Edit: View.cpp and TestPicDraw were untouched since.
Title: Re: SCI Companion Pic Editor saving bug?
Post by: MusicallyInspired on April 28, 2021, 08:52:36 AM
I have the draw commands saved in a clipboard file because there's no other way for me to save it. No matter what build of Companion I paste them into, it looks fine until I save it to a file and open it (again, doesn't matter what build). And it's always corrupted.

I used InsideClipboard to save the data and load it again so I can paste it into the Pic editor because there was no other way for me to preserve the draw commands intact.
Title: Re: SCI Companion Pic Editor saving bug?
Post by: Kawa on April 28, 2021, 09:45:03 AM
Well, I'm convinced. And I have no idea.

I'm just going through the list of commands, seeing where it breaks, removing each one that does so...

137x118 pat C (2-78)
103x160 pat C (2-7A)
85x154 pat C (2-79)
122x121 pat C (2-79)
202x208 pat C (2-7E)
...

just seeing where it does something Weird and going back and forth, deleting the next command and exporting...

And there we go. From 121x119 all the way down to 125x44, with a dozen or so little clusters missing.

The next step is to keep hold of the breaking command list, part of which I bothered to transcribe above, and see why those specific commands seem to be mistaken for others, and go from there.
Title: Re: SCI Companion Pic Editor saving bug?
Post by: troflip on April 28, 2021, 12:59:46 PM
Ok... this shouldn't be too hard to figure out... it's failing on the third pen command...
Title: Re: SCI Companion Pic Editor saving bug?
Post by: troflip on April 28, 2021, 01:52:51 PM
Seems to have something to do with the the pattern index (the random part) being too large (>= 120) and being interpreted as a new command instead of a continuation of the pattern command. However, when you're drawing, the code clamps the value to 118, so that should never happen.
Title: Re: SCI Companion Pic Editor saving bug?
Post by: troflip on April 28, 2021, 02:01:19 PM
Musically Inspired, are you sure this image wasn't created with an old version of SCI Companion? Or some other program?

The third pen command contains an invalid random pattern:

Code: [Select]
Pen: 121x119 Pat-C (2-69)
Pen: 129x119 Pat-C (2-15)
Pen: 137x118 Pat-C (2-78)  // 78 is too big... max allowed is 76
Title: Re: SCI Companion Pic Editor saving bug?
Post by: troflip on April 28, 2021, 02:06:51 PM
Ahh... that fix never made it into the official branch, I see.

In CPicView::_MakeRandomNR() and CPicView::_OnPatternRClick(), the 128 should be changed to 119.

Hold on...
Title: Re: SCI Companion Pic Editor saving bug?
Post by: troflip on April 28, 2021, 02:12:01 PM
Ok, I checked in a fix to the main branch, but I'm not set up to build (or test it, but it should be fine).
Title: Re: SCI Companion Pic Editor saving bug?
Post by: Kawa on April 28, 2021, 03:00:20 PM
Ok, I checked in a fix to the main branch, but I'm not set up to build (or test it, but it should be fine).
On it!


New build with the fix is in the stash.
Title: Re: SCI Companion Pic Editor saving bug?
Post by: troflip on April 28, 2021, 03:29:49 PM
Awesome.

Musically Inspired, note that if you use those same pasted commands, the picture will still be corrupt. You'll need to delete any random pen commands that end with any hex number 77 and above (there's about 10 of them), then it should save correctly.
Title: Re: SCI Companion Pic Editor saving bug?
Post by: MusicallyInspired on April 28, 2021, 05:38:40 PM
Dang. So I might as well just redraw them from scratch then. But I still have the coordinates so if I redraw them in the same coordinates with the latest build it should be fine? Sweet. Thanks for helping to tackle this, guys! I really appreciate it.

I've tested this by redrawing all the commands and it did indeed work! Eureka!
Title: Re: SCI Companion Pic Editor saving bug?
Post by: Kawa on April 29, 2021, 03:34:51 AM
Why redraw it? Just scan through the list of commands and delete the handful of Pen commands with invalid numbers.
Title: Re: SCI Companion Pic Editor saving bug?
Post by: MusicallyInspired on April 29, 2021, 09:03:24 AM
Ah sorry I misunderstood ad I skimmed (I skim way too much). Oh well it's done now.