Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Maybe one of the worst bugs I've ever had

Maybe one of the worst bugs I've ever had

Scheduled Pinned Locked Moved The Lounge
architecturehelplounge
12 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H honey the codewitch

    I wrote a video display driver for an RA8875 display controller. I need it because I use it in one of my commercial projects. Well, it works "fine" (a bit slow, but the controller is slow) except in one demo. I am trying to draw a series of rounded rectangles of random size, random coordinates and random colors. The code is relatively simple and should be innocuous. It also works when it's used as part of a larger routine. But when I simplify the code, remove the big routine, and just run a lines demo followed by the rounded rectangles the whole MCU freezes solid during the 3rd iteration. (Always in the same place but that doesn't matter because even randomization yields the same result boot to boot. There's no real RTC or any sort of non-determinism so freezing in the same spot every time isn't much of a clue in this case). I need to fix this, or at the very least verify it will never happen in my commercial project but I am totally stumped. What a morning.

    To err is human. Fortune favors the monsters.

    Greg UtasG Offline
    Greg UtasG Offline
    Greg Utas
    wrote on last edited by
    #3

    I know sfa about this. But could it be a timing thing, like the simplified code running too fast and overloading the MCU?

    Robust Services Core | Software Techniques for Lemmings | Articles
    The fox knows many things, but the hedgehog knows one big thing.

    <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
    <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

    H 1 Reply Last reply
    0
    • Greg UtasG Greg Utas

      I know sfa about this. But could it be a timing thing, like the simplified code running too fast and overloading the MCU?

      Robust Services Core | Software Techniques for Lemmings | Articles
      The fox knows many things, but the hedgehog knows one big thing.

      H Offline
      H Offline
      honey the codewitch
      wrote on last edited by
      #4

      It doesn't happen when it's part of a larger routine, and basically it's just spinning a loop for 90 iterations drawing rounded rectangles - using draw::filled_rounded_rectangle<>(). The 3rd time it begins that loop (which itself is part of a larger loop) it freezes about 5 or so iterations in. Not when it's part of the larger subroutine though.

      To err is human. Fortune favors the monsters.

      J 1 Reply Last reply
      0
      • L Lost User

        If your "main" can't call your new extracted routine, then you still have dependencies. That's what I use "statics" for (real or simulated).

        "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

        H Offline
        H Offline
        honey the codewitch
        wrote on last edited by
        #5

        it can call it.

        To err is human. Fortune favors the monsters.

        1 Reply Last reply
        0
        • H honey the codewitch

          It doesn't happen when it's part of a larger routine, and basically it's just spinning a loop for 90 iterations drawing rounded rectangles - using draw::filled_rounded_rectangle<>(). The 3rd time it begins that loop (which itself is part of a larger loop) it freezes about 5 or so iterations in. Not when it's part of the larger subroutine though.

          To err is human. Fortune favors the monsters.

          J Offline
          J Offline
          jmaida
          wrote on last edited by
          #6

          you may be cheated of memory captured by calling routine. i.e. statics, call stack, ...

          1 Reply Last reply
          0
          • H honey the codewitch

            I wrote a video display driver for an RA8875 display controller. I need it because I use it in one of my commercial projects. Well, it works "fine" (a bit slow, but the controller is slow) except in one demo. I am trying to draw a series of rounded rectangles of random size, random coordinates and random colors. The code is relatively simple and should be innocuous. It also works when it's used as part of a larger routine. But when I simplify the code, remove the big routine, and just run a lines demo followed by the rounded rectangles the whole MCU freezes solid during the 3rd iteration. (Always in the same place but that doesn't matter because even randomization yields the same result boot to boot. There's no real RTC or any sort of non-determinism so freezing in the same spot every time isn't much of a clue in this case). I need to fix this, or at the very least verify it will never happen in my commercial project but I am totally stumped. What a morning.

            To err is human. Fortune favors the monsters.

            A Offline
            A Offline
            Andreas Mertens
            wrote on last edited by
            #7

            A long time ago I got assigned to fix an issue that sounds similar. C code, back in the DOS days. The previous person that worked on it couldn't solve it and jacked up the stack size. This allowed it to run longer, but didn't fix the underlying problem. Turns out it was using calling convention (Pascal? It has been a long time...) so that the called routine would clear the stack and not the caller. And the function signature did not exactly match between the two. As a result, two bytes of the stack were not released. After X-iterations through that routine, it ran out of stack space and crashed. After correcting the function signature, app ran. Could also trim back the stack to a tenth its size... Not sure if any of that helps. But maybe it will trigger some out of the box thinking....

            H 1 Reply Last reply
            0
            • A Andreas Mertens

              A long time ago I got assigned to fix an issue that sounds similar. C code, back in the DOS days. The previous person that worked on it couldn't solve it and jacked up the stack size. This allowed it to run longer, but didn't fix the underlying problem. Turns out it was using calling convention (Pascal? It has been a long time...) so that the called routine would clear the stack and not the caller. And the function signature did not exactly match between the two. As a result, two bytes of the stack were not released. After X-iterations through that routine, it ran out of stack space and crashed. After correcting the function signature, app ran. Could also trim back the stack to a tenth its size... Not sure if any of that helps. But maybe it will trigger some out of the box thinking....

              H Offline
              H Offline
              honey the codewitch
              wrote on last edited by
              #8

              I wish it was a stack leak issue. It's not too hard to track those down once you identify them. But yeah, thanks. The ESP32 will notify you if it reboots due to stack overflow vs. something else, so that's helpful. It doesn't freeze though. Or at least, it shouldn't. Arduino disables the watchdog timer I think, but if it didn't, this would be causing a reboot.

              To err is human. Fortune favors the monsters.

              A 1 Reply Last reply
              0
              • H honey the codewitch

                I wish it was a stack leak issue. It's not too hard to track those down once you identify them. But yeah, thanks. The ESP32 will notify you if it reboots due to stack overflow vs. something else, so that's helpful. It doesn't freeze though. Or at least, it shouldn't. Arduino disables the watchdog timer I think, but if it didn't, this would be causing a reboot.

                To err is human. Fortune favors the monsters.

                A Offline
                A Offline
                Andreas Mertens
                wrote on last edited by
                #9

                Back in the day when I did deal with this was the early 90's, and the diagnostics weren't as good. The only way I found this issue was to trace through the generated assembler for that code. I actually enjoy a challenging bug hunt, it really gets the creative juices going. And solving a hard one is quite satisfying. I don't do much embedded controller work anymore, or I would offer to look at this with you...

                1 Reply Last reply
                0
                • H honey the codewitch

                  I wrote a video display driver for an RA8875 display controller. I need it because I use it in one of my commercial projects. Well, it works "fine" (a bit slow, but the controller is slow) except in one demo. I am trying to draw a series of rounded rectangles of random size, random coordinates and random colors. The code is relatively simple and should be innocuous. It also works when it's used as part of a larger routine. But when I simplify the code, remove the big routine, and just run a lines demo followed by the rounded rectangles the whole MCU freezes solid during the 3rd iteration. (Always in the same place but that doesn't matter because even randomization yields the same result boot to boot. There's no real RTC or any sort of non-determinism so freezing in the same spot every time isn't much of a clue in this case). I need to fix this, or at the very least verify it will never happen in my commercial project but I am totally stumped. What a morning.

                  To err is human. Fortune favors the monsters.

                  E Offline
                  E Offline
                  englebart
                  wrote on last edited by
                  #10

                  Does it happen with straight rectangles? At the same spot? What happens if you add a fixed offset to each rounded or straight rect? What happens if you change the seed for the pseudo random generator? How is the corner rounding calculated? Try to round only one corner of each rect. Which corner blows? See previous. This might be useful as a primitive. Roundedrectwithcornerfkags

                  H 1 Reply Last reply
                  0
                  • E englebart

                    Does it happen with straight rectangles? At the same spot? What happens if you add a fixed offset to each rounded or straight rect? What happens if you change the seed for the pseudo random generator? How is the corner rounding calculated? Try to round only one corner of each rect. Which corner blows? See previous. This might be useful as a primitive. Roundedrectwithcornerfkags

                    H Offline
                    H Offline
                    honey the codewitch
                    wrote on last edited by
                    #11

                    It doesn't stall with any other driver. The rounded rect code has nothing to do with the driver, which is completely decoupled from it. I will try changing the seed, but i'm not sure what it will tell me if the problem changes with it.

                    To err is human. Fortune favors the monsters.

                    E 1 Reply Last reply
                    0
                    • H honey the codewitch

                      It doesn't stall with any other driver. The rounded rect code has nothing to do with the driver, which is completely decoupled from it. I will try changing the seed, but i'm not sure what it will tell me if the problem changes with it.

                      To err is human. Fortune favors the monsters.

                      E Offline
                      E Offline
                      englebart
                      wrote on last edited by
                      #12

                      I am thinking there is an issue/edge in underlying trigonometry code that is calculating the rounded corners. Changing the seed might work without issue or blow up on a different iteration. It would help point to an edge case. Also, is it possible that it is blowing on the first pixel of the next figure? Have you tried displaying rounded rects starting at 1 pixel and increasing 1 pixel per iteration? Did random kick out a negative due to sign issues?

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups