sparkx 0 Report post Posted October 24, 2008 I am real new to c++ and really don't know much about it at all. I (always jumping right into a language) am having a problem while making a 3D loader. I have no clue how this works but I am basing my VRML loader off of a MS3D one I found. I can "dissect" the file just fine except for one thing. My struct seems to change every time I call it. Here is some code I’m not sure if you need more: struct Material{Â float m_ambient[8];Â float m_diffuse[8];};[...More code...]Material *def_ambientIntensity = new Material[1];memcpy( def_ambientIntensity[1].m_ambient, ambientIntensity->amb, 17);memcpy( def_ambientIntensity[1].m_diffuse , ambientIntensity->dif, 26);//Next my noob way to see what the variable is.MessageBox( NULL, (char*)def_ambientIntensity[1].m_diffuse, "Diffuse", MB_OK | MB_ICONERROR ); //GoodMessageBox( NULL, (char*)def_ambientIntensity[1].m_diffuse, "Diffuse", MB_OK | MB_ICONERROR ); //Bad? Anyone see a problem? I have no clue why the value of "def_ambientIntensity[1].m_diffuse" would change. Please keep your explanation as simple as possible I just started learning c++ about 4 days ago...Thanks,Sparkx Share this post Link to post Share on other sites
mitchellmckain 0 Report post Posted October 24, 2008 I am real new to c++ and really don't know much about it at all. I (always jumping right into a language) am having a problem while making a 3D loader. I have no clue how this works but I am basing my VRML loader off of a MS3D one I found. I can "dissect" the file just fine except for one thing. My struct seems to change every time I call it. Here is some code Iâm not sure if you need more: struct Material{Â float m_ambient[8];Â float m_diffuse[8];};[...More code...]Material *def_ambientIntensity = new Material[1];memcpy( def_ambientIntensity[1].m_ambient, ambientIntensity->amb, 17);memcpy( def_ambientIntensity[1].m_diffuse , ambientIntensity->dif, 26);//Next my noob way to see what the variable is.MessageBox( NULL, (char*)def_ambientIntensity[1].m_diffuse, "Diffuse", MB_OK | MB_ICONERROR ); //GoodMessageBox( NULL, (char*)def_ambientIntensity[1].m_diffuse, "Diffuse", MB_OK | MB_ICONERROR ); //Bad? Anyone see a problem? I have no clue why the value of "def_ambientIntensity[1].m_diffuse" would change. Please keep your explanation as simple as possible I just started learning c++ about 4 days ago...Thanks,Sparkx Well the array indices in c++ usually start at 0 not at 1, so it looks to me like you are referencing a nonexistent member of the array. This is one of the biggest troubles with c++ that you have to do all your own checking to make sure you don't reference nonexistent members of an array, for doing so will trigger no errors, you just get unpredicable results.I think that is it, but if not then it would nice to see what the output looks like, but my guess would be that you have found a bug in your compiler, because they did not quite anticipate how you are using this feature. In that case, what happens without using an array at all or a longer array? Share this post Link to post Share on other sites
sparkx 0 Report post Posted October 24, 2008 (edited) I think I solved that problem. Thanks for your help. All I did was change \"... ambientIntensity->amb, 17\" to \"ambientIntensity->amb, 8*1\" and it seemed to work but now I have a new problem. This is a little frustrating, seems like one thing after another. Now I have a \"GLfloat *\" and I need to convert it to a \"GLfloat\" but nothing I try works. I can\'t just do \"(GLfloat&) ...\" because it doesn\'t convert correctly or something (the color stays at 0.0 when GLfloat * is 1.0). I am trying to put in the colors with glColor3f(R, G, ; but it seems that I can\'t just put \"glColor3f((float) def_color->m_colorR ..)\". I get \"pointer value used where a floating point value was expected\". I read somewhere that I could fix this with an & but this doesn’t work either \"...&def_color->...\". What do I need to do to convert my \"pointer value\" to a \"floating point value\"? I have tried memcpy() and that won\'t convert it correctly and sometime it make my program un-responsive.Any Suggestions?Thanks,SparkxEdit: Smiles were on... Edited October 24, 2008 by sparkx (see edit history) Share this post Link to post Share on other sites