Note that there are some explanatory texts on larger screens.

plurals
  1. POConfusing segmentation fault
    primarykey
    data
    text
    <p><strong>EDIT:</strong> I basically revamped the whole question so I could provide an executable example...</p> <p>I have been getting a segmentation fault that I can't figure out. Here is a compacted version of my code. I maintained the original class hierarchy even though some of the classes have no relevant methods since I think that it has something to do with my issue, especially after some of the comments I've been getting.</p> <pre><code>#import &lt;vector&gt; using namespace std; template&lt;class Data = float&gt; class Vector { // All pure virtual functions. }; template&lt;class Data&gt; class TranslationVector : public virtual Vector&lt;Data&gt; { // All pure virtual functions. }; template&lt;class Data&gt; class SimpleVector4 : public virtual Vector&lt;Data&gt; { public: SimpleVector4(const Data d0, const Data d1, const Data d2, const Data d3) { fData = new vector&lt;Data&gt; ; fData-&gt;push_back(d0); fData-&gt;push_back(d1); fData-&gt;push_back(d2); fData-&gt;push_back(d3); } vector&lt;Data&gt;* getData() { return (fData); } private: vector&lt;Data&gt;* fData; }; template&lt;class Data&gt; class SimpleTranslationVector4 : public SimpleVector4&lt;Data&gt; , public TranslationVector&lt;Data&gt; { public: SimpleTranslationVector4(const Data x, const Data y, const Data z, const Data w) : SimpleVector4&lt;Data&gt; (x, y, z, w) { } }; template&lt;class Data = float&gt; class Matrix { // All pure virtual functions. }; template&lt;class Data&gt; class TransformationMatrix : public virtual Matrix&lt;Data&gt; { // All pure virtual functions. virtual void translate(TranslationVector&lt;Data&gt;* const translation) = 0; }; template&lt;class Data&gt; class SimpleMatrix44 : public virtual Matrix&lt;Data&gt; { public: SimpleMatrix44() { fData = new vector&lt;Data&gt; (CELLS_IN_MATRIX, 0); setIdentity(); } vector&lt;Data&gt;* getData() { return (fData); } void setIdentity() { fData-&gt;at(0) = 1; fData-&gt;at(1) = 0; fData-&gt;at(2) = 0; fData-&gt;at(3) = 0; fData-&gt;at(4) = 0; fData-&gt;at(5) = 1; fData-&gt;at(6) = 0; fData-&gt;at(7) = 0; fData-&gt;at(8) = 0; fData-&gt;at(9) = 0; fData-&gt;at(10) = 1; fData-&gt;at(11) = 0; fData-&gt;at(12) = 0; fData-&gt;at(13) = 0; fData-&gt;at(14) = 0; fData-&gt;at(15) = 1; } private: static const int CELLS_IN_MATRIX = 16; vector&lt;Data&gt;* fData; }; template&lt;class Data&gt; class SimpleTransformationMatrix44 : public SimpleMatrix44&lt;Data&gt; , public TransformationMatrix&lt;Data&gt; { public: SimpleTransformationMatrix44() : SimpleMatrix44&lt;Data&gt; () { } void translate(TranslationVector&lt;Data&gt;* translation) { vector&lt;Data&gt; *data = SimpleMatrix44&lt;Data&gt;::getData(); vector&lt;Data&gt; *transData = ((SimpleVector4&lt;Data&gt;*) translation)-&gt;getData(); // The error occurs on this line: data-&gt;at(12) += data-&gt;at(0) * transData-&gt;at(0) + data-&gt;at(4) * transData-&gt;at(1) + data-&gt;at(8) * transData-&gt;at(2); data-&gt;at(13) += data-&gt;at(1) * transData-&gt;at(0) + data-&gt;at(5) * transData-&gt;at(1) + data-&gt;at(9) * transData-&gt;at(2); data-&gt;at(14) += data-&gt;at(2) * transData-&gt;at(0) + data-&gt;at(6) * transData-&gt;at(1) + data-&gt;at(10) * transData-&gt;at(2); data-&gt;at(15) += data-&gt;at(3) * transData-&gt;at(0) + data-&gt;at(7) * transData-&gt;at(1) + data-&gt;at(11) * transData-&gt;at(2); } }; int main(int argc, char** argv) { SimpleTransformationMatrix44&lt;float&gt; matrix1; matrix1.translate(new SimpleTranslationVector4&lt;float&gt; (0.0f, 10.0f, 0.0f, 1.0f)); return 0; } </code></pre> <p>I have commented in the code where the error occurs. From debugging I can see that it actually occurs in the <code>size()</code> function of <code>vector</code> and that <code>transData</code> has not been initialized. I can't for the life of me figure out why <code>transData</code> has not been initialized! Any ideas?</p> <p>Thanks,</p> <p>Gaz.</p>
    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.
 

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