(UNDER CONSTRUCTION) fixed bad free + testing AXIS_X bifurcation

This commit is contained in:
Emile Clark-Boman 2025-09-16 18:46:01 +10:00
parent b16590fd5a
commit 5e99b09f8a
7 changed files with 92 additions and 46 deletions

View file

@ -46,7 +46,7 @@ struct ct_node *new_node(struct ct_bounds *const bounds,
* WARNING: new_node doesn't set the NFLAG_RESIZE request flag
* WARNING: that should be done by a function calling new_node
*/
return __node(parent->surface->dims, bounds, parent);
return __node(dup_dims(parent->surface->dims), bounds, parent);
}
/* WARNING: Do NOT use __destroy_node() to destroy a node's children!
@ -76,8 +76,9 @@ struct ct_spdims {
/*
*/
int resize_node(struct ct_node *const node, struct ct_dims *const dims) {
int resize_node(struct ct_node *const node, struct ct_dims *dims) {
resize_surface(node->surface, dims);
dims = node->surface->dims;
if (node->surface->bounds->wmin > dims->width ||
node->surface->bounds->hmin > dims->height) {
@ -101,36 +102,43 @@ int resize_node(struct ct_node *const node, struct ct_dims *const dims) {
}
int axm_size, axm_free;
size_t bounds_axm_min_offset, bounds_axm_max_offset;
size_t dims_axm_pos_offset, dims_axm_size_offset;
/* DEBUG: WARNING :DEBUG */
// size_t bounds_axm_min_offset, bounds_axm_max_offset;
// size_t dims_axm_pos_offset, dims_axm_size_offset;
if (node->axis == AXIS_X) {
axm_free = dims->width;
axm_size = dims->width;
dims_axm_pos_offset = offsetof(struct ct_dims, x);
dims_axm_size_offset = offsetof(struct ct_dims, width);
bounds_axm_min_offset = offsetof(struct ct_bounds, wmin);
bounds_axm_max_offset = offsetof(struct ct_bounds, wmax);
/* DEBUG: WARNING :DEBUG */
// dims_axm_pos_offset = offsetof(struct ct_dims, x);
// dims_axm_size_offset = offsetof(struct ct_dims, width);
// bounds_axm_min_offset = offsetof(struct ct_bounds, wmin);
// bounds_axm_max_offset = offsetof(struct ct_bounds, wmax);
} else {
assert(node->axis == AXIS_Y);
axm_free = dims->height;
axm_size = dims->height;
dims_axm_pos_offset = offsetof(struct ct_dims, y);
dims_axm_size_offset = offsetof(struct ct_dims, height);
bounds_axm_min_offset = offsetof(struct ct_bounds, hmin);
bounds_axm_max_offset = offsetof(struct ct_bounds, hmax);
/* DEBUG: WARNING :DEBUG */
// dims_axm_pos_offset = offsetof(struct ct_dims, y);
// dims_axm_size_offset = offsetof(struct ct_dims, height);
// bounds_axm_min_offset = offsetof(struct ct_bounds, hmin);
// bounds_axm_max_offset = offsetof(struct ct_bounds, hmax);
}
struct ct_spdims cspdims[node->cindex];
cindex parts_n = node->cindex;
memset(cspdims, 0, sizeof(struct ct_spdims) * node->cindex);
for (int i = 0; i < node->cindex; i++) {
cspdims[i].min =
*(int *)(node->child[i]->surface->bounds + bounds_axm_min_offset);
cspdims[i].max =
*(int *)(node->child[i]->surface->bounds + bounds_axm_max_offset);
/* DEBUG: WARNING :DEBUG */
// cspdims[i].min =
// *(int *)(node->child[i]->surface->bounds + bounds_axm_min_offset);
// cspdims[i].max =
// *(int *)(node->child[i]->surface->bounds + bounds_axm_max_offset);
cspdims[i].min = node->child[i]->surface->bounds->wmin;
cspdims[i].max = node->child[i]->surface->bounds->wmax;
if (node->child[i]->surface->bounds->type == BOUND_RELATIVE) {
cspdims[i].min *= axm_size;
cspdims[i].max *= axm_size;
@ -165,9 +173,13 @@ int resize_node(struct ct_node *const node, struct ct_dims *const dims) {
// *(int*)(cdims + dims_axo_pos_offset) = *(int*)(dims + dims_axo_pos_offset);
// *(int*)(cdims + dims_axo_size_offset) = axo_size;
for (int i = 0; i < node->cindex; i++) {
*(int *)(cdims + dims_axm_size_offset) = cspdims[i].axm_size;
/* DEBUG: WARNING :DEBUG */
// *(int *)(cdims + dims_axm_size_offset) = cspdims[i].axm_size;
cdims->width = cspdims[i].axm_size;
resize_node(node->child[i], dup_dims(cdims));
*(int *)(cdims + dims_axm_pos_offset) += cspdims[i].axm_size;
/* DEBUG: WARNING :DEBUG */
// *(int *)(cdims + dims_axm_pos_offset) += cspdims[i].axm_size;
cdims->x += cspdims[i].axm_size;
}
free(cdims);
@ -200,13 +212,13 @@ static int __set_cbounds(struct ct_node *const parent,
parent->cbounds.wmin_rel = p_wmin_rel;
parent->cbounds.hmin_rel = p_hmin_rel;
assert(parent->cbounds.wmin_rel > __BOUND_REL_MIN);
assert(parent->cbounds.hmin_rel > __BOUND_REL_MIN);
assert(parent->cbounds.wmin_rel >= __BOUND_REL_MIN);
assert(parent->cbounds.hmin_rel >= __BOUND_REL_MIN);
} else {
parent->cbounds.wmin_abs += c_wmin;
parent->cbounds.hmin_abs += c_hmin;
assert(parent->cbounds.wmin_abs > __BOUND_ABS_MIN);
assert(parent->cbounds.hmin_abs > __BOUND_ABS_MIN);
assert(parent->cbounds.wmin_abs >= __BOUND_ABS_MIN);
assert(parent->cbounds.hmin_abs >= __BOUND_ABS_MIN);
}
return 0;
}
@ -317,8 +329,7 @@ static int __index_as_child(const struct ct_node *const node,
return 2;
}
/*
* If preserve_bounds is set then upon collapse the new node maintains the
/* If preserve_bounds is set then upon collapse the new node maintains the
* original node's bounds struct. Otherwise the bounds of the child collapsed
* onto are used.
*/