Neverending loop
#7
Aye, the problem with the code was simply: There was no problem!  I was simply curious to see how many people might end up banging their head all night over a trick question -- which is something which you guys end up having us poor devs do all the time.  Somebody will report an issue, and at first glance, it appears to be an actual issue...  Then, after spending *forever* digging into it, we finally realize, "Everything is working 100% as it should -- it's just that how it should work isn't how the user expects it to work!" 

In this case, it's exactly as Mark (and Matt over at Discord, before him), has deduced:  The explosion *is* working as intended -- the problem here is that we set the speed of the exploding pieces based upon the distance from the center.  In this case, there's several transparent boxes created near the center of the screen, and as such, they only have a movement rate of about 0.4 pixels per loop.  With a loop limit of 60, those blocks move all of 24 pixels per second, and have about 500 pixels to travel.  Simple math tells us that they're not going to exit the screen for 20+ seconds -- which is *exactly* what we see happening in the program.

Visibly, it appears as if there's a glitch in the matrix -- the program runs, and within a few seconds all visible content is exploded off the screen, leaving it to appear to be doing nothing for the next dozen seconds.  If you're an impatient programmer, it's easy to jump to a conclusion and say, "Welp, that's an endless loop!", as there's no visible confirmation of any changes happening inside the program or on the screen.  In all actuality, the program *is* working 100% as intended; it's just that it's working with transparent boxes of pixels.  Color the background as Mark has in his code above, and you can easily see what's going on here.

Lesson to be learned from this?

Not all code is "broken".  Often, its just the user's expectations which is incorrect! 
Reply


Messages In This Thread
Neverending loop - by SMcNeill - 07-30-2022, 03:18 AM
RE: Neverending loop - by Pete - 07-30-2022, 03:42 AM
RE: Neverending loop - by Pete - 07-30-2022, 04:08 AM
RE: Neverending loop - by bplus - 07-30-2022, 05:02 AM
RE: Neverending loop - by TempodiBasic - 08-02-2022, 01:08 PM
RE: Neverending loop - by bplus - 07-30-2022, 05:11 AM
RE: Neverending loop - by Pete - 07-30-2022, 05:26 AM
RE: Neverending loop - by SMcNeill - 07-30-2022, 03:13 PM
RE: Neverending loop - by bplus - 07-30-2022, 03:43 PM
RE: Neverending loop - by Pete - 07-30-2022, 03:45 PM
RE: Neverending loop - by Kernelpanic - 07-30-2022, 09:54 PM
RE: Neverending loop - by bplus - 08-02-2022, 03:42 PM
RE: Neverending loop - by Kernelpanic - 08-02-2022, 05:03 PM
RE: Neverending loop - by admin - 08-02-2022, 06:59 PM
RE: Neverending loop - by Kernelpanic - 08-02-2022, 07:51 PM
RE: Neverending loop - by TempodiBasic - 08-04-2022, 12:43 AM



Users browsing this thread: 15 Guest(s)