What's new

"Debug Assertion Failed" Error

mesman00

What's that...?
this is something i have never seen before. everything compiles fine but i get a runtime "Debug Assertion Error" when i try to execute a certain line of code. I have pin-pointed it to the exact line of code, and i have no idea what is causing this. The error is also triggered when i just simply exit the program. What even is a Debug Assertion Error? Anyone?
 

smcd

Active member
assert is a function in C and C++ (and several other languages most likely) that says basically "if this condition isn't met then say so!" (typically used to debug, hence the "debugging" part in the error message) If you can post your code online or in a PM I'd be happy to try and help, it's kind of hard to tell you what's happening without seeing it.
 
OP
mesman00

mesman00

What's that...?
you probably wont understand what this i doing, so i'll explain. i'm using a toolkit that genereates the HTML code to convert a .dcm file (a structured report, don't ask for details), to an html file. here is the code, i have commented where the error occurs.

Code:
void ToHTML::convert()
{
	/*MessageBox(NULL, "Function Not Yet Implemented", "Error", 
		MB_ICONWARNING | MB_OK);*/

	DcmFileFormat fileformat;
	OFCondition status = fileformat.loadFile("test.dcm"); //error occurs do to this line
	
	if (status.good())
	{
		DSRDocument document;
		
		status = document.read(*fileformat.getDataset());
		
		if (status.good())
		{
			status = document.renderHTML(cout);
			
			if (status.bad())
			{
				//cerr << "Error: cannot render SR document (" << status.text() << ")" << endl;
			}
		}
		else
		{
			//cerr << "Error: cannot parse SR document (" << status.text() << ")" << endl;
		}
	} 
	else
	{
		//cerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl;
	}
}

from your def. of what assert does, i'm guessing that it's not finding the test.dcm file in the directory. what do you think?
 
Last edited:

smcd

Active member
Well that didn't help too much since there is no visible assert( in there, it seems this is being done inside the code for either the OFCondition or DcmFileFormat object. Do you have the source for either of those, or a help/reference document? (not asking you to post the code here, but to search through it yourself for "assert") I tried searching online for both "DcmFileFormat" and "OFCondition" but nothing valid was returned, except :
http://www.google.com/search?hl=en&lr=&ie=UTF-8&q=news2mail+OFCondition+C++
click the google cache link and it has the same code as you (basically) for loading a file, but no mention of a debug assertion error. Are you sure the file is local? In visual C++ don't put the file in the /debug/ or /release/ folder, but put it up in the root folder above these folders.
 
OP
mesman00

mesman00

What's that...?
here is the actual function itself.

Code:
OFCondition DcmFileFormat::loadFile(const char *fileName,
                                    const E_TransferSyntax readXfer,
                                    const E_GrpLenEncoding groupLength,
                                    const Uint32 maxReadLength,
                                    OFBool isDataset)
{
    if (isDataset)
        return getDataset()->loadFile(fileName, readXfer, groupLength, maxReadLength);

    OFCondition l_error = EC_IllegalParameter;
    /* check parameters first */
    if ((fileName != NULL) && (strlen(fileName) > 0))
    {
        /* open file for input */
        DcmInputFileStream fileStream(fileName);
        /* check stream status */
        l_error = fileStream.status();
        if (l_error.good())
        {
            /* read data from file */
            transferInit();
            l_error = read(fileStream, readXfer, groupLength, maxReadLength);
            transferEnd();
        }
    }
    return l_error;
}
 

smcd

Active member
It still makes no mention of a debugging call to assert =-( Have you tried compiling in "Release" mode and (guessing by the assertion failing) it crashing? You can set a breakpoint (F9) on the line, and when running in debug mode, step in to the code until you 1)crash 2)see something about an assertion.
 
OP
mesman00

mesman00

What's that...?
sethmcdoogle said:
It still makes no mention of a debugging call to assert =-( Have you tried compiling in "Release" mode and (guessing by the assertion failing) it crashing? You can set a breakpoint (F9) on the line, and when running in debug mode, step in to the code until you 1)crash 2)see something about an assertion.

yep i did that, i see nothing about an assertion, and then boom it crashes. i'll have to keep working to solve it.
 
OP
mesman00

mesman00

What's that...?
sethmcdoogle said:
It still makes no mention of a debugging call to assert =-( Have you tried compiling in "Release" mode and (guessing by the assertion failing) it crashing? You can set a breakpoint (F9) on the line, and when running in debug mode, step in to the code until you 1)crash 2)see something about an assertion.

yep i did that, i see nothing about an assertion, and then boom it crashes. i'll have to keep working to solve it.
 

smcd

Active member
Don't know what to tell you 'cuz it's hard having not seen the code or used that toolkit before, good luck finding it!
 

Doomulation

?????????????????????????
A typical "I don't know what the hell is going on!" type of problem. I guess you'll have to pinpoint WHERE exactly in the code the problem occours... sniff around a little to see something...
OR, make a workaround somehow. That usually seems the only solution to these kindof problems. Welcome to the world of C++!
 

euphoria

Emutalk Member
Maybe if you define NDEBUG before your functions should suppress the assert calls but then again this doesn't fix the problem...

This is from djgpp documentation on libc-2.02:

assert
Syntax

#define NDEBUG
#include <assert.h>

assert(expression);
assertval(expression);
Description

These macros are used to assist in debugging. The source code includes references to assert and assertval, passing them expressions that should be true (or non-zero). When the expression equals zero, a diagnostic message is printed to stderr and the program aborts.

If you define the macro NDEBUG before including `assert.h', then the macros expand to nothing to reduce code size after debugging is done.
Return Value

assert returns one if it passes, else it aborts.

assertval returns the value of the expression if nonzero, else it aborts.
Portability

ANSI, POSIX
Example

int strdup(char *s)
{
assert(s != 0);
 

Top