   [D3D9] LPD3DXEFFECT trouble, simple access results in crash [SOLVED]
  I have a structure for my shaders:class Shader{private:bool CreateFromString ( IDirect3DDevice9 *device, std::string shader_code );public:LPD3DXEFFECT effect; // pointer to an ID3DXEffect (using ID3DXEffect *effect doesn't make a diff BTW)bool CreateFromFile ( IDirect3DDevice9 *device, std::string filename );bool CreateDefaultShader ( IDirect3DDevice9 *device );bool CreateNullShader ( IDirect3DDevice9 *device );};Take a look at the implementation of CreateFromFile:bool Shader::CreateFromFile ( IDirect3DDevice9 *device, std::string filename )// creates a shader from an external file{ID3DXBuffer *error_buffer = NULL;if ( FAILED ( D3DXCreateEffectFromFileA ( device, filename.c_str ( ), NULL, NULL, SHADER_COMPILE_FLAGS, NULL, &effect, &error_buffer ) ) ){std::stringstream s;s << "Failed to compile effect..." << std::endl << std::endl;s << "The following error(s) were encountered during compilation of '" << filename.c_str ( ) << "':" << std::endl << std::endl;s << ( const char *) error_buffer->GetBufferPointer ( ) << std::endl << std::endl;s << "Hit Ctrl+C to copy this message to the clipboard, then paste it when you report this error...";Error ( s.str ( ) );return false;}if ( !effect ){std::stringstream s;s << "Failed to create effect from file '" << filename.c_str ( ) << "'...";Error ( s.str ( ) );return false;}if ( FAILED ( effect->SetTechnique ( "EntryPoint" ) ) )// select technique{std::stringstream s;s << "Failed to set technique for effect '" << filename.c_str ( ) << "'...";Error ( s.str ( ) );return false;}return true;}Should be straight-forward. However, I discovered that the above function crashes whenever I even try to access the shader::effect member. The first call (to D3DXCreateEffectFromFileA) actually runs fine (doesn't FAIL or crash) but the line below (if ( !effect )) crashes. When I add even something like "effect = NULL;" as the first line in the function, it crashes there.I'm not exactly sure what could be causing this to be honest. What DOES work is when I define the effect member as a simple local variable in the function. This won't crash (but is obviously not what I'm looking for).Any ideas?[Edited by - d h k on April 3, 2010 7:59:14 PM]
  What's the "crash" you're getting? The exception code and information should tell you some specifics of the problem. Also if you're calling CreateFromFile on a pointer to a Shader, make sure that pointer is valid (and not NULL, or uninitialized).;  Wow, yeah that was it. Really embarrassing mistake to make... :p I actually had a system for the user to create custom shaders defined in the engine but forgot I didn't have it implemented so my std::vector<Shader*> had invalid Shader instances in it which caused the "weird" behavior.Thanks a ton, I think I'm slightly wiser now. :D   