problem with "bool" as class variable

Started by
30 comments, last by Zahlman 15 years, 12 months ago
Quote:Original post by ehmdjii
yes it seems that the problem is elsewhere, cause it looks like the instance that is accessed later on when the problem occurs, is a complete different one.

but how can this happen? how can an instance be created without passing through the constructor?

It's likely that the object is being copy constructed. Nevertheless, you are fifty seconds away from the compiler just telling you exactly where the problem is. Just use a data breakpoint.
Advertisement
Quote:Original post by ehmdjii
button b0, b1, b2, b3, b4, b5, b6, b7;
button buttonArray[8] = {b0, b1, b2, b3, b4, b5, b6, b7};

That creates 8 instances of buttons using your default constructor then copy-constructs, with an implicit copy constructor, 8 more instances into an array.

You probably just want:

button buttonArray[8];

That will instantiate an array of 8 default constructed buttons.
thank you,

excuse the stupid question, but what is a "data"-breakpoint? :-)
Is it really too hard to put "data breakpoint" into google?
it's not. :) sorry

ok, i found out what a data breakpoint is, used it and it turns out that the data is modified in another class's constructor during an fread.
Quote:Original post by ehmdjii
thank you,

excuse the stupid question, but what is a "data"-breakpoint? :-)
In VC2005 (It'll be similar for other Visual Studio versions), put a breakpoint just after where you construct the variable, then when it's hit go to Debug -> New Breakpoint -> New Data Breakpoint, put in "&mouseover" for the address, and hit OK.
Then you'll break to the debugger whenever that variable is changed.
Quote:Original post by ehmdjii
it's not. :) sorry

ok, i found out what a data breakpoint is, used it and it turns out that the data is modified in another class's constructor during an fread.
It sounds like you're reading too many bytes and overflowing whatever buffer you're writing into.
Quote:Original post by Evil Steve
It sounds like you're reading too many bytes and overflowing whatever buffer you're writing into.


thank you.

this is the code where the data-breakpoint is triggered
	size_t bytestoread = width * height * depth;	size_t bytesread = 0;	pixels = (GLubyte * )malloc(bytestoread);	bytesread = fread(pixels, 1, bytestoread, filepointer);	if(bytesread != bytestoread) {		err = "Byte read mismatch";	}


the err is never reached though, so it seems as if i am reading the correct amount of memory i have previously allocated.
Now, the caveat there is that if you're later deallocating that memory, it may just happen to be in the same location as the eventual error location. To make sure that this isn't the case, use _CrtSetDbgFlag() to set the _CRTDBG_DELAY_FREE_MEM_DF flag. Alternately, simply keep running through the program, and see where the last modification of that memory location happens before the error occurs.
thank you, sneftel.

the last modification of the variable with the data breakpoint also happens in that fread line.

also, the heap-debug using _CrtSetDbgFlag does not output anything. or how is it supposed to notify you if such an overwrite occurs?

This topic is closed to new replies.

Advertisement