Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 930813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:23:56+00:00 2026-05-15T20:23:56+00:00

I am creating a factory that makes rooms, and it is passed an int

  • 0

I am creating a factory that makes rooms, and it is passed an int of steps and a start room and it is supposed to do a step, build a room, and then call itself with one fewer step and the new room as the start room. The problem is that it never ends. In the debugger, I can see that it’s calling itself, which creates another method call in memory that actually has one fewer step, but then the execution line goes to the top of the current method call! so it never actually completes the new call. As though it were putting the new call into heap instead of stack, and then never actually getting to it.

Code:

@Override
public Room place(Level level, int cycles, Room start_room,
        Direction direction, int shop, int exit, LevelFactoryReport report) throws Exception
{


    Room room = null;
    if(cycles < 1)
    {
        return start_room;
    }
    else
    {
        report.addEvent("--Placer step--");
        report.addEvent("Steps remaining: "+cycles);
        room = this.Step(level, start_room, direction, shop, exit, report);
        if(room == null)
        {
            cycles = 0;
            report.addEvent("Step returned a null room (probably because it ran into an existing room). Ending cycle.");
        }
    }
    return place(level, (cycles--), room, direction, (shop--), (exit--), report);
}

In the code above, it goes through the various implementation, then gets to the new call for place(), and then it just creates a new instance of place(), but doesn’t step into it, and instead the execution line goes back to “Room room = start_room” of the original call. It does this infinitely, with the cycles always at its initial value of 4, and more and more instances of place() filling up the stack. I looked into the new instances, and all of them actually do have a “cycles” value of 3.

The strange thing is, each iteration that actually runs is being run on the next room, so when it goes back to the top, it is going back to the top passing the next room. But why is it creating a new instance of place() (with the new room AND the new cycles value of 3), and then re-running the old place() using the new room BUT NOT the new cycles value of 3?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:23:57+00:00Added an answer on May 15, 2026 at 8:23 pm

    You’re using cycles--, shop-- to decrement the variables. However while x-- does decrement x, it does not return the decremented value. The return value of the expression x-- is the old value of x. Use x-1 instead of x--. (Or --x if you must, but there is no point in mutating the variable here).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a factory that is supposed to create objects that inherit from class
I am creating a factory which uses a delegate to call a static method
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'PNLResultDAOImpl' defined in file [C:\EclipseWS1\SpringJDBCExample\target\classes\com\synechron\tom\pnl\dao\impl\PNLResultDAOImpl.class]: Instantiation of bean
I'm using the Ninject Factory Extension and creating a custom instance provider explained in
I'm trying to register a factory method for creating instances of an open generic
Is this possible? I am creating a single base factory function to drive factories
Does anybody recognize this error? org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory': Post-processing of
I'm having the following issue with my hibernate 3.6.10 project: org.springframework.beans.factory.BeanCreationException: Error creating bean
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
We are creating a small application that will be deployed to very limited machines.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.