Jump to content
  • Advertisement
Sign in to follow this  

size of 0 after queue insertion?

This topic is 3008 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a std queue. For some reason, the size is occasionally 0 after calling push. How is this possible? For some reason the assertion in the UserInputQueue::PushbackTick function is failing. mybuffer has a size of 0 after push is called.
#pragma once
#include <queue>
#include "BOOST/shared_ptr.hpp"

struct TickInput
    int xmove;
    bool jump;
    bool shoot;
    bool suicide;

    void Reset();

class UserInputQueue
    std::queue<TickInput> mybuffer;
    TickInput currenttick;

    unsigned int left,right,jump;

    void ChangeKeyCount(unsigned int& count, bool down);


    bool Empty() const;
    const TickInput& GetInput() const;
    void PopTick();

    void Shoot();
    void Suicide();
    void Jump(bool down);
    void KeyLeft(bool down);
    void KeyRight(bool down);

    void PushbackTick();
    void PushbackTickCopy(const TickInput& newtick);

#include "inputstreams.h"
#include "utilityheaders/debug.h"

TickInput::TickInput(): xmove(0), jump(false), shoot(false), suicide(false) {}
void TickInput::Reset() {xmove=0;jump=false;shoot=false; suicide=false;}

void UserInputQueue::ChangeKeyCount(unsigned int& count, bool down)

UserInputQueue::UserInputQueue():left(0),right(0), jump(0) {}

bool UserInputQueue::Empty() const {return mybuffer.empty();}
const TickInput& UserInputQueue::GetInput() const {assert(!Empty()); return mybuffer.front();}
void UserInputQueue::PopTick() {mybuffer.pop();}

void UserInputQueue::Shoot() {currenttick.shoot=true;}
void UserInputQueue::Suicide() {currenttick.suicide=true;}

void UserInputQueue::Jump(bool down) {ChangeKeyCount(jump, down);}
void UserInputQueue::KeyLeft(bool down) {ChangeKeyCount(left, down);}
void UserInputQueue::KeyRight(bool down) {ChangeKeyCount(right, down);}

void UserInputQueue::PushbackTick()
    if(left) {--currenttick.xmove;}
    if(right) {++currenttick.xmove;}
    if(jump) {currenttick.jump = true;}

void UserInputQueue::PushbackTickCopy(const TickInput& newtick)

Share this post

Link to post
Share on other sites
Nevermind, I figured out the problem. I accidentally called Pop when it was already empty. Rather then causing an error, this somehow made the size become negative.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!