Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This:</p> <pre><code> progList = &amp;list[0]; </code></pre> <p>Should work perfectly.</p> <p>But because:</p> <pre><code>std::vector&lt;char*&gt; list; </code></pre> <p>is local to the function it is only valid while the function is active. Once the function returns the pointer become invalid (as the vector no longer exists).</p> <p>The reason I mention this is that you seem to be trying to use <code>progList</code> as an out parameters here:</p> <pre><code>int glfxGetProgramList(int effect, char** progList, int* count) // Because you call like this: glfxGetProgramList(effect, list, &amp;size ); // The value of list will not change // as you are passing by value. fprintf(stderr, "Output: %s\n", list[0]); // So here list has not changed. // But also note it would not have worked // as the object you were trying to make it // point at would have gone out of scope. </code></pre> <p>Unfortunately (or fortunately) because these parameters are not references any changes you make locally do not affect the original values outside the function.</p> <p>So you need to fix a couple of things:</p> <ul> <li>Make the vector last longer than the call to the function</li> <li>Pass list by reference into the function.</li> </ul> <p>Try:</p> <pre><code>int glfxGetProgramList(int effect, char**&amp; progList, int* count) // ^ pass by reference { static std::vector&lt;char*&gt; list; // Static makes the list last past the end of the function list.clear(); // Now we have to clear it each time we call to make sure // that old results do not pollute the list. gEffects[effect]-&gt;GetProgramList(list); fprintf(stderr, "Lib Output: %s\n", list[0]); progList = &amp;list[0]; // Value now passed correctly // back to the calling function // and list will still exist. int size = list.size(); memcpy(count, &amp;size, sizeof(int)); // This copies the first value out } </code></pre>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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