snprintf replacement: fix usage of ai_snprintf when snprintf is available.
parent
6bfdeb6a12
commit
d43a083dc1
|
@ -436,7 +436,7 @@ struct Mesh : public MeshWithSmoothingGroups<D3DS::Face>
|
||||||
|
|
||||||
// Generate a default name for the mesh
|
// Generate a default name for the mesh
|
||||||
char szTemp[128];
|
char szTemp[128];
|
||||||
::ai_snprintf(szTemp, 128, "UNNAMED_%i",iCnt++);
|
ai_snprintf(szTemp, 128, "UNNAMED_%i",iCnt++);
|
||||||
mName = szTemp;
|
mName = szTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -656,7 +656,7 @@ void PretransformVertices::Execute( aiScene* pScene)
|
||||||
{
|
{
|
||||||
aiNode* pcNode = *nodes = new aiNode();
|
aiNode* pcNode = *nodes = new aiNode();
|
||||||
pcNode->mParent = pScene->mRootNode;
|
pcNode->mParent = pScene->mRootNode;
|
||||||
pcNode->mName.length = ::sprintf(pcNode->mName.data,"light_%u",i);
|
pcNode->mName.length = ai_snprintf(pcNode->mName.data, MAXLEN, "light_%u",i);
|
||||||
pScene->mLights[i]->mName = pcNode->mName;
|
pScene->mLights[i]->mName = pcNode->mName;
|
||||||
}
|
}
|
||||||
// generate camera nodes
|
// generate camera nodes
|
||||||
|
|
|
@ -216,7 +216,7 @@ void SMDImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
|
||||||
void SMDImporter::LogErrorNoThrow(const char* msg)
|
void SMDImporter::LogErrorNoThrow(const char* msg)
|
||||||
{
|
{
|
||||||
char szTemp[1024];
|
char szTemp[1024];
|
||||||
sprintf(szTemp,"Line %u: %s",iLineNumber,msg);
|
ai_snprintf(szTemp,1024,"Line %u: %s",iLineNumber,msg);
|
||||||
DefaultLogger::get()->error(szTemp);
|
DefaultLogger::get()->error(szTemp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ void SMDImporter::LogWarning(const char* msg)
|
||||||
{
|
{
|
||||||
char szTemp[1024];
|
char szTemp[1024];
|
||||||
ai_assert(strlen(msg) < 1000);
|
ai_assert(strlen(msg) < 1000);
|
||||||
sprintf(szTemp,"Line %u: %s",iLineNumber,msg);
|
ai_snprintf(szTemp,1024,"Line %u: %s",iLineNumber,msg);
|
||||||
DefaultLogger::get()->warn(szTemp);
|
DefaultLogger::get()->warn(szTemp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -655,7 +655,7 @@ void SMDImporter::CreateOutputMaterials()
|
||||||
pScene->mMaterials[iMat] = pcMat;
|
pScene->mMaterials[iMat] = pcMat;
|
||||||
|
|
||||||
aiString szName;
|
aiString szName;
|
||||||
szName.length = (size_t)::sprintf(szName.data,"Texture_%u",iMat);
|
szName.length = (size_t)ai_snprintf(szName.data,MAXLEN,"Texture_%u",iMat);
|
||||||
pcMat->AddProperty(&szName,AI_MATKEY_NAME);
|
pcMat->AddProperty(&szName,AI_MATKEY_NAME);
|
||||||
|
|
||||||
if (aszTextures[iMat].length())
|
if (aszTextures[iMat].length())
|
||||||
|
|
|
@ -44,7 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
namespace Assimp {
|
//namespace Assimp {
|
||||||
|
|
||||||
/// @fn ai_snprintf
|
/// @fn ai_snprintf
|
||||||
/// @brief The portable version of the function snprintf ( C99 standard ), which works on visual studio compilers 2013 and earlier.
|
/// @brief The portable version of the function snprintf ( C99 standard ), which works on visual studio compilers 2013 and earlier.
|
||||||
|
@ -53,7 +53,7 @@ namespace Assimp {
|
||||||
/// @param format The format string
|
/// @param format The format string
|
||||||
/// @param ap The additional arguments.
|
/// @param ap The additional arguments.
|
||||||
/// @return The number of written characters if the buffer size was big enough. If an encoding error occurs, a negative number is returned.
|
/// @return The number of written characters if the buffer size was big enough. If an encoding error occurs, a negative number is returned.
|
||||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
//#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||||
|
|
||||||
inline int c99_ai_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap) {
|
inline int c99_ai_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap) {
|
||||||
int count(-1);
|
int count(-1);
|
||||||
|
@ -67,32 +67,35 @@ namespace Assimp {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int ai_snprintf(char *s, size_t n, const char *fmt, ...) {
|
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||||
|
|
||||||
|
inline int ai_snprintf(char *outBuf, size_t size, const char *format, ...) {
|
||||||
int count;
|
int count;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, format);
|
||||||
count = c99_ai_vsnprintf(outBuf, size, fmt, ap);
|
count = c99_ai_vsnprintf(outBuf, size, format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
#define ai_snprintf snprintf
|
||||||
inline int ai_snprintf(char *s, size_t n, const char *format, ...) {
|
/*inline int ai_snprintf(char *outBuf, size_t size, const char *format, ...) {
|
||||||
int count;
|
int count;
|
||||||
va_list ap;
|
va_list args;
|
||||||
va_start(ap, format);
|
va_start(args, format);
|
||||||
count = snprintf(s, n, format, ap);
|
count = c99_ai_vsnprintf(outBuf, size, format, args);
|
||||||
va_end(ap);
|
// count = ::snprintf(outBuf, size, format, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // Namespace Assimp
|
//} // Namespace Assimp
|
||||||
|
|
||||||
#endif // INCLUDED_AI_STRINGUTILS_H
|
#endif // INCLUDED_AI_STRINGUTILS_H
|
||||||
|
|
||||||
|
|
|
@ -842,7 +842,7 @@ inline void AssetMetadata::Read(Document& doc)
|
||||||
|
|
||||||
if (version != 1) {
|
if (version != 1) {
|
||||||
char msg[128];
|
char msg[128];
|
||||||
Assimp::ai_snprintf(msg, 128, "Unsupported glTF version: %d", version);
|
ai_snprintf(msg, 128, "Unsupported glTF version: %d", version);
|
||||||
throw DeadlyImportError(msg);
|
throw DeadlyImportError(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -925,7 +925,7 @@ inline void Asset::Load(const std::string& pFile, bool isBinary)
|
||||||
|
|
||||||
if (doc.HasParseError()) {
|
if (doc.HasParseError()) {
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
Assimp::ai_snprintf(buffer, 32, "%d", static_cast<int>(doc.GetErrorOffset()));
|
ai_snprintf(buffer, 32, "%d", static_cast<int>(doc.GetErrorOffset()));
|
||||||
throw DeadlyImportError(std::string("JSON parse error, offset ") + buffer + ": "
|
throw DeadlyImportError(std::string("JSON parse error, offset ") + buffer + ": "
|
||||||
+ GetParseError_En(doc.GetParseError()));
|
+ GetParseError_En(doc.GetParseError()));
|
||||||
}
|
}
|
||||||
|
@ -1029,9 +1029,9 @@ inline std::string Asset::FindUniqueID(const std::string& str, const char* suffi
|
||||||
if (it == mUsedIds.end()) break;
|
if (it == mUsedIds.end()) break;
|
||||||
|
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
int offset = Assimp::ai_snprintf(buffer, 256, "%s_", id.c_str());
|
int offset = ai_snprintf(buffer, 256, "%s_", id.c_str());
|
||||||
for (int i = 0; it != mUsedIds.end(); ++i) {
|
for (int i = 0; it != mUsedIds.end(); ++i) {
|
||||||
Assimp::ai_snprintf(buffer + offset, 256, "%d", i);
|
ai_snprintf(buffer + offset, 256, "%d", i);
|
||||||
|
|
||||||
id = buffer;
|
id = buffer;
|
||||||
it = mUsedIds.find(id);
|
it = mUsedIds.find(id);
|
||||||
|
|
|
@ -190,7 +190,7 @@ namespace glTF {
|
||||||
else {
|
else {
|
||||||
for (size_t i = 0; i < lst.size(); ++i) {
|
for (size_t i = 0; i < lst.size(); ++i) {
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
Assimp::ai_snprintf(buffer, 32, "%s_%d", semantic, int(i));
|
ai_snprintf(buffer, 32, "%s_%d", semantic, int(i));
|
||||||
attrs.AddMember(Value(buffer, w.mAl).Move(), Value(lst[i]->id, w.mAl).Move(), w.mAl);
|
attrs.AddMember(Value(buffer, w.mAl).Move(), Value(lst[i]->id, w.mAl).Move(), w.mAl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "assimp_view.h"
|
#include "assimp_view.h"
|
||||||
|
#include "StringUtils.h"
|
||||||
|
|
||||||
namespace AssimpView {
|
namespace AssimpView {
|
||||||
|
|
||||||
|
@ -385,7 +386,7 @@ void CBackgroundPainter::RecreateNativeResource()
|
||||||
if (!szEnd)szEnd = szPath.c_str()-1;
|
if (!szEnd)szEnd = szPath.c_str()-1;
|
||||||
|
|
||||||
char szTemp[1024];
|
char szTemp[1024];
|
||||||
sprintf(szTemp,"[ERROR] Unable to load background cubemap %s",szEnd+1);
|
ai_snprintf(szTemp,1024,"[ERROR] Unable to load background cubemap %s",szEnd+1);
|
||||||
|
|
||||||
CLogDisplay::Instance().AddEntry(szTemp,
|
CLogDisplay::Instance().AddEntry(szTemp,
|
||||||
D3DCOLOR_ARGB(0xFF,0xFF,0,0));
|
D3DCOLOR_ARGB(0xFF,0xFF,0,0));
|
||||||
|
@ -419,7 +420,7 @@ void CBackgroundPainter::RecreateNativeResource()
|
||||||
if (!szEnd)szEnd = szPath.c_str()-1;
|
if (!szEnd)szEnd = szPath.c_str()-1;
|
||||||
|
|
||||||
char szTemp[1024];
|
char szTemp[1024];
|
||||||
sprintf(szTemp,"[ERROR] Unable to load background texture %s",szEnd+1);
|
ai_snprintf(szTemp,1024,"[ERROR] Unable to load background texture %s",szEnd+1);
|
||||||
|
|
||||||
CLogDisplay::Instance().AddEntry(szTemp,
|
CLogDisplay::Instance().AddEntry(szTemp,
|
||||||
D3DCOLOR_ARGB(0xFF,0xFF,0,0));
|
D3DCOLOR_ARGB(0xFF,0xFF,0,0));
|
||||||
|
|
|
@ -41,6 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "assimp_view.h"
|
#include "assimp_view.h"
|
||||||
#include "AnimEvaluator.h"
|
#include "AnimEvaluator.h"
|
||||||
#include "SceneAnimator.h"
|
#include "SceneAnimator.h"
|
||||||
|
#include "StringUtils.h"
|
||||||
|
|
||||||
namespace AssimpView {
|
namespace AssimpView {
|
||||||
|
|
||||||
|
@ -168,13 +169,14 @@ int CDisplay::AddNodeToDisplayList(
|
||||||
{
|
{
|
||||||
iIndex += iDepth * 100;
|
iIndex += iDepth * 100;
|
||||||
}
|
}
|
||||||
else iIndex += iDepth * 10;
|
else
|
||||||
sprintf(chTemp,"Node %u",iIndex);
|
iIndex += iDepth * 10;
|
||||||
|
ai_snprintf(chTemp, MAXLEN,"Node %u",iIndex);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sprintf(chTemp,"%s",pcNode->mName.data);
|
ai_snprintf(chTemp, MAXLEN,"%s",pcNode->mName.data);
|
||||||
}
|
}
|
||||||
sprintf(chTemp+strlen(chTemp), iIndex ? " (%i)" : " (%i meshes)",pcNode->mNumMeshes);
|
ai_snprintf(chTemp+strlen(chTemp), MAXLEN- strlen(chTemp), iIndex ? " (%i)" : " (%i meshes)",pcNode->mNumMeshes);
|
||||||
|
|
||||||
TVITEMEXW tvi;
|
TVITEMEXW tvi;
|
||||||
TVINSERTSTRUCTW sNew;
|
TVINSERTSTRUCTW sNew;
|
||||||
|
@ -222,12 +224,12 @@ int CDisplay::AddMeshToDisplayList(unsigned int iIndex, HTREEITEM hRoot)
|
||||||
char chTemp[MAXLEN];
|
char chTemp[MAXLEN];
|
||||||
|
|
||||||
if(0 == pcMesh->mName.length) {
|
if(0 == pcMesh->mName.length) {
|
||||||
sprintf(chTemp,"Mesh %u",iIndex);
|
ai_snprintf(chTemp,MAXLEN,"Mesh %u",iIndex);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sprintf(chTemp,"%s",pcMesh->mName.data);
|
ai_snprintf(chTemp,MAXLEN,"%s",pcMesh->mName.data);
|
||||||
}
|
}
|
||||||
sprintf(chTemp+strlen(chTemp), iIndex ? " (%i)" : " (%i faces)",pcMesh->mNumFaces);
|
ai_snprintf(chTemp+strlen(chTemp),MAXLEN-strlen(chTemp), iIndex ? " (%i)" : " (%i faces)",pcMesh->mNumFaces);
|
||||||
|
|
||||||
TVITEMEXW tvi;
|
TVITEMEXW tvi;
|
||||||
TVINSERTSTRUCTW sNew;
|
TVINSERTSTRUCTW sNew;
|
||||||
|
@ -387,7 +389,7 @@ int CDisplay::AddTextureToDisplayList(unsigned int iType,
|
||||||
if ('*' == *szPath->data)
|
if ('*' == *szPath->data)
|
||||||
{
|
{
|
||||||
int iIndex = atoi(szPath->data+1);
|
int iIndex = atoi(szPath->data+1);
|
||||||
sprintf(chTempEmb,"Embedded #%i",iIndex);
|
ai_snprintf(chTempEmb,256,"Embedded #%i",iIndex);
|
||||||
sz = chTempEmb;
|
sz = chTempEmb;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -451,10 +453,10 @@ int CDisplay::AddTextureToDisplayList(unsigned int iType,
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
if (bIsExtraOpacity) {
|
if (bIsExtraOpacity) {
|
||||||
sprintf(chTemp,"%s %i (<copy of diffuse #1>)",szType,iIndex+1);
|
ai_snprintf(chTemp,512,"%s %i (<copy of diffuse #1>)",szType,iIndex+1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
sprintf(chTemp,"%s %i (%s)",szType,iIndex+1,sz);
|
ai_snprintf(chTemp,512,"%s %i (%s)",szType,iIndex+1,sz);
|
||||||
|
|
||||||
TVITEMEX tvi;
|
TVITEMEX tvi;
|
||||||
TVINSERTSTRUCT sNew;
|
TVINSERTSTRUCT sNew;
|
||||||
|
@ -540,11 +542,11 @@ int CDisplay::AddMaterialToDisplayList(HTREEITEM hRoot,
|
||||||
aiString szOut;
|
aiString szOut;
|
||||||
if (AI_SUCCESS != aiGetMaterialString(pcMat,AI_MATKEY_NAME,&szOut))
|
if (AI_SUCCESS != aiGetMaterialString(pcMat,AI_MATKEY_NAME,&szOut))
|
||||||
{
|
{
|
||||||
sprintf(chTemp,"Material %i",iIndex+1);
|
ai_snprintf(chTemp,512,"Material %i",iIndex+1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sprintf(chTemp,"%s (%i)",szOut.data,iIndex+1);
|
ai_snprintf(chTemp,512,"%s (%i)",szOut.data,iIndex+1);
|
||||||
}
|
}
|
||||||
TVITEMEXW tvi;
|
TVITEMEXW tvi;
|
||||||
TVINSERTSTRUCTW sNew;
|
TVINSERTSTRUCTW sNew;
|
||||||
|
@ -821,24 +823,24 @@ int CDisplay::FillDefaultStatistics(void)
|
||||||
}
|
}
|
||||||
// and fill the statistic edit controls
|
// and fill the statistic edit controls
|
||||||
char szOut[1024];
|
char szOut[1024];
|
||||||
sprintf(szOut,"%i",(int)iNumVert);
|
ai_snprintf(szOut,1024,"%i",(int)iNumVert);
|
||||||
SetDlgItemText(g_hDlg,IDC_EVERT,szOut);
|
SetDlgItemText(g_hDlg,IDC_EVERT,szOut);
|
||||||
sprintf(szOut,"%i",(int)iNumFaces);
|
ai_snprintf(szOut, 1024,"%i",(int)iNumFaces);
|
||||||
SetDlgItemText(g_hDlg,IDC_EFACE,szOut);
|
SetDlgItemText(g_hDlg,IDC_EFACE,szOut);
|
||||||
sprintf(szOut,"%i",(int)g_pcAsset->pcScene->mNumMaterials);
|
ai_snprintf(szOut, 1024,"%i",(int)g_pcAsset->pcScene->mNumMaterials);
|
||||||
SetDlgItemText(g_hDlg,IDC_EMAT,szOut);
|
SetDlgItemText(g_hDlg,IDC_EMAT,szOut);
|
||||||
sprintf(szOut,"%i",(int)g_pcAsset->pcScene->mNumMeshes);
|
ai_snprintf(szOut, 1024,"%i",(int)g_pcAsset->pcScene->mNumMeshes);
|
||||||
SetDlgItemText(g_hDlg,IDC_EMESH,szOut);
|
SetDlgItemText(g_hDlg,IDC_EMESH,szOut);
|
||||||
|
|
||||||
// need to get the number of nodes
|
// need to get the number of nodes
|
||||||
iNumVert = 0;
|
iNumVert = 0;
|
||||||
GetNodeCount(g_pcAsset->pcScene->mRootNode,&iNumVert);
|
GetNodeCount(g_pcAsset->pcScene->mRootNode,&iNumVert);
|
||||||
sprintf(szOut,"%i",(int)iNumVert);
|
ai_snprintf(szOut, 1024,"%i",(int)iNumVert);
|
||||||
SetDlgItemText(g_hDlg,IDC_ENODEWND,szOut);
|
SetDlgItemText(g_hDlg,IDC_ENODEWND,szOut);
|
||||||
|
|
||||||
// now get the number of unique shaders generated for the asset
|
// now get the number of unique shaders generated for the asset
|
||||||
// (even if the environment changes this number won't change)
|
// (even if the environment changes this number won't change)
|
||||||
sprintf(szOut,"%i", CMaterialManager::Instance().GetShaderCount());
|
ai_snprintf(szOut, 1024,"%i", CMaterialManager::Instance().GetShaderCount());
|
||||||
SetDlgItemText(g_hDlg,IDC_ESHADER,szOut);
|
SetDlgItemText(g_hDlg,IDC_ESHADER,szOut);
|
||||||
|
|
||||||
sprintf(szOut,"%.5f",(float)g_fLoadTime);
|
sprintf(szOut,"%.5f",(float)g_fLoadTime);
|
||||||
|
|
|
@ -41,6 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
#include "assimp_view.h"
|
#include "assimp_view.h"
|
||||||
|
#include "StringUtils.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -257,8 +258,9 @@ int LoadAsset(void)
|
||||||
g_pcAsset->mAnimator = new SceneAnimator( g_pcAsset->pcScene);
|
g_pcAsset->mAnimator = new SceneAnimator( g_pcAsset->pcScene);
|
||||||
|
|
||||||
// build a new caption string for the viewer
|
// build a new caption string for the viewer
|
||||||
char szOut[MAX_PATH + 10];
|
static const size_t Size = MAX_PATH + 10;
|
||||||
sprintf(szOut,AI_VIEW_CAPTION_BASE " [%s]",g_szFileName);
|
char szOut[Size];
|
||||||
|
ai_snprintf(szOut, Size,AI_VIEW_CAPTION_BASE " [%s]",g_szFileName);
|
||||||
SetWindowText(g_hDlg,szOut);
|
SetWindowText(g_hDlg,szOut);
|
||||||
|
|
||||||
// scale the asset vertices to fit into the viewer window
|
// scale the asset vertices to fit into the viewer window
|
||||||
|
|
Loading…
Reference in New Issue