r/ProgrammerHumor • • Jun 16 '21

Maximum call stack size exceeded

Post image
20.2k Upvotes

225 comments sorted by

300

u/mqduck Jun 16 '21

I'd just like to point out that this meme only recurses five times.

2

u/ElectricOstrich57 Jun 16 '21

Didn’t think anyone would look that closely, haha

→ More replies (1)

44

u/AlexSin0 Jun 16 '21

Stack Overflow

22

u/jedimaster1138 Jun 16 '21

22

u/[deleted] Jun 16 '21

You go through that effort, only to save it as a low-quality JPEG, the compression of which obliterates any real detail in the smaller recursions?

Why? Are you the self-sabotaging sort of person that says they are going to go to bed early and get a good night's sleep, only to browse Reddit and Youtube until 2am in the morning and wonder why it's so hard to get out of bed in the morning?

→ More replies (2)

9

u/Synthrea Jun 16 '21

Did you try setting a larger stack limit?

7

u/i-FF0000dit Jun 16 '21

The stack limit would cause a crash, but this recursion actually ends. I guess the answer to her question is yes.

→ More replies (2)

3

u/[deleted] Jun 16 '21

There's actually a base case as well!

3

u/cowlinator Jun 16 '21

So there in fact was a base case

2

u/i-FF0000dit Jun 16 '21

This should be the top comment.

0

u/[deleted] Jun 16 '21

[deleted]

43

u/i-FF0000dit Jun 16 '21

I can’t believe I almost fell for that.

14

u/Mnawab Jun 16 '21

I can't believe I fell for that

45

u/[deleted] Jun 16 '21

Made me laugh lol

15

u/spikederailed Jun 16 '21

Expected, still got a good chuckle. Have your updoot.

→ More replies (1)
→ More replies (9)

860

u/jegueverde Jun 16 '21

I hope that you, like any other programmer, spent several hours writing an image manipulation app to do this recursively instead of doing it in 5 minutes by hand. And your reasoning for it is to "save time"

410

u/kris159 Jun 16 '21

Sadly they didn't, you can see 6 layers deep that the very bottom right panel is Padme's full face, the same size as the panel above it

291

u/chhuang Jun 16 '21

This is outrageous

84

u/FututiRedesignuMatii Jun 16 '21

Dissapointing, it could've been resized & pasted a few more times to the point where it was a few pixels and not noticeable anymore.

113

u/HearingNo8617 Jun 16 '21

plot twist: there is a base case and it was hit

51

u/Pit_27 Jun 16 '21

Base case was op giving up

→ More replies (4)

5

u/[deleted] Jun 16 '21

this was the base case.

3

u/Jadien Jun 16 '21

Padme was the base case all along

→ More replies (4)

26

u/B0n3 Jun 16 '21

Save time. For the next time

19

u/[deleted] Jun 16 '21

Shit. I hard coded the image dimensions in there, it doesn't work with this new format.....I'll just go in here and change this one line....aaaand...

81

u/returnFutureVoid Jun 16 '21

This is the way.

41

u/TheDroidNextDoor Jun 16 '21

This Is The Way Leaderboard

1. u/Flat-Yogurtcloset293 475775 times.

2. u/_RryanT 22744 times.

3. u/max-the-dogo 8489 times.

..

165279. u/returnFutureVoid 1 times.


beep boop I am a bot and this action was performed ^automatically.

→ More replies (9)

11

u/eisaletterandanumber Jun 16 '21

Install ImageMagick then run the following for each iteration:

convert img.png \( +clone -resize 50% -gravity SouthEast \) -composite img.png

5

u/Prince705 Jun 16 '21

With a base case, right?

4

u/Homoshrexual234 Jun 16 '21

You could do this pretty quick with python and pillow.

3

u/20_chickenNuggets Jun 16 '21

Otherwise I would lose my respect for OP

4

u/Wime36 Jun 16 '21

If it isn't automatically repeating down to the bottom right 4 pixels then it's wrong

→ More replies (2)

835

u/[deleted] Jun 16 '21

Finally someone gets recursion right with this meme.

263

u/Wime36 Jun 16 '21

Finally someone gets recursion right with this comment.

164

u/Adam_Kearn Jun 16 '21

I’ve been clicking this link for over and hour and still can’t find what comment you are talking about.

62

u/ZippZappZippty Jun 16 '21

We’ve won this by a mile.

11

u/[deleted] Jun 16 '21

Salute

3

u/[deleted] Jun 16 '21

Ever noticed that the last part of the link spells out hydra if you omit the numbers?

→ More replies (3)

240

u/architkhandelwal47 Jun 16 '21

Finally someone gets recursion right with this meme.

162

u/[deleted] Jun 16 '21

Finally someone gets recursion right with this meme.

→ More replies (16)

2

u/Royal-Tough4851 Jun 16 '21

Ah, programmer humor. Love it

2

u/SupersonicSpitfire Jun 16 '21

Finally someone gets recursion right with this

-18

u/grimonce Jun 16 '21

Ironic, because it doesn't...

20

u/ErikBjare Jun 16 '21

lol at the people downvoting this.

If you look closely at the image you can clearly see the base case.

4

u/beardedchimp Jun 16 '21

Maximum call size stack exceeded, the image was written to continuously and stopped at segfault. Segfault is my base case.

→ More replies (1)

707

u/Hk-Neowizard Jun 16 '21

Finally, someone does something new with this overused meme.

Take an upvote

57

u/Brick_Double Jun 16 '21

Same, one of the few to get a laugh out of me.

13

u/Republikanen Jun 16 '21

4

u/sneakpeekbot Jun 16 '21

Here's a sneak peek of /r/mathmemes using the top posts of the year!

#1: Just to be sure! | 106 comments
#2: It's a struggle | 62 comments
#3: correlation | 125 comments


I'm a bot, beep boop | Downvote to remove | Contact ^^me | ^^Info | ^^Opt-out

3

u/Hk-Neowizard Jun 16 '21

I absolutely love it. Thank you

2

u/ReimarPB Jun 16 '21

This is not really new though, I've seen this kind of meme in a million other formats

0

u/[deleted] Jun 16 '21

[deleted]

90

u/[deleted] Jun 16 '21

Finally, someone does something new with this overused meme.

Take an upvote

41

u/ultramarineafterglow Jun 16 '21

Finally, someone does something new with this overused meme.

Take an upvote

→ More replies (6)
→ More replies (7)
→ More replies (3)

30

u/GroundTeaLeaves Jun 16 '21

What is a base case?

56

u/TheHackPete Jun 16 '21 edited Jun 16 '21

(The) One case you know the answer for.

The other cases recurse toward the base case. This way, the calculation can stop.

e.g. you know the Fibonacci number of 0 and 1. Every other is the sum of the two predecessors. So fib(3) is fib(2)+fib(1); whith fib(2) being fib(1)+fib(0) and fib(1) and fib(0) being known --> the "base case(s)".

→ More replies (2)

16

u/CookieSpoder Jun 16 '21
public static long sumOfDigits(long n) {
    if (n==0) {
        return 0;
    } else {
        return n % 10 + sumOfDigits(n/10);
    }
}

The base case returns 0, like the other comment said, this is where the recursion ends. The base case is a final state that you know will inevitably happen. This method here sums the digits in a given number, ie 1 2 3 = 6. Any number less than 10 when divided by 10 will return 0. This lets the function know that it has reached the last digit, and the recursion ends.

5

u/cowlinator Jun 16 '21

When you know what recursion is, but you don't know what a base case is, your only option is stack overflow

2

u/[deleted] Jun 16 '21

Only option AND actual exception you’ll encounter

2

u/SonicSubculture Jun 16 '21

You could call it a… first order response

→ More replies (1)

21

u/vavavoomvoom9 Jun 16 '21

Nice

26

u/ifuckinglovetesla Jun 16 '21 edited Jun 16 '21

‘’’

Nice(job)
{
     Nice(job);
}

‘’’

3

u/Slim_Bun Jun 16 '21

‘’’

def Nice(job):
     Nice(job)

‘’’

4

u/Kaynee490 Jun 16 '21 edited Jun 16 '21

void Nice(Job job) { Nice(job); }

12

u/__bichael__ Jun 16 '21

Missing semikolon in line 0.

→ More replies (2)
→ More replies (1)
→ More replies (2)

14

u/dvof Jun 16 '21

tail recursion: pathetic

3

u/grandoz039 Jun 16 '21

Isn't that the best kind? That gets automatically optimized (well, I guess depending on language/compiler)?

4

u/CrackerJackKittyCat Jun 16 '21

Laughs in python

→ More replies (1)

33

u/Thecakeisalie25 Jun 16 '21

5

u/NikZapp Jun 16 '21

Happy that im not the only one!

9

u/wonkey_monkey Jun 16 '21 edited Jun 16 '21

I was messing around with a compiler to see what optimisers do and I wrote a recursive function that (accidentally) never returned its base case. But because the non-base case was simply to return the result of the next recursion, the optimiser optimised it away entirely.

It was something like

rec_func(int y) {
  if (impossible_thing) return 5;
  return rec_func(y + 1);
}

and the optimiser just turned it into "5". It was never going to return, but if it could have, it would have returned 5, and that was good enough.

It feels like there should be something deep and meaningful about that, but there probably isn't.

6

u/vectrovectro Jun 16 '21

That sounds like a compiler bug to me, or maybe undefined behavior.

2

u/kronicmage Jun 16 '21

Infinite loops are undefined behaviour so this is a valid optimization

2

u/KuntaStillSingle Jun 16 '21

It is undefined in C++, 'forward progress gaurantee"

GCC seems to handle this in the intuitive manner even with -O3 or -Ofast, while clang with -O1 will happily optimize it away. Interestingly clang doesn't tail call optimize til -O2 but still terminates the function with no side effects at -O1.

#include<iostream>

int test_a(int i){
  if(1 == 2) return i;
  return test_a(i);
}

int test_b(int i){
  if(1 == 2) return i;
  std::cout << "";
  return test_b(i);
}

int main(){
  test_a(1); // g++ will stack overflow with -O1 or infinite loop with -O2
  std::cout << "Completed a" << std::endl; //clang++ -O1 will reach this
  test_b(1); //this will stack overflow on clang++ -O1 or infinite loop on -O2
  std::cout << "Completed b" << std::endl;
  return 0;
}
→ More replies (1)

12

u/NikZapp Jun 16 '21

Damn, your maximum call stack size must be 6

3

u/MrWhiteVincent Jun 16 '21

Base case: can't be small than a pixel.

3

u/empereur_sinix Jun 16 '21

We can see it ends the 5th Time.

3

u/Pablo_0_6 Jun 16 '21

A-Ha. 6th one is normal

3

u/[deleted] Jun 16 '21

This meme isn't just stellar. It's......Interstellar.....

I'll see myself out.

3

u/kettu3 Jun 16 '21 edited Jun 16 '21
    if too_small_to_notice_without_zooming_in:
        return picture_of_non_smiling_padme()

2

u/backtickbot Jun 16 '21

Fixed formatting.

Hello, kettu3: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

2

u/try4gain Jun 16 '21

me tonight..

2

u/abhi307 Jun 16 '21

core dumped....

2

u/Hodat2k9 Jun 16 '21

There are only 6 recursive lol.

2

u/beewyka819 Jun 16 '21

Wait but it does have a base case, I can see the end of it a few layers down. However my question is: where’s the unwinding? Did the program simply crash at the breakpoint? So many questions… so few answers

2

u/Lip98B Jun 16 '21

StackOverflow

2

u/[deleted] Jun 16 '21

Only six iterations, though. Am disappoint.

2

u/OmegonAlphariusXX Jun 16 '21

Weak, the image only repeats 6 times

1

u/GeO4K Jun 16 '21

mandelbrot is turning in his grave

1

u/ManuGamingYT Jun 16 '21

[Circular *1]

1

u/afterlife71 Jun 16 '21

Or use it to your advantage, I have a friend who broke? The memory management on his laptop so whenever he runs out of memory he runs a recursive haskell script until it takes most of his memory and then kills it so the memory's freed up.

1

u/ChrispyByDefault Jun 16 '21

Oh nooooooooooooo…………

1

u/jakethedumbmistake Jun 16 '21

A wrinkly is never more than that stack

1

u/PotaytoPrograms Jun 16 '21

shoulda put a rick roll at the end

1

u/private256 Jun 16 '21

AKA Stackoverflow

1

u/RoscoMan1 Jun 16 '21

We call it 'gilead'

1

u/PyBind Jun 16 '21

was looking for an other punchline in the pixels came back with tears

1

u/pclouds Jun 16 '21

May tail recursion be with you.

1

u/pastroc Jun 16 '21

This meme is prohibited but take my upvote.

1

u/QuarantineSucksALot Jun 16 '21

I don't make people call me Dr.

1

u/jakethedumbmistake Jun 16 '21

Nursing is a great name! I call dibs!

1

u/simplisticallysimple Jun 16 '21

Just do:

import sys
sys.setrecursionlimit(1000000000)

3

u/kronicmage Jun 16 '21

That's how you get a segfault instead of a RecursionError

1

u/backtickbot Jun 16 '21

Fixed formatting.

Hello, simplisticallysimple: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

1

u/CaptainSpaceBoat Jun 16 '21

I’m not knowledgable enough to know why this is genious, but it is.

1

u/Dwaas_Bjaas Jun 16 '21

The last panel will never exist and it will exist at the same time

1

u/spaceweed27 Jun 16 '21

LDR R1 #00

ADD R1, R1, 1

OUT R1

JMP 0x01

2

u/lennyerik Jun 16 '21 edited Jun 16 '21

That would fix the issue. Unoptimised recursion would look like this:

RECURSIVE:
    LDR R1 #00
    ADD R1, R1, 1
    OUT R1
    CALL RECURSIVE
    RET

That way the stack will overflow eventually. On a modern OS we get our lovely Segmentation Fault (core dumped).

2

u/spaceweed27 Jun 16 '21

Yeah.

Thing is, that my teacher has made his own cpu, and he wrote his own microcode. We just have 2 Registers, ADD, SUB, JMP, STR, LDR, CMP, OUT, STOP as "assembler".

So functions out of x86 Intel assembler would be new to me.

2

u/lennyerik Jun 16 '21

I don't know if you know about the stack / heap model, but modern operating systems structure memory in a way that gives each program an area of memory called the stack. Items can be pushed onto it and popped of the top of it (push / pop instructions), making the stack grow / shrink in size.

The call instruction is fairly simple. It simply pushes the return address or address of the next instruction (basically EIP or whatever your instruction pointer / program counter register is plus the size of the current instruction) onto the stack and then sets the instruction pointer to the address specified by the first parameter. The ret instruction returns from the called function: the return address is popped from the stack and is jumped back to afterwards.

The problem with non-terminating recursive functions is that the stack grows in size indefinitely because more and more return addresses get pushed onto the stack. At some point the operating systems runs out of allocatable memory for your application and voilà, Segmentation fault (core dumped)!

Also, by no means is my posted code valid x86 assembler. I just stole your custom instruction set and added the x86 call instruction. :)

1

u/jakethedumbmistake Jun 16 '21

Nah she’s more than that stack

1

u/jakethedumbmistake Jun 16 '21

they are just kitten, but 10x the size

1

u/M1n3c4rt Jun 16 '21

Extra points for recursion

1

u/DivineChili_ Jun 16 '21

The base case is technically the size of the image. when its 2x2 or less, then it terminate

1

u/[deleted] Jun 16 '21

oofe

1

u/KuntaStillSingle Jun 16 '21

When you don't put a lower bound on your quadtree depth

1

u/[deleted] Jun 16 '21

“I don’t think the system works”

1

u/TheOnlyFallenCookie Jun 16 '21

The base is when the CPU melts

1

u/Risembool Jun 16 '21

Yassss this is gud stuff

1

u/Kazzizle Jun 16 '21

Can we let this meme die?

1

u/Kykobear Jun 16 '21

I just got out of my 8th grade coding class, can someone please help me get this?

1

u/[deleted] Jun 16 '21

Just stick "end" somewhere near the end of the loop...

1

u/ReadABookFriend Jun 16 '21

LOL I love this!

1

u/[deleted] Jun 16 '21

Poor girl, she’ll never get her answer :(

1

u/reevus77 Jun 16 '21

Base case is running out of pixels?

1

u/MingusMingusMingu Jun 17 '21

Can we stop with the stackoverflow memes?

1

u/theuniverseisboring Jun 17 '21

My school actually had us write a recursive function for which we legit had to increase the stack size. It was a function for finding and labeling holes in an image. They were incredibly easy to find, and the stuff we did was totally inapplicable and won't help if we actually needed to do something more advanced.

1

u/pirhana1997 Jun 17 '21

I laughted so hard because I commit this mistake everyday 😢

1

u/lets-talk-graphic Jun 16 '21

I’d give you an award for this but also I’d give you an award for this but also I’d give you an award for this but also I’d give you an award for this but also

1

u/Sceptz Jun 16 '21

Are you saying you made a...
StackOverflow?

-6

u/grimonce Jun 16 '21

All memes about recursion are bad.
They seem to show that recursion takes a fixed amount of memory while in practice it is not the case...
Look at this example, the images of consecutive calls are getting smaller and smaller while in reality they are mostly getting bigger and bigger...
Tldr all memes bad

2

u/FoliumInVentum Jun 16 '21

weapons grade autism

1

u/skippedtoc Jun 16 '21

Why does memory taken by recursive calls have to be bigger?

0

u/[deleted] Jun 16 '21

[deleted]

2

u/_kta_ Jun 16 '21

Operations on a tree data structure is a common use of recursive functions