|
Previous post is getting long, so I'm making another.
I noticed some strange behaviour that I believe is definitely the cause of the "vector deleting destructor" error I've been getting.
I set a break point on each of the following lines and a watch on p_TileArray[0] through p_TileArray[3].
In the watch window it only shows p_TileArray for each variable, without the index. Furthermore, when I step through the breakpoints, You can see that p_TileArray is being treated as a single variable, as with every call to SetPos() , each element is given the same value. That is why the destructor is failing, as it is a vector deleting destructor and is being used as a scalar deleting destructor.
What causes this behaviour with p_TileArray and how do I fix it?"
See image here[^]
|
|
|
|
|
Bloody hell this is getting annoying >_> I ought to not be posting at this time of night as I do stupid things.
Anyway, turns out it is being treated as a regular array, like it should.
It's probably worth noting that the constructor is being called twice by the code, which should not happen.
if (p_CurrentBlock->isGrounded() == true)<br />
{<br />
Block theBlock;<br />
vector_BlockList.push_back(theBlock);<br />
p_CurrentBlock = &vector_BlockList.back();<br />
}
and immediately after stepping out of the constructor for the second time, we get a crash / assert failure, and every element of p_TileArray loses its data and becomes -1.5883997e+038 >_>
EDIT: I really think I may have figured it out now - I haven't defined a copy constructor for my Block class, so when theBlock is copied into vector_BlockList and we exit the if statement, all the Tile objects created on the heap are deleted, whilst theBlock that was passed into vector_BlockList still has a pointer that refers to them.
I've yet to implement the copy constructor as it's nearly 2 AM over here, but it's first on the table for tomorrow. Here's hoping for a good day tomorrow :P
modified on Saturday, October 4, 2008 11:46 AM
|
|
|
|
|
Okay so now I've built the copy constructor and I'm fairly certain it works perfectly, however now when I step through the program, The constructor for Block is being called once, followed by it's destructor, which now exhibits normal behaviour, first deleting p_TileArray and then setting it to NULL . Then the constructor is being called a second time, once again followed by the destructor, which also exhibits normal behaviour, but THEN the destructor is called a second time without another call to the constructor, which ends with a Debug assertion failure
EDIT:
for(int i=0; i < 10; i++)<br />
{<br />
Block theBlock; <br />
vector_BlockList.push_back(theBlock);<br />
p_CurrentBlock = &vector_BlockList.back();<br />
}
After the second iteration of this loop, vector_BlockList contains two of my Block class. The watch window tells me that the member variables are:
vector_BlockList[0].Shape = 5
vector_BlockList[0].Colour = 2
vector_BlockList[0].Grounded = false
vector_BlockList[0].p_TileArray = 0x00d15c7c {left=-1.5883997e+038 top=-1.5883997e+038 depth=-1.5883997e+038 ...}
vector_BlockList[1].Shape = 1
vector_BlockList[1].Colour = 4
vector_BlockList[1].Grounded = false
vector_BlockList[1].p_TileArray = p_TileArray = 0x00d15c7c {left=-1.5883997e+038 top=-1.5883997e+038 depth=-1.5883997e+038 ...}
modified on Saturday, October 4, 2008 7:18 PM
|
|
|
|
|
finally solved
It was an error in my copy constructor for the Block and Tile classes. Because the copy constructor was const , it had to invoke const -only methods. Turns out I stuffed up the syntax and used
const int GetSomeVar()
{
return SomeVar;
}
instead of
int GetSomeVar() const
{
return SomeVar;
}
Thanks to everyone who helped.
|
|
|
|
|
Even in CEdit::PreTranslateMessage I can't meet WM_MOUSEHOVER .
No problem with CListCtrl ,
even without a call to TrackMouseEvent ,
and I'm not sure if TrackMouseEvent is necessary any more.
logics
|
|
|
|
|
WM_MOUSEHOVER is a relatively new mouse message, so I'm not surprised at all that it doesn't fire from an EDIT window (one of the golden oldies).
You could always write your own CIHandleHoveringEdit class, and handle WM_MOUSEMOVEs, etc, and a WM_TIMER you reset each time the mouse moves... and so on. Not trivial, but do-able.
Iain.
|
|
|
|
|
H havei,
I am having a CListCtrl control in my dialog box. The ClistCtrl Control is having 5 columns withe column heads.
Now what i want to do is on a button click i want the same ClistCtrl to have redraw itself withe 2 columns along with their column heading.
So what exactly i want is to dynamically change the number of columns of a ClistCtrl along with their
headings. My application is on MFC
Please tell me how to do it.
Thanks In advance.
Dhiraj
|
|
|
|
|
You can also check out the DeleteColumn API if it suits your needs.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Use the CListCtrl::DeleteColumn() function.
|
|
|
|
|
Hi all,
I want to write the content of a buffer into a stringstream. So I do the following.
HRESULT hrRead;
ULONG readLen = 0;
do
{
char writeBuffer[100] = {0};
hrRead = pOutFileStream->Read(writeBuffer, sizeof(writeBuffer), &readLen);
str.write(writeBuffer, readLen);
}while(hrRead == S_OK);
But it's write only one byte to the stream. I can't figure it out. Can you someone helps me to fix it.
Thanks
I appreciate your help all the time...
CodingLover
|
|
|
|
|
CodingLover wrote: pOutFileStream->Read(writeBuffer, sizeof(writeBuffer), &readLen);
I am not sure, but I guess if the string in the buffer is in UNICODE format, such problem will occur.
|
|
|
|
|
Actually pOutFileStream is a IStream (I mean CComPtr<istream>) in UNICODE. I want to that stream attach to a buffer.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Well in that case, after reading from the buffer, convert the UNICODE to multi byte( use WideCharToMultiByte API ) and then set it to stringstream.
|
|
|
|
|
I'm bit confusing now sir.
I have read a stream(pOutFileStream) into a buffer. And then write that buffer content into a ostream. Actually pOutFileStream is a stream of an XML file formatted in UNICODE.
If you have any example related to that conversion please send it here.
Thanks
I appreciate your help all the time...
CodingLover
|
|
|
|
|
try this..
HRESULT hrRead;
ULONG readLen = 0;
do
{
char writeBuffer[100] = {0};
wchar_t ReadBuffer[100] = {0};
hrRead = pOutFileStream->Read(ReadBuffer, 100 , &readLen);
WideCharToMultiByte( CP_ACP, NULL, ReadBuffer, -1,writeBuffer, 100, NULL, NULL );
str.write(writeBuffer, strlen(writeBuffer));
}while(hrRead == S_OK);
|
|
|
|
|
I try what you suggest. But no luck.
My xml stream like this, <state>0</state> but the buffer only contain < in my previous code. With your suggestion, nothing is contain.
Here is my full code.
int GetStat::CopyTo(ostream& str)
{
HRESULT hrSeek, hrRead;
ULONG readLen = 0;
LARGE_INTEGER startPos = {0};
if((hrSeek = pOutFileStream->Seek(startPos, STREAM_SEEK_SET, NULL)) != S_OK)
{
LOG4CPLUS_ERROR(RF_GROUP_LOGGER, "Stream seek failed." << __FUNCTION__);
return -1;
}
do
{
char writeBuffer[256] = {0};
wchar_t ReadBuffer[100] = {0};
hrRead = pOutFileStream->Read(writeBuffer, sizeof(writeBuffer), &readLen);
str.write(writeBuffer, readLen);
}while(hrRead == S_OK);
return 0;
}
std::string GetStat::GetAsString(void)
{
stringstream str(ios::in|ios::out|ios::binary);
if(CopyTo(str) == 0)
return str.str();
return "";
}
int GetStat::Result()
{
std::string temp = GetAsString();
std::cout << temp << std::endl;
char buff[256] = {0};
sprintf(buff, "%s", temp.c_str());
}
You can find the buff in above code. In Result() method you can see I've print the output to the console. It gives the correct xml stream. But buff contain only the first character.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
I still belive this is because of the UNICODE. Did you debug and check the return value of WideCharToMultiByte() function, and if it is success what is the value in ReadBuffer , writeBuffer etc?
|
|
|
|
|
Yes I do. That function return value 1 ReadBuffer contains all zeros. WriteBuffer contains the xml stream.
In the WriteBuffer after each character it contain zero. I hope it's because of UNICODE.
Did you notice my result on console on Result() method. String variable temp prints the expected value. But when I add it to the buff it contain only < sign. In writeBuffer after that sign contain a zero. Is that effect in my case?
I appreciate your help all the time...
CodingLover
|
|
|
|
|
CodingLover wrote: ReadBuffer contains all zeros
All zero?? Then the function dosent worked as expected isnt it...?
CodingLover wrote: In the WriteBuffer after each character it contain zero
Thats is excatly the problem. That is in the statement sprintf(buff, "%s", temp.c_str()); , the sprintf() function will stop scanning the source string when it encounters a NULL. In your case since the source string is UNICODE, the second byte will be zero and hence the sprintf() returns at that point.
BTW there is another solution for the sprintf to work with unicode strings. used "%S" instead of "%s" in the format specifier.
|
|
|
|
|
Naveen wrote: BTW there is another solution for the sprintf to work with unicode strings. used "%S" instead of "%s" in the format specifier.
I've try that too. But no luck. In that time also, no any character is added to char buffer(buff)
Please help me to solve this, I'm wired with this now.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
HRESULT hrRead; ULONG readLen = 0;
do {
char writeBuffer[100] = {0};
hrRead = pOutFileStream->Read(writeBuffer, sizeof(writeBuffer), &readLen);
if (hrRead!=S_OK) break;
str.write(writeBuffer, readLen);
} while(hrRead == S_OK);
logics
|
|
|
|
|
I try your suggestion, but no luck. Do you think it's really need. Because Read() not return S_OK if read less number of bytes than define.
And also for the second part, yes I move the pointer to the beginning of the stream.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
I get a memory leak like this on debugging (after exiting the application):
{1557} normal block at 0x00483160, 2 bytes long.
Data: <1 > 31 00
How do I exactly find out the variable (name) holding the memory
0x00483160 that causes the leak.
Note : Double-clicking on the aforementioned line doesn't show me the
place of the memory leak
Thanx in Advance.
|
|
|
|
|
|
Hi, I've been using c# for some time , but I'm new in c++ and I'm using qt.
My question is whether there is a container control in C++ like a sliding menu ( for example, tool box , server explorer, solution explorer in Visual Studio when auto-hide (stample like) button is pressed.) These menus are hidden as you know when this auto-hide option is chosen and they appear sliding towards the center of the screen when mouse is over their tab.
I want to use a control likewise in my C++ (qt) application.
I went through Qt Designer but I couldn't find an object like that
Seeking for your help, thanx
|
|
|
|