The code for Picture Type Decision in NVENC

It seems I must close the “enablePTD” option(set it as 0) for async encode mode in nvenc api,I copy the code from the sample in nvencsdk v4.0 to do the picture type decision,but the output stream has some problem,I modify the code in my
experience,then the output stream is ok,I’m not sure the code I modified is corrent because it is just from my experience, not based on documents,so I post my code in below,and please tell me what I modified is correct? (note : I only modify the last line)

m_encPicParams.codecPicParams.h264PicParams.refPicFlag = 1;
m_encPicParams.codecPicParams.h264PicParams.displayPOCSyntax = 2 * m_uiFrameNumInGOP;
m_encPicParams.pictureType = ((m_uiFrameNumInGOP % nvEncCfg.gopLength)==0) ? NV_ENC_PIC_TYPE_IDR : NV_ENC_PIC_TYPE_P;
m_uiFrameNumInGOP = (m_uiFrameNumInGOP + 1) % nvEncCfg.gopLength; // it is the what I modified,the original code in sdk sample is “m_uiFrameNumInGOP++”