Ok I feel dumb

Started by
4 comments, last by writh 17 years, 10 months ago
I’m sorry if I am posting this in the wrong section but this I thought bust suited my question. So here it goes. I’m getting an error on this piece of code that I just don’t understand. #include <vector> std::vector<tChapter> g_Chapter; int g_iCurrChapter = 0; int main (){ tChapter firstChapter = {0}; g_Chapter.push_back(firstChapter); g_Chapter[g_iCurrChapter].NumObjs = 0; //<- what’s wrong } It compiles and runs but once it executes the line “g_Chapter[g_iCurrChapter].NumObjs = 0;” is causes a break and for the life of me I cant seem to figure it out.
Peace Code & Coffee :)
Advertisement
What does your tChapter class/struct look like?

You only have a few points of failure there:

* g_iCurrChapter is somehow larger than your vector. Perhaps you are ending up with a value other than 0 in it? Perhaps you are running out of memory, and the push_back is failing? Perhaps an exception is getting thrown?

* Perhaps NumObjs is a complex object that has problems with assignment to 0?

A side note, but what are you trying to do with your tChapter, when you initialize it to 0?
Post the tChapter class if you can. The only way I can see that this would be caused is if g_iCurrChapter is modified elsewhere before that line occurs (eg. in the tChapter constructor). This is under the assumption that NumObjs's type is just a built-in (like int) and that your system isn't so overloaded that your running out of memory.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
I’m sorry I can’t give you all of my code but I can give you a sample of what I am trying to do. Long story short this is part of my game tools. This is an over glorified map editor. Each level is stored as a chapter and there are X number of objects in the chapter. As shown below



class tPdxObjs{
public:
int ObjType; // Object type
int ObjRef; // refrence Number for object
char strObjName[50]; // a string name of this object
char strFileName[50]; // the file name if there is one
tMaterialInfo Material; //<-- just basic struct
int customTypeIndex;
unsigned int m_texture;

void Init()
{
m_texture = -1;
vScale.m_x = 1;
vScale.m_y = 1;
vScale.m_z = 1;
sprintf(Material.strFile,"%s","Unused");
Material.fColor[0] = 0.5f;
Material.fColor[1] = 0.5f;
Material.fColor[2] = 0.5f;
selected = FALSE;
}
};

class tChapter{

public:
std::vector<tPdxObjs> pdxObj;
int NumObjs;

};

// in my game lib
int g_iCurrChapter = 0;
std::vector<tChapter> g_LuaChapter;

// in the actual app
std::vector<tChapter> g_Chapter;


Now my problem happens not when I’m using g_LuaChapter or g_Chapter the problem happens when I’m trying to get one to be the same as the other such as

swap ( g_Chapter[g_iCurrChapter].pdxObj, g_LuaChapter[g_iCurrChapter].pdxObj); the g_LuaChapter is comming from a dll and g_Chapter is in an MFC applacation the error givein is second assertion failed or subscript out of range. Any help would be aprishated ty.
Peace Code & Coffee :)
Different STL libraies? If the lib is built with using an older version or different version of the STL libary than the app, you can't exchange their data with a swap like that, it would proablly result in some memory overrunn. The only sure way to build with the same STL libraries is to explictly set the stl paths yourself for both the app and the lib.

Good Luck!

-ddn
cool ty when i have some time ill look into it i have a direction now i just could not see a problem in the code
Peace Code & Coffee :)

This topic is closed to new replies.

Advertisement