使用difftime()时出现未处理的异常

时间:2013-06-20 10:05:53

标签: c++ unhandled-exception

我正在创建一个程序,用于从XML文件中读取有关烟花的数据(例如类型,颜色,启动时间(以毫秒为单位)以及持续时间等等。然后,它会循环显示使用openGL的烟花汇演。

我的方法是拥有一个管理器类,它接收xml读取烟花的向量并在3个不同的向量之间移动它们:inactiveFireworks(那些尚未触发的),activeFireworks(需要动画的那些) )和耗尽的防火墙(在显示器运行时将被推回到inactiveFireworks的那些)。

要检查是否需要触发烟火,我需要计算烟花管理器被调用的时间与程序的当前时间之间的差异,并将其乘以1000以获得毫秒。

例如:如果烟火是在3000点发生火灾,那么消防工作经理将会被召唤3秒钟。

不幸的是,此时我收到了一个未处理的异常错误,我不确定为什么......

timeDifference = difftime(time(&currentTime),initTime) * 1000;

这是头文件:

#ifndef FWORKMANAGER_H
#define FWORKMANAGER_H

#include <Time.h>
#include <vector>
#include "firework.h"

class fworkManager
{
private:
    time_t initTime;
    time_t currentTime;
    double timeDifference;

    std::vector<firework*> inactiveFireworks; 
    std::vector<firework*> activeFireworks; 
    std::vector<firework*> depletedFireworks; 

public:
    fworkManager(std::vector<firework*> fListIn);
    void drawAllFireworks();

    void evolve();
    void fireInactiveFireworks();
    void moveActiveFireworks();
    void moveDepletedFireworks();
    void reset();   
};

#endif

这是CPP。

#include <vector>
#include "LUtil.h"
#include "fworkManager.h"

fworkManager :: fworkManager(std::vector<firework*> fListIn){
    inactiveFireworks = fListIn;
    time (&initTime);
}

//animates fireworks
void fworkManager::evolve(){
    //check time against inactiveFireworks

    fireInactiveFireworks();
    moveActiveFireworks();
    moveDepletedFireworks();
    reset();
}

//draws fireworks as they come up
void fworkManager::drawAllFireworks()
{
    std::vector<firework*>::iterator i;

    for(i=activeFireworks.begin(); i != activeFireworks.end(); i ++)
    {
        (*i) -> draw();
    }
}

//if fireworks are ready to fire, push them to active list
void fworkManager::fireInactiveFireworks()
{
    timeDifference = difftime(time(&currentTime),initTime) * 1000;
    std::vector<firework*>::iterator i;

    for(i = inactiveFireworks.begin(); i != inactiveFireworks.end();)
    {
        if((*i) -> getBegin() <= timeDifference)
        {
            activeFireworks.push_back(*i);
            (*i) -> explode();
            i = inactiveFireworks.erase(i);
        }else{
            ++i;
        }
    }
}

//animate each firework in the active list
void fworkManager::moveActiveFireworks()
{
    std::vector<firework*>::iterator i;
        for(i = activeFireworks.begin(); i != activeFireworks.end(); i++)
    {
        (*i) -> evolve();
    }
}

//move fireworks that have met their duration requirement to the depleted list.
void fworkManager::moveDepletedFireworks()
{
        std::vector<firework*>::iterator i;
    for(i = activeFireworks.begin(); i != activeFireworks.end();)
    {
        if((*i) -> getLifeSpan() >= (*i) -> getDuration()  )
        {
            depletedFireworks.push_back(*i);

            i = activeFireworks.erase(i);
        }else{
            ++i;
        }
    }
}

//repopulates the inactive firework list and resets the time difference. Allows animation to loop.
void fworkManager::reset()
{
    if(inactiveFireworks.empty() && activeFireworks.empty())
    {
        time (&initTime);
        std::vector<firework*>::iterator i;
        for(i=depletedFireworks.begin(); i != depletedFireworks.end();)
        {
            (*i) -> reset();
            inactiveFireworks.push_back(*i);
            i = depletedFireworks.erase(i);

        }

    }
}

非常感谢您提供的任何见解。

0 个答案:

没有答案