Do program development will be with the compiler to deal with, compiler optimization can give us code to run a certain increase, but there may be some unexpected problems. Here is the development time I encountered a pit, hoping to give you some reference
Speak directly to the code.
1 StaticUnsignedChar* S_data = NULL;//storing one frame of video data2 voiddorendering ()3 {4 //D3d11 Case5 if(S_devicetype = = Kunitygfxrendererd3d11 &&ensured3d11resourcesarecreated ())6 {7id3d11devicecontext* CTX =NULL;8G_d3d11device->getimmediatecontext (&ctx);9 Ten //update native texture from code One if(G_texturepointer) A { -id3d11texture2d* D3dtex = (id3d11texture2d*) G_texturepointer; -D3d11_texture2d_desc DESC;//Save Texture Information theD3dtex->getdesc (&DESC);//Get texture Information - - //unsigned char* s_data = new unsigned char[desc. Width*desc. HEIGHT*4]; - //char* errormessage = new char[80]; + Charerrormessage[ the]; - + if(!S_isinitrender) A { atS_data = (unsignedChar*)malloc(Desc. Width*desc. height*4); -Initrender (Desc. Width, Desc. Height,2, errormessage);//Initializing render parameters - if(NULL = =s_hthread) - { -unsigned threadID;//Thread ID -S_hthread = (HANDLE) _beginthreadex (NULL,0, Sfprefreshthread, NULL,0, &threadid);//new thread control rendering frequency in } - } to //Control Refresh Frequency + if(S_refreshflag &&S_isinitrender) - { the if( ! Rendertexturewithvideo (Desc. width*4, S_data)) * { $Releaserender (2);//Releasing render memoryPanax Notoginseng Free(s_data); -S_data =NULL; the } +Ctx->updatesubresource (D3dtex,0, NULL, S_data, Desc. width*4,0); AS_refreshflag =false; the } + } -Ctx->Release (); $}
In line 1th, we define a global pointer variable, allocate and free memory in the function dorendering, call this function multiple times, and allocate and release the memory of the pointer multiple times.
However, in the VC compiler, the second call to the function will cause an error, but not in the GCC compiler.
So, if you encounter the above situation, change a compiler to try!
Compiler optimization Trap--Global pointer multiple use exception