Click here to Skip to main content
15,896,453 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: CWinFormsControl Problem Pin
Aamir Butt28-May-06 19:27
Aamir Butt28-May-06 19:27 
QuestionMFC ActiveX Pin
satsumatable24-May-06 20:25
satsumatable24-May-06 20:25 
AnswerRe: MFC ActiveX [modified] Pin
Nish Nishant25-May-06 9:31
sitebuilderNish Nishant25-May-06 9:31 
Questionclient /server application Pin
vaninathan24-May-06 17:03
vaninathan24-May-06 17:03 
AnswerRe: client /server application Pin
Nish Nishant25-May-06 9:33
sitebuilderNish Nishant25-May-06 9:33 
QuestionNeed to click menu twice to activate in an MDI application Pin
zenzero24-May-06 11:03
zenzero24-May-06 11:03 
AnswerRe: Need to click menu twice to activate in an MDI application Pin
zenzero29-May-06 13:51
zenzero29-May-06 13:51 
Questioninexplicable System.NullReferenceException when using stl vector Pin
razilon23-May-06 20:33
razilon23-May-06 20:33 
Hi,

I've written a managed class that makes use of stl vectors of a few unmanaged structs for data handling/manipulation, but I'm getting a few very strange errors. I get an "Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object" occasionally when adding a new element to a vector. By occasionally I mean that the exact same code works fine most of the time, throwing the error around 1% of the time. Based on sample data that I'm feeding the program, the errors occur on the exact same data every execution, but I don't see anything wrong with the offending data or the code. Can someone help? Even if you only have a vague idea of something I can look into, please let me know.

Here's the relevant code snippet:

// if a headline occurs after a normal paragraph, split the block there
for (int i = thisDoc->blocks.size() - 1; i >= 0; i--)
{
block* curBlock = &thisDoc->blocks[i];
if (curBlock->type == blockType::text)
{
// search through all the paragraphs (from end to start)
bool lastWasHeadline = false;
for (int j = curBlock->paragraphs.size() - 1; j >= 0; j--)
{
// is this paragraph a headline?
if (curBlock->paragraphs[j].type == paragraphType::headline)
lastWasHeadline = true;
else
{
// did we just leave a headline?
if (lastWasHeadline)
{
// split the remainder of the block into a new block
block newBlock;
newBlock.type = blockType::text;
for (int k = curBlock->paragraphs.size() - 1; k > j; k--)
{
newBlock.paragraphs.insert(newBlock.paragraphs.begin(), curBlock->paragraphs[k]);
curBlock->removeParagraph(k);
}
//!!!!!!!!!!!!!!!!!!ERROR!!!!!!!!!!!!!!!!!!
//Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
thisDoc->addBlock(newBlock);
//!!!!!!!!!!!!!!!!!!ERROR!!!!!!!!!!!!!!!!!!
}
lastWasHeadline = false;
}
}
}
}


From the class header (to show you what my struct declarations look like):

__nogc struct block
{
rectangle bounds;
rectangle adjacent;
rectangle gutterDist;
int type;
vector<paragraph> paragraphs;

block()
{
bounds.left = bounds.right = bounds.top = bounds.bottom = 0;
adjacent.left = adjacent.right = adjacent.top = adjacent.bottom = -1;
gutterDist.left = gutterDist.right = gutterDist.top = gutterDist.bottom = 2147483647;
type = blockType::undecided;
paragraphs.clear();
}

~block() {paragraphs.clear();}

void addParagraph(paragraph newParagraph)
{
// if this is the first line to be added to the paragraph
if (paragraphs.size() == 0)
{
bounds.left = newParagraph.bounds.left;
bounds.right = newParagraph.bounds.right;
bounds.top = newParagraph.bounds.top;
bounds.bottom = newParagraph.bounds.bottom;
}
else
{
if (newParagraph.bounds.left < bounds.left)
bounds.left = newParagraph.bounds.left;
if (newParagraph.bounds.right > bounds.right)
bounds.right = newParagraph.bounds.right;
if (newParagraph.bounds.top < bounds.top)
bounds.top = newParagraph.bounds.top;
if (newParagraph.bounds.bottom > bounds.bottom)
bounds.bottom = newParagraph.bounds.bottom;
}
paragraphs.push_back(newParagraph);
}

void removeParagraph(int index)
{
paragraphs.erase(paragraphs.begin() + index);
}
};

__nogc struct page
{
int width, height, resolution;
vector<block> blocks;
double avgLineHeight; // calculated in reFormat(...)

page()
{
width = height = resolution = 0;
blocks.clear();
}

~page() {blocks.clear();}

void addBlock(block newBlock) {blocks.push_back(newBlock);}

void removeBlock(int index)
{
blocks.erase(blocks.begin() + index);
}
};

// all necessary internal variables
page __nogc* thisDoc;
QuestionError Code: C2039 Pin
satsumatable23-May-06 18:27
satsumatable23-May-06 18:27 
AnswerRe: Error Code: C2039 Pin
Cedric Moonen23-May-06 21:11
Cedric Moonen23-May-06 21:11 
QuestionCompiling error for Clipboard.SetDataObject(). Pin
robert tian guo23-May-06 4:47
robert tian guo23-May-06 4:47 
AnswerRe: Compiling error for Clipboard.SetDataObject(). [modified] Pin
George L. Jackson23-May-06 9:34
George L. Jackson23-May-06 9:34 
GeneralRe: Compiling error for Clipboard.SetDataObject(). [modified] Pin
robert tian guo23-May-06 14:32
robert tian guo23-May-06 14:32 
GeneralRe: Compiling error for Clipboard.SetDataObject(). [modified] Pin
George L. Jackson24-May-06 3:15
George L. Jackson24-May-06 3:15 
QuestionHow Can I play the music on my game Pin
Squallkin8423-May-06 4:08
Squallkin8423-May-06 4:08 
QuestionProto type mismatch Pin
satsumatable22-May-06 23:57
satsumatable22-May-06 23:57 
QuestionReading memory Pin
satsumatable22-May-06 17:32
satsumatable22-May-06 17:32 
QuestionCreating new managedObject[100] in C++ Pin
StevenS_Dev22-May-06 12:35
StevenS_Dev22-May-06 12:35 
AnswerRe: Creating new managedObject[100] in C++ Pin
George L. Jackson23-May-06 2:01
George L. Jackson23-May-06 2:01 
GeneralRe: Creating new managedObject[100] in C++ Pin
StevenS_Dev23-May-06 7:38
StevenS_Dev23-May-06 7:38 
QuestionOverriding void Dispose(bool disposing) in C++/CLI? Pin
Filip Strugar20-May-06 14:37
Filip Strugar20-May-06 14:37 
AnswerRe: Overriding void Dispose(bool disposing) in C++/CLI? [modified] Pin
George L. Jackson20-May-06 15:44
George L. Jackson20-May-06 15:44 
AnswerRe: Overriding void Dispose(bool disposing) in C++/CLI? Pin
Dave Doknjas20-May-06 19:25
Dave Doknjas20-May-06 19:25 
GeneralRe: Overriding void Dispose(bool disposing) in C++/CLI? Pin
Filip Strugar22-May-06 22:34
Filip Strugar22-May-06 22:34 
GeneralRe: Overriding void Dispose(bool disposing) in C++/CLI? Pin
George L. Jackson23-May-06 1:57
George L. Jackson23-May-06 1:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.