|
Yeah perfect.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
See the suggestion here.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
I have a vector that contains POSITIONs. When I try to push_back or clear, the program crashes. The callstack shows _invalid_parameter_noinfo in one of the frames. I googled and found a solution(defining _HAS_ITERA.... and _SECURE_SCL to 0) , but was not effective. I'm using VS2008 with MFC feature pack installed on vista.
Please help.
Thanks
|
|
|
|
|
Can be due to a lot of reasons. Could you please provide relevant code snippet and call stack during crash?
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
The call stack:
> Desktop.exe!_crt_debugger_hook(int _Reserved=0) Line 65 C
Desktop.exe!_invalid_parameter(const wchar_t * pszExpression=0x00000000, const wchar_t * pszFunction=0x00000000, const wchar_t * pszFile=0x00000000, unsigned int nLine=0, unsigned int pReserved=0) Line 112 + 0x7 bytes C++
Desktop.exe!_invalid_parameter_noinfo() Line 125 + 0xc bytes C++
Desktop.exe!std::vector<crecord> >::insert(std::_Vector_const_iterator<crecord> > _Where=..., CRecord * const & _Val=0x01703200) Line 878 + 0x1e bytes C++
Desktop.exe!COutlineTextView::prepareSelBounds() Line 4816 C++
Desktop.exe!COutlineTextView::OnMouseMove(unsigned int nFlags=1, CPoint point={...}) Line 167 + 0x40 bytes C++
Desktop.exe!COutlineEditView::OnMouseMove(unsigned int nFlags=1, CPoint pointMove={...}) Line 2935 C++
Desktop.exe!CWnd::OnWndMsg(unsigned int message=512, unsigned int wParam=1, long lParam=3231936, long * pResult=0x007bfc9c) Line 2062 C++
Code snippet where it crashes:
declared as
std::vector<POSITION> m_selection;
in member function:
if (m_selection.size() > 0){
m_selection.clear();
}
.........
,.............
.......
POSITION pos = m_selStart.getItem();
while(pos != NULL && pos != m_selEnd.getItem())
{
m_selection.push_back(pos);
pos = getMan()->getNext(pos);
}
ASSERT(pos);
m_selection.push_back(m_selEnd.getItem());
|
|
|
|
|
Why are you mixing MFC collections with STL ones?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Is it a serious issue(mixing MFC with STL)? please explain.
|
|
|
|
|
It's not FATAL - but the two mindsets of the framework designers are quite different.
So you're setting yourself up for confusion. Which is never good. I find it confusing enough just getting out of bed.
Iain.
modified on Friday, December 19, 2008 10:07 AM
|
|
|
|
|
Iain Clarke wrote: It's not FATAL - but the two mindsets of the framework designers are quite different.
Also the quality of the two mindsets is quite different (as usual this is going on my arrogant...)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
The problem is still not solved.
I have some classes that inherit from vectors.
I have a vector of POSITION(in afx.h)
struct __POSITION {};
typedef __POSITION* POSITION;
So when I try to push a POSITION value to the vector<position>
I get this crash saying invalid parameter.
In call stack I see its trying to push(insert) a value of different type (ref. classes that inherit from vectors) other than POSITION. How is this possible?
Please help!!!
|
|
|
|
|
Nope, if you're able to master both. Anyway, if you're able to master both then you don't mix them.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
ThisIsMeRon wrote: Desktop.exe!_invalid_parameter_noinfo() Line 125 + 0xc bytes C++
Looks like a CRT invalid argument error. You can use _set_invalid_parameter_handler[^] to set a custom handler for whatever invalid argument is being passed. Note that not correctly handling the error could mask the real problem.
Best Wishes,
-David Delaune
|
|
|
|
|
I had the same problem when porting from VS2005 to VS2008.
I avoided it using dynamic allocation something like this:
std::vector<???> *v;
v = new ???;
v->push_back(***)
This works in both debug and release mode ^^
|
|
|
|
|
hi all,
I m using a ListCtrl,here diffrent rows and column are present.
for example there is 10 row and 4 column.
i want a RECT value for corresponding row and column.
i m using this.
CRect CDemo::GetCellRect(int nRow, int nCol)
{
ASSERT(nCol >= 0 && nCol < m_nPageCols);
ASSERT(nRow >= 0 && nRow < m_nRowCount);
CSize charSize = m_CharSizeBody;
CRect rectBody = m_rectBody;
CRect rectCol = GetColumnRect(0);
for (int nLeft=0, i=0; i < nCol; i++)
nLeft += GetColumnWidth(m_nColumns[i]);
int nRight = nLeft + GetColumnWidth(m_nColumns[i]);
int nPageRow = nRow % m_nPageRows;
ASSERT(nPageRow <= m_nPageRows);
CRect rect(
rectBody.left + nLeft,
rectBody.top + rectCol.Height() + charSize.cy * nPageRow,
rectBody.left + nRight,
rectBody.top + rectCol.Height() + charSize.cy * (nPageRow + 1));
if (rect.right > rectBody.right)
rect.right = rectBody.right;
rect.left += (int)(CELL_PADDING * m_RatioX);
return rect;
}
but this gives some wrong values.
for all columns in one row its gives same value and put data in 1st column.
i want to put data in corresponding row and columns.
please correct me.
thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
|
Why dont' you use GetItemRect and GetSubItemRect ?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi all,
What is wrong in this problem. Is this the right way to handle?
#include <iostream.h>
class MyErrorClass
{
char *reason;
int *i;
public:
MyErrorClass(char *r)
{
i = new int[6];
cout<<;"Constructor<<endl;
reason = r;
cout<<reason<<<endl;
}
char* giveReason()
{
return reason;
}
~MyErrorClass()
{
cout<<"destructor"<<endl;
delete[] i;
}
};
void main()
{
try
{
throw MyErrorClass("error");
}
catch (MyErrorClass &e)
{
cout<<"Exception caught --- <<e.giveReason()<<endl;
}
}
Thanks
San
|
|
|
|
|
I hope you got a crash when you run this code snippet. I rewrote it like this. It allocates the MyErrorClass then throw it. On the top level function, you can delete it. Check the code snippet.
void main()
{
try
{
throw new MyErrorClass("error");
}
catch (MyErrorClass* e)
{
cout<<"Exception caught --- "<<e->giveReason()<<endl;
delete e;
}
}
[Added] As pointed out by Stuart, it will be better to catch the exception object by reference itself. But here the problem is your MyErrorClass is not well written to handle its allocation which can cause crashes(I had). Hope you've already went thought Stuart's explanations.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
modified on Friday, December 19, 2008 9:46 AM
|
|
|
|
|
Ummm - no. You definitely should not get a crash when you throw an exception object (as opposed to an exception pointer). The exception declaration does not define the lifetime of the exception - the runtime copies it (or something like that, anyway).
Try the following - you'll find it doesn't crash...
#include <stdexcept>
#include <iostream>
int main(int, char**)
{
try
{
throw std::runtime_error("Test");
}
catch(std::exception& e)
{
std::cerr << "Caught exception - " << e.what() << std::endl;
};
}
|
|
|
|
|
Well Stuart, try with this code snippet. Its the same code snippet provided by Ron. I made it compilable. I'll be surprised if it didn't crashed in your system.
class MyErrorClass
{
char *reason;
int *i;
public:
MyErrorClass(char *r)
{
i = new int[6];
cout<<"Constructor"<<endl;
reason = r;
cout<<reason<<endl;
}
char* giveReason()
{
return reason;
}
~MyErrorClass()
{
cout<<"destructor"<<endl;
delete[] i;
}
};
void main()
{
try
{
throw MyErrorClass("error");
}
catch (MyErrorClass* e)
{
cout<<"Exception caught --- "<<e->giveReason()<<endl;
}
}
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Yes, this code will crash - because you're throwing an object of type MyErrorClass and trying to catch a pointer to an object of type MyErrorClass .
With the original code, which has this line, catching an object (well, reference to an object) of type MyErrorClass
catch (MyErrorClass &e)
the code compiles, links and runs as expected.
Did you try it? I did.
|
|
|
|
|
Ah! Sorry, i did send you the wrong code. I forgot to rollback the changes made to the old code. I really meant - catch (MyErrorClass &e) will also crash. I'm posting the code snippet once again. Well, I'm using Visual Studio 6.0. Which one you're using? Well, the reason for crash is due to the fact that MyErrorClass::i is being de-allocated twice, since the copy constructor is not written for deep copy.
class MyErrorClass
{
char *reason;
int *i;
public:
MyErrorClass(char *r)
{
i = new int[6];
cout<<"Constructor"<<endl;
reason = r;
cout<<reason<<endl;
}
char* giveReason()
{
return reason;
}
~MyErrorClass()
{
cout<<"destructor"<<endl;
delete[] i;
}
};
void main()
{
try
{
throw MyErrorClass("error");
}
catch (MyErrorClass& e)
{
cout<<"Exception caught --- "<<e.giveReason()<<endl;
}
}
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Jijo raj wrote: Well, the reason for crash is due to the fact that MyErrorClass::i is being de-allocated twice, since the copy constructor is not written for deep copy
You're quite correct - I didn't get a crash because I compiled with a non-debug runtime library. Even so, I'd still recommend throwing objects, not pointers - the real solution is for the OP to write a better exception class, I think.
Jijo raj wrote: I'm using Visual Studio 6.0. Which one you're using?
2003, 2005 and 2008 - certainly not VC6!!! The reason I don't use VC6 is because it is so primitive in terms of C++ language support.
|
|
|
|
|
Stuart Dootson wrote: Even so, I'd still recommend throwing objects, not pointers - the real solution is for the OP to write a better exception class, I think.
You're right. Indeed, i did forget about C++ morels when i saw the crash.
Stuart Dootson wrote: 2003, 2005 and 2008 - certainly not VC6!!! The reason I don't use VC6 is because it is so primitive in terms of C++ language support.
Yep. That's right. But still my favorite due to the excellent fast IDE. Well, i'm waiting for VC10 which is supposed to be the new 6.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Jijo raj wrote: still my favorite due to the excellent fast IDE
VS2003 and VS2005 are fast when you give them a 2.4GHz Core 2 Duo and 4GB of RAM to play with VS2008...I'm not so fond of, the debugger especially seems sluggish.
Jijo raj wrote: Well, i'm waiting for VC10 which is supposed to be the new 6.
It's not (IMO) - I've used the CTP, and it's a really an evolution of VS2008 - it did seem a bit quicker, though. And the compiler has C++0x features, like lambdas and type inferencing, which are uber-cool
|
|
|
|