10,500,000 members (88,270 online)
Rate this:
See more:
```CRect rc;
rc.UnionRect(m_DMBR,childNode->GetDMBR());```

M_DMBR is empty,and childNode->GetDMBR()has values;
I want to know why rc is empty?
and I make a little test like this:

```CRect rt =CRect(35,35,112,112);
CRect rc,rc1;
rc1.UnionRect(rc,rt);
```

rc1 is not empty.

I dont know the reason.somebody can help me?
Posted 25-Sep-12 3:25am
Updated 25-Sep-12 3:46am
Malli_S30.1K
v2
Malli_S 25-Sep-12 9:49am

There is a chance that the union is empty. What does the UnionRect() function call returns?
mengfei358 25-Sep-12 10:04am

CRect rt =CRect(35,35,112,112);
CRect rc,rc1;
rc1.UnionRect(rc,rt);
In this code ,after using UnionRect,rc1 is not empty.
Richard MacCutchan 25-Sep-12 12:40pm

What is the content of `rc` at this point? I suspect it has some garbage in it, which is why you get a union that is not zero. You can test this by initialising it to a null rectangle.
Sergey Alexandrovich Kryukov 25-Sep-12 13:31pm

Maybe, still strange... union is not intersection...
Anyway, OP needs to make a sample where both operands are defined.
--SA
Richard MacCutchan 25-Sep-12 13:39pm

Exactly so, I'm just guessing here as there is not enough information to be sure.
Sergey Alexandrovich Kryukov 25-Sep-12 14:18pm

Absolutely,
--SA
mengfei358 25-Sep-12 20:31pm

Rc is an object of CRect, It's empty,and after union Rc1 (35,35,112,112).this is not my question ,my question is why
CRect rc;
rc.UnionRect(m_DMBR,childNode->GetDMBR());
rc is empty after union .
Richard MacCutchan 26-Sep-12 3:31am

As I said above, it may well be that `rc` contains garbage at this point, since you did not initialise it to anything. If you read the documentation you will see that the no argument constructor does not initialise it, so it may well contain values which mean it appears to be an unnormalized rectangle. This means that `UnionRect()` will return a zero rectangle, as again noted in the documentation.

It always pays to
i) read the documentation thoroughly, and
ii) use your debugger to check the actual values of your variables during execution.
Richard MacCutchan 26-Sep-12 3:41am

What are the actual values of `m_DMBR` and `childNode->GetDMBR()` at this point?
mengfei358 26-Sep-12 4:24am

M_DMBR is an object of CRect .and initialise it is null. and childNode->GetDMBR() get the value of one node's MBR.
Richard MacCutchan 26-Sep-12 4:38am

Why do you not answer the question I asked? I said What are the actual values, at this point in the program? The type of object or function call is totally irrelevant to your problem.
mengfei358 26-Sep-12 4:51am

sorry ,Maybe I dont understand whats your meaning ." the actual values of m_DMBR and childNode->GetDMBR() at this point?"?
Richard MacCutchan 26-Sep-12 5:01am

I mean the l, t, r, and b values of each of the rectangles you are trying to get the union of? Have you learned how to use your debugger to check such things?
mengfei358 26-Sep-12 8:07am

the l, t, r, and b values of each of the rectangle is known.
Richard MacCutchan 26-Sep-12 8:15am

Yes, but what are they? Unless you can answer this question with the actual values we cannot hope to guess why this is going wrong!
mengfei358 26-Sep-12 8:30am

CRect rc;
rc.UnionRect(m_DMBR,entry->GetInterMBR());
CString str;
str.Format("leaf:%d,%d,entry:%d,%d,m_DMBR:%d,%d",rc.BottomRight(),entry->GetInterMBR().BottomRight(),m_DMBR.BottomRight());
AfxMessageBox(str);
using this to test.and get value as this:leaf:0,0 entry:53,550,m_DMBR:-858993460,-858993460,
Richard MacCutchan 26-Sep-12 8:35am

At last you see that you are returning some incorrect values. Now you need to dig into your code to find out why.
mengfei358 26-Sep-12 8:52am

yes ，so thats what I want to know,after debug ,I cant find out the reason
Richard MacCutchan 26-Sep-12 8:59am

Well how on earth do you expect us to guess what may be happening? We have no idea what your code is doing or where these values come from. It is up to you to get working with your debugger and step through the code to find out.
mengfei358 26-Sep-12 9:08am

ok ，if I can find out the reason.i wouldnt ask the question.anyway,thank you.
Richard MacCutchan 26-Sep-12 11:06am

But how do you think we can find the reason? You have not given us any information about the values that are being passed in to the call to `CRect::UnionRect()`, in terms of where they come from, and even when I asked you to check them you did not provide all values. If you do not know how to use the debugger to trace through your code then I suggest you spend some time with the documentation and see how to stop the program at breakpoints and how to check the contents of variables.

Rate this:

## Solution 1

Please check m_DMBR initializing proper?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Graeme_Grant 170 OriginalGriff 138 Jochen Arndt 115 Kornfeld Eliyahu Peter 90 BillWoodruff 80
 OriginalGriff 3,095 Graeme_Grant 1,519 ProgramFOX 1,367 ppolymorphe 1,217 Jochen Arndt 1,205

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 18 Nov 2012