Stack Over flow exception for long code in picture box paint.

Hany Metry 41 Reputation points
2022-09-12T09:49:08.773+00:00

240072-problem.pngHi

I have a long code in picture paint of picture box, so when I run the application, I got a message Stack Over flow exception as per attached photo.

How I can divide the code into two or more subroutine.

The code manly is drawings with many conditions.

The code is in VB.net

Regards,

.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,119 questions
{count} votes

5 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,686 Reputation points
    2022-09-12T22:01:31.99+00:00

    The problem is your code is recursing. you will need to fix the bug. breaking it up will not help. looking at the stack trace should help find your bug.


  2. Hany Metry 41 Reputation points
    2022-09-13T01:06:21.083+00:00

    Hi,

    The problem happened during load the program and I don't know how to make stack trace.

    0 comments No comments

  3. Bruce (SqlWork.com) 55,686 Reputation points
    2022-09-13T17:12:56.567+00:00

    in your posted vs image, it is the call stack window.


  4. Bruce (SqlWork.com) 55,686 Reputation points
    2022-09-19T15:06:01.177+00:00

    Stackoverflows are not cause by code length. And breaking up the code (which is typically a good idea for readability and maintenance) will have no effect.

    Typically cause is a non terminating recursive call. Review your stack trace.

    0 comments No comments

  5. Hany Metry 41 Reputation points
    2022-09-20T06:41:42.52+00:00

    Hi Bruce

    When I try to divide the picturebox1 paint to additional subroutine by writing the following code in the module

    Friend e As System.Windows.Forms.PaintEventArgs

    Initialization exception happened.

    And when I make my program divided into two programs, my problem is solved and I have not stack over flow exception.

    So stack over flow exception happened because long code in picture box paint.

    Kind Regards,

    Hany Metry

    0 comments No comments