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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:48:50+00:00 2026-06-07T19:48:50+00:00

I have got this Runtime Error when running this code: void AlienShipManager::Update(float timeDelta, BulletManager*

  • 0

I have got this Runtime Error when running this code:

void AlienShipManager::Update(float timeDelta, 
        BulletManager* bulletManager,
        ParticleManager* particleManager,
        GameStringSystem* stringBatch)
{
    unsigned int i = 0;
    while (i < m_alienShipList.size())
    {
        AlienResult result = m_alienShipList[i].Update(timeDelta, bulletManager);
        switch (result)
        {
            case AlienResult::Dead:
                break;
            default:
                break;
        }
            ++i 
    }
}

in line

AlienResult result = m_alienShipList[i].Update(timeDelta, bulletManager);

There is how I add AlienShip to vector class:

m_alienShipList.push_back(AlienShip(position, speed, m_screeSize, m_alienShipTexture));

error also appers if I chance that to:

AlienShip* newAlien = new AlienShip(position, speed, m_screeSize, m_alienShipTexture);
    m_alienShipList.push_back(*newAlien);
    delete newAlien;

but does not appear if I change that to:

AlienShip* newAlien = new AlienShip(position, speed, m_screeSize, m_alienShipTexture);
    m_alienShipList.push_back(*newAlien);

which hence lead to huge memory leaks.

This is how looks my AlienShip class:

#pragma once

#include "Body.h"
#include "BulletManager.h"
#include "ParticleManager.h"

enum AliensShipState
{
    flying,
    dying,
    dead,
    escaped
};

enum AlienResult
{
    No,
    Hit,
    Dying,
    Dead,
    Escaped
};

class AlienShip : public Body
{
public:
    AlienShip(void);
    AlienShip(float2& position, float2& speed, float2* screenSize, ID3D11Texture2D* alienTexture);
    ~AlienShip(void);

    AlienResult Update(float timeDelta, BulletManager* bulletManager);
    void Draw(BasicSprites::SpriteBatch^ spriteBatch);

protected:
    float m_baseY;
    AliensShipState m_state;
    float2* m_screenSize;
};

AlienShip class is inherited from Body class, which has Sprite class inside it, which has another vector inside it.
But since Sprite class is working perfectly elsewhere, I don’t think it is source of error.

I wonder why this happens, because I can’t find the relationship between deleting temporary object and corrupting vector iterator, If it corrupted at all.

Also program compiles and runs in Release, but with some data corruption.

I am using Visual Studio 2012 Beta for Windows 8.

Please write if you need more source code.
Unfortunately it is very hard to post all code, as this is complex program.

  • 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-06-07T19:48:51+00:00Added an answer on June 7, 2026 at 7:48 pm

    Given that it doesn’t work when you add the item to the vector by value but it does when you leak a pointer, I have 95% confidence that your copy constructor for AlienShip does a shallow copy, causing your problems.

    EDIT: Note that m_alienShipList.push_back(AlienShip(position, speed, m_screeSize, m_alienShipTexture)); causes a copy of your class and if the copy constructor doesn’t work right it will cause problems later.

    In fact if the AlienShip definition you’ve pasted is correct there is in fact only the default copy constructor which likely does the wrong thing (further reinforced by the fact that you have your own destructor).

    Either implement a copy constructor that does a deep copy, or more preferably rewrite your class to use RAII to manage the memory for you so that the default copy is correct.

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

Sidebar

Related Questions

I have got this code: function init(){ if (typeof window.jQuery !== 'function') { var
I have got this code: $subject=<<<EOD <object height=400 width=500><param name=allowfullscreen value=false> <param name=AllowScriptAccess value=always>
I have got this code for detection of mobile device. <?xml version=1.0 encoding=UTF-8?> <configuration>
I have got this code: XDocument xdoc = XDocument.Load(URI); XElement root = xdoc.Element(forecast); //get
I have got this code and I am trying to understand the convention followed,
I have got this text file with latitude and longitude values of different points
I have got this regex pattern that works with my current apache log format:
I have got this result with the answer given by bluefeet Equipt BSL AQ
I have got this html: <div id=myDiv> <p class=readMore></p> <p class=readMore></p> <p class=readMore></p> </div>
I have got this css: <style type=text/css> #heading{ margin:auto; background-color: brown; } </style> and

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.