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 6580969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:05:38+00:00 2026-05-25T16:05:38+00:00

I’m writing an open source project for the Xbox 360, it’s my first time

  • 0

I’m writing an open source project for the Xbox 360, it’s my first time using C++ and I’m obviously doing something (Most likely many things) wrong.

My specific problem at the moment is that I create many instances of a class, passing in a reference to an object in the constructor, and setting a member variable to that object.

Later, when I access these objects, the member variable does not contain the object I assigned to it in the constructor.

Also, these objects have an Update(float x, float y) method, in this method I simply assign the x and y to member variables _x and _y.

When I access these values later, they are garbage.

I’m going to try post the relevant code here, but there may be something I miss, so just in case here is a link to the github project Github – Xenu.

The class I’m referring to is source/GUIApplicationPanel and the instantiating/using of them is in source/GUIManager.

Here is the object I am instantiating many instances of:

GUIApplicationPanel.H

class GUIApplicationPanel {
public:
    GUIApplicationPanel(LibXenonApplication libXenonApplication);
    void update(float x, float y);
    void draw();

private:
    LibXenonApplication application;
    float _x, _y;
};

GUIApplicationPanel.CPP

GUIApplicationPanel::GUIApplicationPanel(LibXenonApplication libXenonApplication) 
{
    application = libXenonApplication;
}

void GUIApplicationPanel::update(float x, float y)
{
    _x = x;
    _y = y;
}

void GUIApplicationPanel::draw()
{
    Draw::DrawColoredRect(_x, _y, 0.3f, 0.3f, ThemeManager::GetPanelColor());
}

And here is the code that creates them:

GUIManager.H

class GUIManager {
public:
    void update(controller_data_s controller);

    void draw();

private:
    /* SNIP SNIP */

    vector<GUIApplicationPanel> *currentPanels;

    vector<GUIApplicationPanel> applicationPanels;
};

GUIManager.C

vector<LibXenonApplication> applications = LibXenonApplicationManager::GetApplications(applicationsPath);

// Create panels for applications
for(vector<LibXenonApplication>::iterator iter = applications.begin(); iter != applications.end(); ++iter) {
     applicationPanels.push_back(GUIApplicationPanel(*iter));
}

Here is the code that updates them:

currentPanels = &applicationPanels;

// Render each screens worth of panels
    for(int currentPass = 0; currentPass < renderPasses; currentPass++) {

        horizontalOffset = currentPass * 1.0f;

        for(int verticalPanel = 0; verticalPanel < verticalPanels; verticalPanel++) {

            for(int horizontalPanel = 0; horizontalPanel < horizontalPanels; horizontalPanel++) {

                // Make sure we haven't exceeded the amount of panels we're drawing...
                if(panelIndex >= currentPanels->size()){break;}

                // Get the panel at the current index
                GUIApplicationPanel currentPanel = currentPanels->at(panelIndex);

                // Calculate its position
                float panelX = horizontalOffset + xStart + (horizontalPanel * panelWidth) + (horizontalPanel * panelGap);
                float panelY = yStart + (verticalPanel * panelHeight) + (verticalPanel * panelGap);

                // Update the panel
                currentPanel.update(panelX, panelY);

                // Move to the next panel...
                panelIndex++;
            }
        }
    }

And lastly here is the code that accesses values on them:

for(vector<GUIApplicationPanel>::iterator iter = currentPanels->begin(); iter != currentPanels->end(); ++iter) {
    iter->draw();
}

To be honest I’m all out of ideas – Acessing the application variable on a panel anywhere other than the constructor results in it being garbage, and likewise with _x and _y (Other than in the update method).

I put some logging in, so a line will be logged in the update method of the panel logging the values of _x and _y after they’ve been set, as well as showing the name of the application (Which comes out blank in the log).

A line will also be logged when the draw method is called showing the current values of _x, _y and application:

Updating  to x -0.70 y 0.40
Updating  to x -0.30 y 0.40
Updating  to x 0.10 y 0.40
Updating  to x 0.50 y 0.40
Updating  to x 0.90 y 0.40
Updating  to x -0.70 y 0.80
Updating  to x -0.30 y 0.80
Updating  to x 0.10 y 0.80
Updating  to x 0.50 y 0.80
Drawing  at x 0.00 y 0.00
Drawing  at x 0.00 y 0.00
Drawing  at x 0.00 y 0.00
Drawing  at x 0.00 y 0.00
Drawing  at x 0.00 y 0.00
Drawing  at x 0.00 y 0.00
Drawing  at x 0.00 y 0.00
Drawing  at x 0.00 y 275577729171396449271808.00
Drawing  at x 0.00 y 0.00
  • 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-25T16:05:39+00:00Added an answer on May 25, 2026 at 4:05 pm

    The problem lies in the way you access the elements in the vector:

    GUIApplicationPanel currentPanel = currentPanels->at(panelIndex);
    

    This obtains a copy of the element, so you set the attributes of the copy, not the item held in the container. Obtain a reference and then you can modify the item in the container..

    EDIT: Based on comment, as you’ve realised std::vector<>::at() return a reference, so what you need to do is change the above to be a reference, i.e.

    GUIApplicationPanel& currentPanel = currentPanels->at(panelIndex);
    

    Now currentPanel refers to the instance of GUIApplicationPanel at the specified index in the container.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am writing an app with both english and french support. The app requests
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload

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.