473,547 Members | 2,674 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Randomly occuring error DAMAGE: after Normal block

Hi Folks,

I got an error that drives me crazy because it only occurs sometimes and I
can`t even reproduce it.

I got a __gc class here is it`s header:

#pragma once

#include "../empLib/empImg.h"

namespace empDll
{
public __gc struct Image {
int x;
int y;
int z;
float data __gc[];
};

public __gc class Imager {
private:
char __nogc *_cfile;
empImg<float> __nogc *_img;
public:
Imager (System::String *filename);
~Imager(void);

int getDimX ();
int getDimY ();
int getDimZ ();

Image* load (int startPos, int count );
};

}

and here the code:

#include "Imager.h"
#include "../empLib/empDiscIO.h"

#using <mscorlib.dll >

using namespace System;

namespace empDll {
Imager::Imager (System::String *filename) {
try {
_cfile = new char [filename->Length];
memset (_cfile,0, strlen(_cfile)) ;

for (int i=0; i < filename->Length; i++) {
_cfile[i] = (char) filename->get_Chars(i) ;
}
_img = new empImg<float>;
} catch (empError e) {
e.msg();
}
}

Imager::~Imager (void) {
delete _img;
delete _cfile;
}

int Imager::getDimX () { return _img->dimx();}
int Imager::getDimY () { return _img->dimy();}
int Imager::getDimZ () { return _img->dimz();}

Image* Imager::load (int startPos, int count) {
try {
empDiscIO __nogc* imgIO = new empDiscIO(_cfil e);
*_img = imgIO->load(_cfile, startPos, count).normaliz e(0,255);

Image *tmp = new Image;

tmp->data = new float __gc[_img->size()];
tmp->x = _img->dimx();
tmp->y = _img->dimy();
tmp->z = _img->dimz();

System::Runtime ::InteropServic es::Marshal::Co py(_img->data, tmp->data, 0
,_img->size());
delete imgIO;
return tmp;
} catch (empError e) {
e.msg();
} catch (...) {
cout << "ERROR";
}

}

}

I use this managed and __gc class from C# in the following way:

public emData(string filename)
{
empDll.Imager myIo = new empDll.Imager(f ilename);
empDll.Image temp = myIo.load(0,0);
m_dims = new int[3];
m_dims[0] = temp.x;
m_dims[1] = temp.y;
m_dims[2] = temp.z;

m_emData = new float[m_dims[0]*m_dims[1]*m_dims[2]];

long bytecount = m_dims[0]*m_dims[1]*m_dims[2];

for (long i = 0; i<bytecount; i++) m_emData[i] = temp.data[i];

myIo = null;
}

When I use the emData Class in C# sometimes it simply works, sometimes i get
an null reference exception when accessing temp.x, temp.y or something else
and sometimes I get a very strange debugging error message:

DAMAGE: after Normal block (#114) at 0x060C5230

and everything crashes.

I assume that somehow memory allocated in the managed C++ DLL is not freeed
or something similar but I have no idea what I am doing wrong isn`t calling
delete enough in this case? Can someone please help me? Additionally I am
quite sure that I don`t have to loop through arrays and copy them value by
value I am just doing this to make sure this is not the problem here.

Thanks in Advance

Chucker

Jul 22 '05 #1
4 5138
Chucker,
That message occurs because some code wrote more bytes to an array than
the allocated length. In debug mode, the C++ allocator puts a distinctive
bit pattern both before and after the memory it returns to you. When that
memory is deleted, the code checks to see if those bit patterns are still
the same. If not, you get a message about damage before or after the memory
block.
Bob
"Chucker" <Ch*****@discus sions.microsoft .com> wrote in message
news:54******** *************** ***********@mic rosoft.com...
Hi Folks,

I got an error that drives me crazy because it only occurs sometimes and I
can`t even reproduce it.

I got a __gc class here is it`s header:

#pragma once

#include "../empLib/empImg.h"

namespace empDll
{
public __gc struct Image {
int x;
int y;
int z;
float data __gc[];
};

public __gc class Imager {
private:
char __nogc *_cfile;
empImg<float> __nogc *_img;
public:
Imager (System::String *filename);
~Imager(void);

int getDimX ();
int getDimY ();
int getDimZ ();

Image* load (int startPos, int count );
};

}

and here the code:

#include "Imager.h"
#include "../empLib/empDiscIO.h"

#using <mscorlib.dll >

using namespace System;

namespace empDll {
Imager::Imager (System::String *filename) {
try {
_cfile = new char [filename->Length];
memset (_cfile,0, strlen(_cfile)) ;

for (int i=0; i < filename->Length; i++) {
_cfile[i] = (char) filename->get_Chars(i) ;
}
_img = new empImg<float>;
} catch (empError e) {
e.msg();
}
}

Imager::~Imager (void) {
delete _img;
delete _cfile;
}

int Imager::getDimX () { return _img->dimx();}
int Imager::getDimY () { return _img->dimy();}
int Imager::getDimZ () { return _img->dimz();}

Image* Imager::load (int startPos, int count) {
try {
empDiscIO __nogc* imgIO = new empDiscIO(_cfil e);
*_img = imgIO->load(_cfile, startPos, count).normaliz e(0,255);

Image *tmp = new Image;

tmp->data = new float __gc[_img->size()];
tmp->x = _img->dimx();
tmp->y = _img->dimy();
tmp->z = _img->dimz();

System::Runtime ::InteropServic es::Marshal::Co py(_img->data, tmp->data, 0
,_img->size());
delete imgIO;
return tmp;
} catch (empError e) {
e.msg();
} catch (...) {
cout << "ERROR";
}

}

}

I use this managed and __gc class from C# in the following way:

public emData(string filename)
{
empDll.Imager myIo = new empDll.Imager(f ilename);
empDll.Image temp = myIo.load(0,0);
m_dims = new int[3];
m_dims[0] = temp.x;
m_dims[1] = temp.y;
m_dims[2] = temp.z;

m_emData = new float[m_dims[0]*m_dims[1]*m_dims[2]];

long bytecount = m_dims[0]*m_dims[1]*m_dims[2];

for (long i = 0; i<bytecount; i++) m_emData[i] = temp.data[i];

myIo = null;
}

When I use the emData Class in C# sometimes it simply works, sometimes i
get
an null reference exception when accessing temp.x, temp.y or something
else
and sometimes I get a very strange debugging error message:

DAMAGE: after Normal block (#114) at 0x060C5230

and everything crashes.

I assume that somehow memory allocated in the managed C++ DLL is not
freeed
or something similar but I have no idea what I am doing wrong isn`t
calling
delete enough in this case? Can someone please help me? Additionally I am
quite sure that I don`t have to loop through arrays and copy them value by
value I am just doing this to make sure this is not the problem here.

Thanks in Advance

Chucker

Jul 22 '05 #2
Hi Bob,

the only place where I think this can happen is here:

System::Runtime ::InteropServic es::Marshal::Co py(_img->data, tmp->data,
0,_img-size());

maybe

System::Runtime ::InteropServic es::Marshal::Co py(_img->data, tmp->data,
0,_img-size()-1);

might solve the problem, I will check this out. What if the native C++ Class
Library that I am wrapping here has an internal memory leak, is there any way
to deal with?

Thanks

Chucker

"Bob Milton" wrote:
Chucker,
That message occurs because some code wrote more bytes to an array than
the allocated length. In debug mode, the C++ allocator puts a distinctive
bit pattern both before and after the memory it returns to you. When that
memory is deleted, the code checks to see if those bit patterns are still
the same. If not, you get a message about damage before or after the memory
block.
Bob
"Chucker" <Ch*****@discus sions.microsoft .com> wrote in message
news:54******** *************** ***********@mic rosoft.com...
Hi Folks,

I got an error that drives me crazy because it only occurs sometimes and I
can`t even reproduce it.

I got a __gc class here is it`s header:

#pragma once

#include "../empLib/empImg.h"

namespace empDll
{
public __gc struct Image {
int x;
int y;
int z;
float data __gc[];
};

public __gc class Imager {
private:
char __nogc *_cfile;
empImg<float> __nogc *_img;
public:
Imager (System::String *filename);
~Imager(void);

int getDimX ();
int getDimY ();
int getDimZ ();

Image* load (int startPos, int count );
};

}

and here the code:

#include "Imager.h"
#include "../empLib/empDiscIO.h"

#using <mscorlib.dll >

using namespace System;

namespace empDll {
Imager::Imager (System::String *filename) {
try {
_cfile = new char [filename->Length];
memset (_cfile,0, strlen(_cfile)) ;

for (int i=0; i < filename->Length; i++) {
_cfile[i] = (char) filename->get_Chars(i) ;
}
_img = new empImg<float>;
} catch (empError e) {
e.msg();
}
}

Imager::~Imager (void) {
delete _img;
delete _cfile;
}

int Imager::getDimX () { return _img->dimx();}
int Imager::getDimY () { return _img->dimy();}
int Imager::getDimZ () { return _img->dimz();}

Image* Imager::load (int startPos, int count) {
try {
empDiscIO __nogc* imgIO = new empDiscIO(_cfil e);
*_img = imgIO->load(_cfile, startPos, count).normaliz e(0,255);

Image *tmp = new Image;

tmp->data = new float __gc[_img->size()];
tmp->x = _img->dimx();
tmp->y = _img->dimy();
tmp->z = _img->dimz();

System::Runtime ::InteropServic es::Marshal::Co py(_img->data, tmp->data, 0
,_img->size());
delete imgIO;
return tmp;
} catch (empError e) {
e.msg();
} catch (...) {
cout << "ERROR";
}

}

}

I use this managed and __gc class from C# in the following way:

public emData(string filename)
{
empDll.Imager myIo = new empDll.Imager(f ilename);
empDll.Image temp = myIo.load(0,0);
m_dims = new int[3];
m_dims[0] = temp.x;
m_dims[1] = temp.y;
m_dims[2] = temp.z;

m_emData = new float[m_dims[0]*m_dims[1]*m_dims[2]];

long bytecount = m_dims[0]*m_dims[1]*m_dims[2];

for (long i = 0; i<bytecount; i++) m_emData[i] = temp.data[i];

myIo = null;
}

When I use the emData Class in C# sometimes it simply works, sometimes i
get
an null reference exception when accessing temp.x, temp.y or something
else
and sometimes I get a very strange debugging error message:

DAMAGE: after Normal block (#114) at 0x060C5230

and everything crashes.

I assume that somehow memory allocated in the managed C++ DLL is not
freeed
or something similar but I have no idea what I am doing wrong isn`t
calling
delete enough in this case? Can someone please help me? Additionally I am
quite sure that I don`t have to loop through arrays and copy them value by
value I am just doing this to make sure this is not the problem here.

Thanks in Advance

Chucker


Jul 22 '05 #3
A memory leak will NOT cause this error message! This is a data overrun,
and is a serious problem. Somewhere in the C++ DLL is a call to new which is
too small for the data being copied. BTW, this error message is for the C++
side, not the C# side of things.
Bob

"Chucker" <Ch*****@discus sions.microsoft .com> wrote in message
news:47******** *************** ***********@mic rosoft.com...
Hi Bob,

the only place where I think this can happen is here:

System::Runtime ::InteropServic es::Marshal::Co py(_img->data, tmp->data,
0,_img-size());

maybe

System::Runtime ::InteropServic es::Marshal::Co py(_img->data, tmp->data,
0,_img-size()-1);

might solve the problem, I will check this out. What if the native C++
Class
Library that I am wrapping here has an internal memory leak, is there any
way
to deal with?

Thanks

Chucker

"Bob Milton" wrote:
Chucker,
That message occurs because some code wrote more bytes to an array
than
the allocated length. In debug mode, the C++ allocator puts a distinctive
bit pattern both before and after the memory it returns to you. When that
memory is deleted, the code checks to see if those bit patterns are still
the same. If not, you get a message about damage before or after the
memory
block.
Bob
"Chucker" <Ch*****@discus sions.microsoft .com> wrote in message
news:54******** *************** ***********@mic rosoft.com...
> Hi Folks,
>
> I got an error that drives me crazy because it only occurs sometimes
> and I
> can`t even reproduce it.
>
> I got a __gc class here is it`s header:
>
> #pragma once
>
> #include "../empLib/empImg.h"
>
> namespace empDll
> {
> public __gc struct Image {
> int x;
> int y;
> int z;
> float data __gc[];
> };
>
> public __gc class Imager {
> private:
> char __nogc *_cfile;
> empImg<float> __nogc *_img;
> public:
> Imager (System::String *filename);
> ~Imager(void);
>
> int getDimX ();
> int getDimY ();
> int getDimZ ();
>
> Image* load (int startPos, int count );
> };
>
> }
>
> and here the code:
>
> #include "Imager.h"
> #include "../empLib/empDiscIO.h"
>
> #using <mscorlib.dll >
>
>
>
> using namespace System;
>
> namespace empDll {
> Imager::Imager (System::String *filename) {
> try {
> _cfile = new char [filename->Length];
> memset (_cfile,0, strlen(_cfile)) ;
>
> for (int i=0; i < filename->Length; i++) {
> _cfile[i] = (char) filename->get_Chars(i) ;
> }
> _img = new empImg<float>;
> } catch (empError e) {
> e.msg();
> }
> }
>
> Imager::~Imager (void) {
> delete _img;
> delete _cfile;
> }
>
> int Imager::getDimX () { return _img->dimx();}
> int Imager::getDimY () { return _img->dimy();}
> int Imager::getDimZ () { return _img->dimz();}
>
> Image* Imager::load (int startPos, int count) {
> try {
> empDiscIO __nogc* imgIO = new empDiscIO(_cfil e);
> *_img = imgIO->load(_cfile, startPos, count).normaliz e(0,255);
>
> Image *tmp = new Image;
>
> tmp->data = new float __gc[_img->size()];
> tmp->x = _img->dimx();
> tmp->y = _img->dimy();
> tmp->z = _img->dimz();
>
> System::Runtime ::InteropServic es::Marshal::Co py(_img->data, tmp->data,
> 0
> ,_img->size());
> delete imgIO;
> return tmp;
> } catch (empError e) {
> e.msg();
> } catch (...) {
> cout << "ERROR";
> }
>
> }
>
> }
>
> I use this managed and __gc class from C# in the following way:
>
> public emData(string filename)
> {
> empDll.Imager myIo = new empDll.Imager(f ilename);
> empDll.Image temp = myIo.load(0,0);
> m_dims = new int[3];
> m_dims[0] = temp.x;
> m_dims[1] = temp.y;
> m_dims[2] = temp.z;
>
> m_emData = new float[m_dims[0]*m_dims[1]*m_dims[2]];
>
> long bytecount = m_dims[0]*m_dims[1]*m_dims[2];
>
> for (long i = 0; i<bytecount; i++) m_emData[i] = temp.data[i];
>
> myIo = null;
> }
>
> When I use the emData Class in C# sometimes it simply works, sometimes
> i
> get
> an null reference exception when accessing temp.x, temp.y or something
> else
> and sometimes I get a very strange debugging error message:
>
> DAMAGE: after Normal block (#114) at 0x060C5230
>
> and everything crashes.
>
> I assume that somehow memory allocated in the managed C++ DLL is not
> freeed
> or something similar but I have no idea what I am doing wrong isn`t
> calling
> delete enough in this case? Can someone please help me? Additionally I
> am
> quite sure that I don`t have to loop through arrays and copy them value
> by
> value I am just doing this to make sure this is not the problem here.
>
> Thanks in Advance
>
> Chucker
>


Jul 22 '05 #4
I solved it! The problem was that the static lib linked to the managed DLL
was linked against the static runtime, the managed lib was linked against the
DLL Runtime and the C# Application was linked against CRT.

Now I rebuild everything and linked everything against the multithreaded
debug dll runtime and suddenly everything is fine!

Thanks for your efforts

Chucker
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
12279
by: viditm | last post by:
Hi I keep getting the error "Error Creating Windows Handle" in my application and different places in the code. This occurs only to certain users. Its very random and cannot be reproduced in the development environment. I have an applicatin error logger which shows this error occuring (in the stack trace dump) but it again occurs at different...
4
44304
by: Nathan Given | last post by:
Hello All, I am trying to randomly change the background image of my home page but I can't seem to figure it out. Here is a snippet of my css .... BODY {background:transparent url(../images/homepagebg3.jpg) no-repeat; font:normal 90% Arial, Helvetica, sans-serif; color:#263158;}
5
5261
by: fbwhite | last post by:
I know this issue has been brought up many times, but I have tried many of the solutions to no avail. I wanted to give my specific case to see if someone could be of any help. We are using the sessionstate inproc mode and users are randomly losing their session. I do not believe it is happening across all users at one time. It seems to...
4
338
by: Chucker | last post by:
Hi Folks, I got an error that drives me crazy because it only occurs sometimes and I can`t even reproduce it. I got a __gc class here is it`s header: #pragma once #include "../empLib/empImg.h"
10
6626
by: Jeff Shepler | last post by:
This is probably not the right newsgroup for this, but this is the only one I read and there are a lot of smart people that "live" here. Please don't berate me if you think this should have been posted in another newsgroup. The web application I'm currently working on will (seemingly) randomly throw an exception when opening a database...
2
7987
by: Mehmet Kitapci | last post by:
Hi, I receive this "Debug Error!" message while deleting the CContext instance. e.g. CContext pCC = new CContext(); // ... do something on pCC delete pCC; // error message pops up here. I've given below the code fragment for the class.
5
1506
by: Nick Gilbert | last post by:
Hi, I recently upgraded a website from ASP.NET 1.1 to 2.0. While working on the site and changing aspx or ascx files, I sometimes randomly get a compilation error after refreshing the page in the browser (NOT when building the project from within VS.NET). The only way to fix it is to clean the project and rebuild it - then reload the page...
3
1447
by: raan | last post by:
Whats wrong with the code ? delete tp; is throwing DAMAGE: After normal block(#56) at 0x00321480 Environment, VS2003, XP #include <iostream> #include <fstream> #include <string> #include <set> #include <stack> #include <sstream>
4
1429
by: JDHawk | last post by:
Hi, when I compile my c++ program, MS Visual C++ (2003) shows this error: Damage: after Normal Block (#139) at 0xXXXXXXXX In Debug Mode I found out that it is the deallocation with "delete" in the destructor. When hiding the delete, there is no error, but I want to set my data free in the destructor before the object dies. It has...
0
7510
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7703
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7797
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6032
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3473
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1050
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
748
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.