Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Basically the problem is that your <code>clean_model</code> function is passed <code>model**</code> instead of <code>model*</code> you were expecting.</p> <p>Remember that <code>GArray</code> is meant to store complete structs, not just pointers to structs. In order to do that it needs to <em>copy</em> the whole contents of the struct into the internal <code>data</code> array and therefore any subsequent pointers to the structs (as passed to <code>clean_model</code>) are going to be pointing somewhere inside <code>data</code> (i.e. <code>clean_model((elt_type*)&amp;models-&gt;data[index * sizeof(elt_type)])</code> - where in your case <code>elt_type</code> is <code>model*</code>)</p> <p>To fix the situation couple options come to mind, in order of (subjective) preference:</p> <ol> <li>use <code>GPtrArray</code> instead; given that your elements are dynamically allocated already the memory management / pointer handling / typecasts (or lack thereof) would be less confusing</li> <li>change <code>clean_model</code> argument to <code>model**</code></li> <li>use <code>GArray</code> to store <code>model</code> structs rather than pointers, but only makes sense if you can separate the allocation from populating the model contents, e.g. <code>g_array_new(FALSE, FALSE, sizeof(model))</code> and <code>fill_model(&amp;g_array_index(models, model, i))</code></li> </ol> <p>In all cases you should also probably pass <code>TRUE</code> to <code>g_array_free</code> since you don't seem to be using the <code>GArray.data</code> for anything afterwards (not that it would make any sense given that you're freeing all the useful data in it anyway.)</p>
 

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