Note that there are some explanatory texts on larger screens.

plurals
  1. POproblem with quadTree & union
    primarykey
    data
    text
    <p>i have the following quadtree-like structure, in which each cell can either be a inner node or a leaf. if it is a leaf, it can store a color. if it is a inner node, it stores pointers to four children (which can be either leaf or inner node):</p> <pre><code>class RenderBucketCell{ public: RenderBucketCell(); RenderBucketCell(float R, float G, float B, float A, unsigned short X, unsigned short Y); ~RenderBucketCell(); void split(); void collapse(); bool isLeaf; RenderBucketCell* neighbours[8]; unsigned short x; unsigned short y; union{ struct{ float r; float g; float b; float a; }; struct{ RenderBucketCell* children[4]; }; }; }; </code></pre> <p>if the cell is is an inner node, then it doesn't need to store a color. if it's a leaf, then it doesn't need to store pointers to children. therefore the color and the children shall share the same memory (union)</p> <p>there is the function split() which transforms a leaf into a inner node and creates for children (leafs) with the same color the current cell has at the moment:</p> <pre><code>void RenderBucketCell::split(){ isLeaf=false; float rt = r;//make backups of the values before setting the children (union) float gt = g; float bt = b; float at = a; unsigned short xt2 = x*2; unsigned short yt2 = y*2; children[0] = new RenderBucketCell(rt,gt,bt,at, xt2, yt2); children[1] = new RenderBucketCell(rt,gt,bt,at, xt2+1, yt2); children[2] = new RenderBucketCell(rt,gt,bt,at, xt2, yt2+1); children[3] = new RenderBucketCell(rt,gt,bt,at, xt2+1, yt2+1); } </code></pre> <p>now i'm debugging the function split(). i set a debug point on the line</p> <pre><code>children[0] = new RenderBucketCell(rt,gt,bt,at, xt2, yt2); </code></pre> <p>so now: the debugger stops at this line and i observe the membervalues. i do a procedurestep, such that the line gets executed (the instruction cursor is now on the next line). After the line has been executed, the pointervalue of children[0] is still the same! instead, the pointervalue of children[2] has changed (along with the float value b)</p> <p>can someone explain me this behaviour?? what am i doing wrong?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload