From bb62249f0c76124a7fd44398b90a76009182476c Mon Sep 17 00:00:00 2001 From: Yingying Wang Date: Wed, 4 Mar 2020 14:52:26 -0800 Subject: [PATCH 1/6] fix gltf2 exporter memory crash --- code/glTF2/glTF2Asset.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/glTF2/glTF2Asset.inl b/code/glTF2/glTF2Asset.inl index 35ecfa62d..2535207c4 100644 --- a/code/glTF2/glTF2Asset.inl +++ b/code/glTF2/glTF2Asset.inl @@ -535,7 +535,7 @@ inline void Buffer::Grow(size_t amount) // Shift operation is standard way to divide integer by 2, it doesn't cast it to float back and forth, also works for odd numbers, // originally it would look like: static_cast(capacity * 1.5f) - capacity = std::max(capacity + (capacity >> 1), byteLength + amount); + capacity = byteLength + amount; //wangyi fix crash std::max(capacity + (capacity >> 1), byteLength + amount); uint8_t* b = new uint8_t[capacity]; if (mData) memcpy(b, mData.get(), byteLength); From 06e40b98200b6e0ef34fd0ca8797184cf7e48ae8 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Lortie Date: Tue, 31 Mar 2020 17:22:56 -0400 Subject: [PATCH 2/6] Removed unneeded SceneDiffer.h includes. --- test/unit/ImportExport/utCOBImportExport.cpp | 1 - test/unit/ImportExport/utOFFImportExport.cpp | 1 - test/unit/ImportExport/utOgreImportExport.cpp | 1 - test/unit/ImportExport/utQ3BSPFileImportExport.cpp | 1 - test/unit/ut3DSImportExport.cpp | 1 - test/unit/utAMFImportExport.cpp | 1 - test/unit/utASEImportExport.cpp | 1 - test/unit/utArmaturePopulate.cpp | 1 - test/unit/utAssbinImportExport.cpp | 1 - test/unit/utB3DImportExport.cpp | 1 - test/unit/utDXFImporterExporter.cpp | 1 - test/unit/utFBXImporterExporter.cpp | 1 - test/unit/utM3DImportExport.cpp | 1 - test/unit/utPMXImporter.cpp | 1 - test/unit/utSTLImportExport.cpp | 1 - test/unit/utX3DImportExport.cpp | 1 - test/unit/utXImporterExporter.cpp | 1 - 17 files changed, 17 deletions(-) diff --git a/test/unit/ImportExport/utCOBImportExport.cpp b/test/unit/ImportExport/utCOBImportExport.cpp index bd0260c0d..e0f423d92 100644 --- a/test/unit/ImportExport/utCOBImportExport.cpp +++ b/test/unit/ImportExport/utCOBImportExport.cpp @@ -39,7 +39,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ -#include "SceneDiffer.h" #include "UnitTestPCH.h" #include diff --git a/test/unit/ImportExport/utOFFImportExport.cpp b/test/unit/ImportExport/utOFFImportExport.cpp index f8413e217..8e5de92d1 100644 --- a/test/unit/ImportExport/utOFFImportExport.cpp +++ b/test/unit/ImportExport/utOFFImportExport.cpp @@ -40,7 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "AbstractImportExportBase.h" -#include "SceneDiffer.h" #include "UnitTestPCH.h" #include #include diff --git a/test/unit/ImportExport/utOgreImportExport.cpp b/test/unit/ImportExport/utOgreImportExport.cpp index a63afbb99..0c25a82cb 100644 --- a/test/unit/ImportExport/utOgreImportExport.cpp +++ b/test/unit/ImportExport/utOgreImportExport.cpp @@ -40,7 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "AbstractImportExportBase.h" -#include "SceneDiffer.h" #include "UnitTestPCH.h" #include diff --git a/test/unit/ImportExport/utQ3BSPFileImportExport.cpp b/test/unit/ImportExport/utQ3BSPFileImportExport.cpp index cc3674850..e3dbf9f95 100644 --- a/test/unit/ImportExport/utQ3BSPFileImportExport.cpp +++ b/test/unit/ImportExport/utQ3BSPFileImportExport.cpp @@ -40,7 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "AbstractImportExportBase.h" -#include "SceneDiffer.h" #include "UnitTestPCH.h" #include diff --git a/test/unit/ut3DSImportExport.cpp b/test/unit/ut3DSImportExport.cpp index 7ffc66f1e..8debf6e86 100644 --- a/test/unit/ut3DSImportExport.cpp +++ b/test/unit/ut3DSImportExport.cpp @@ -40,7 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "AbstractImportExportBase.h" -#include "SceneDiffer.h" #include "UnitTestPCH.h" #include diff --git a/test/unit/utAMFImportExport.cpp b/test/unit/utAMFImportExport.cpp index 0cbd59a67..e4406702a 100644 --- a/test/unit/utAMFImportExport.cpp +++ b/test/unit/utAMFImportExport.cpp @@ -40,7 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "AbstractImportExportBase.h" -#include "SceneDiffer.h" #include "UnitTestPCH.h" #include diff --git a/test/unit/utASEImportExport.cpp b/test/unit/utASEImportExport.cpp index 5d138dcd5..2ddc81f29 100644 --- a/test/unit/utASEImportExport.cpp +++ b/test/unit/utASEImportExport.cpp @@ -40,7 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "AbstractImportExportBase.h" -#include "SceneDiffer.h" #include "UnitTestPCH.h" #include diff --git a/test/unit/utArmaturePopulate.cpp b/test/unit/utArmaturePopulate.cpp index d00330ced..8a6036239 100644 --- a/test/unit/utArmaturePopulate.cpp +++ b/test/unit/utArmaturePopulate.cpp @@ -42,7 +42,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "UnitTestPCH.h" #include "AbstractImportExportBase.h" -#include "SceneDiffer.h" #include #include diff --git a/test/unit/utAssbinImportExport.cpp b/test/unit/utAssbinImportExport.cpp index d679914a9..a1f8c7511 100644 --- a/test/unit/utAssbinImportExport.cpp +++ b/test/unit/utAssbinImportExport.cpp @@ -39,7 +39,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ #include "AbstractImportExportBase.h" -#include "SceneDiffer.h" #include "UnitTestPCH.h" #include #include diff --git a/test/unit/utB3DImportExport.cpp b/test/unit/utB3DImportExport.cpp index e79d87084..2f213aa8c 100644 --- a/test/unit/utB3DImportExport.cpp +++ b/test/unit/utB3DImportExport.cpp @@ -40,7 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "AbstractImportExportBase.h" -#include "SceneDiffer.h" #include "UnitTestPCH.h" #include diff --git a/test/unit/utDXFImporterExporter.cpp b/test/unit/utDXFImporterExporter.cpp index c9791db7f..79289f82a 100644 --- a/test/unit/utDXFImporterExporter.cpp +++ b/test/unit/utDXFImporterExporter.cpp @@ -40,7 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "AbstractImportExportBase.h" -#include "SceneDiffer.h" #include "UnitTestPCH.h" #include diff --git a/test/unit/utFBXImporterExporter.cpp b/test/unit/utFBXImporterExporter.cpp index 89b94dddc..30a26d99d 100644 --- a/test/unit/utFBXImporterExporter.cpp +++ b/test/unit/utFBXImporterExporter.cpp @@ -40,7 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "AbstractImportExportBase.h" -#include "SceneDiffer.h" #include "UnitTestPCH.h" #include diff --git a/test/unit/utM3DImportExport.cpp b/test/unit/utM3DImportExport.cpp index 0fc5d2ff3..3fb98a4a2 100644 --- a/test/unit/utM3DImportExport.cpp +++ b/test/unit/utM3DImportExport.cpp @@ -41,7 +41,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "AbstractImportExportBase.h" -#include "SceneDiffer.h" #include "UnitTestPCH.h" #include diff --git a/test/unit/utPMXImporter.cpp b/test/unit/utPMXImporter.cpp index d70c4c64e..5ab7a9d6a 100644 --- a/test/unit/utPMXImporter.cpp +++ b/test/unit/utPMXImporter.cpp @@ -40,7 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "UnitTestPCH.h" -#include "SceneDiffer.h" #include "AbstractImportExportBase.h" #include "MMD/MMDImporter.h" diff --git a/test/unit/utSTLImportExport.cpp b/test/unit/utSTLImportExport.cpp index 94417e260..2b4c3873f 100644 --- a/test/unit/utSTLImportExport.cpp +++ b/test/unit/utSTLImportExport.cpp @@ -40,7 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "AbstractImportExportBase.h" -#include "SceneDiffer.h" #include "UnitTestPCH.h" #include diff --git a/test/unit/utX3DImportExport.cpp b/test/unit/utX3DImportExport.cpp index c19842895..5b3438d91 100644 --- a/test/unit/utX3DImportExport.cpp +++ b/test/unit/utX3DImportExport.cpp @@ -40,7 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "AbstractImportExportBase.h" -#include "SceneDiffer.h" #include "UnitTestPCH.h" #include diff --git a/test/unit/utXImporterExporter.cpp b/test/unit/utXImporterExporter.cpp index 07f857227..39cda4e35 100644 --- a/test/unit/utXImporterExporter.cpp +++ b/test/unit/utXImporterExporter.cpp @@ -40,7 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "AbstractImportExportBase.h" -#include "SceneDiffer.h" #include "UnitTestPCH.h" #include From c21a1ffffaf7a9fec6955ee436f8d69ba7d68c7a Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 1 Apr 2020 11:16:39 +0200 Subject: [PATCH 3/6] Remove comments to increase readability --- code/glTF2/glTF2Asset.inl | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/code/glTF2/glTF2Asset.inl b/code/glTF2/glTF2Asset.inl index 781267e7e..a41e62e5c 100644 --- a/code/glTF2/glTF2Asset.inl +++ b/code/glTF2/glTF2Asset.inl @@ -508,18 +508,23 @@ inline size_t Buffer::AppendData(uint8_t *data, size_t length) { } inline void Buffer::Grow(size_t amount) { - if (amount <= 0) return; + if (amount <= 0) { + return; + } + + // Capacity is big enough if (capacity >= byteLength + amount) { byteLength += amount; return; } - // Shift operation is standard way to divide integer by 2, it doesn't cast it to float back and forth, also works for odd numbers, - // originally it would look like: static_cast(capacity * 1.5f) - capacity = byteLength + amount; //wangyi fix crash std::max(capacity + (capacity >> 1), byteLength + amount); + // Just allocate data which we need + capacity = byteLength + amount; uint8_t *b = new uint8_t[capacity]; - if (mData) memcpy(b, mData.get(), byteLength); + if (nullptr != mData) { + memcpy(b, mData.get(), byteLength); + } mData.reset(b, std::default_delete()); byteLength += amount; } From 56e2f2e37e399896054c73a1c3c2cd42df061dce Mon Sep 17 00:00:00 2001 From: Marc-Antoine Lortie Date: Thu, 2 Apr 2020 14:19:16 -0400 Subject: [PATCH 4/6] Fixed /W4 compile warnings in sample SimpleOpenGL. --- samples/SimpleOpenGL/Sample_SimpleOpenGL.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/SimpleOpenGL/Sample_SimpleOpenGL.c b/samples/SimpleOpenGL/Sample_SimpleOpenGL.c index a8a3532cf..e1a9be0d9 100644 --- a/samples/SimpleOpenGL/Sample_SimpleOpenGL.c +++ b/samples/SimpleOpenGL/Sample_SimpleOpenGL.c @@ -245,7 +245,7 @@ void do_motion (void) static int frames = 0; int time = glutGet(GLUT_ELAPSED_TIME); - angle += (time-prev_time)*0.01; + angle += (time-prev_time)*0.01f; prev_time = time; frames += 1; From e67ddd0ca101227210ceed24e44e3ced6faa128d Mon Sep 17 00:00:00 2001 From: Marc-Antoine Lortie Date: Fri, 3 Apr 2020 09:43:01 -0400 Subject: [PATCH 5/6] Fixed /W4 compile warnings in sample SimpleTexturedDirectx11. --- .../SimpleTexturedDirectx11/Mesh.h | 48 ++++++++--------- .../SimpleTexturedDirectx11/ModelLoader.cpp | 52 +++++++++---------- .../SimpleTexturedDirectx11/ModelLoader.h | 12 ++--- .../SimpleTexturedDirectx11/main.cpp | 26 +++++----- 4 files changed, 69 insertions(+), 69 deletions(-) diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/Mesh.h b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/Mesh.h index 125b3e585..e0169ee1a 100644 --- a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/Mesh.h +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/Mesh.h @@ -31,40 +31,40 @@ struct Texture { class Mesh { public: - std::vector vertices; - std::vector indices; - std::vector textures; - ID3D11Device *dev; + std::vector vertices_; + std::vector indices_; + std::vector textures_; + ID3D11Device *dev_; Mesh(ID3D11Device *dev, const std::vector& vertices, const std::vector& indices, const std::vector& textures) : - vertices(vertices), - indices(indices), - textures(textures), - dev(dev), - VertexBuffer(nullptr), - IndexBuffer(nullptr) { - this->setupMesh(this->dev); + vertices_(vertices), + indices_(indices), + textures_(textures), + dev_(dev), + VertexBuffer_(nullptr), + IndexBuffer_(nullptr) { + this->setupMesh(this->dev_); } void Draw(ID3D11DeviceContext *devcon) { UINT stride = sizeof(VERTEX); UINT offset = 0; - devcon->IASetVertexBuffers(0, 1, &VertexBuffer, &stride, &offset); - devcon->IASetIndexBuffer(IndexBuffer, DXGI_FORMAT_R32_UINT, 0); + devcon->IASetVertexBuffers(0, 1, &VertexBuffer_, &stride, &offset); + devcon->IASetIndexBuffer(IndexBuffer_, DXGI_FORMAT_R32_UINT, 0); - devcon->PSSetShaderResources(0, 1, &textures[0].texture); + devcon->PSSetShaderResources(0, 1, &textures_[0].texture); - devcon->DrawIndexed(static_cast(indices.size()), 0, 0); + devcon->DrawIndexed(static_cast(indices_.size()), 0, 0); } void Close() { - SafeRelease(VertexBuffer); - SafeRelease(IndexBuffer); + SafeRelease(VertexBuffer_); + SafeRelease(IndexBuffer_); } private: // Render data - ID3D11Buffer *VertexBuffer, *IndexBuffer; + ID3D11Buffer *VertexBuffer_, *IndexBuffer_; // Functions // Initializes all the buffer objects/arrays @@ -73,15 +73,15 @@ private: D3D11_BUFFER_DESC vbd; vbd.Usage = D3D11_USAGE_IMMUTABLE; - vbd.ByteWidth = static_cast(sizeof(VERTEX) * vertices.size()); + vbd.ByteWidth = static_cast(sizeof(VERTEX) * vertices_.size()); vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER; vbd.CPUAccessFlags = 0; vbd.MiscFlags = 0; D3D11_SUBRESOURCE_DATA initData; - initData.pSysMem = &vertices[0]; + initData.pSysMem = &vertices_[0]; - hr = dev->CreateBuffer(&vbd, &initData, &VertexBuffer); + hr = dev->CreateBuffer(&vbd, &initData, &VertexBuffer_); if (FAILED(hr)) { Close(); throw std::runtime_error("Failed to create vertex buffer."); @@ -89,14 +89,14 @@ private: D3D11_BUFFER_DESC ibd; ibd.Usage = D3D11_USAGE_IMMUTABLE; - ibd.ByteWidth = static_cast(sizeof(UINT) * indices.size()); + ibd.ByteWidth = static_cast(sizeof(UINT) * indices_.size()); ibd.BindFlags = D3D11_BIND_INDEX_BUFFER; ibd.CPUAccessFlags = 0; ibd.MiscFlags = 0; - initData.pSysMem = &indices[0]; + initData.pSysMem = &indices_[0]; - hr = dev->CreateBuffer(&ibd, &initData, &IndexBuffer); + hr = dev->CreateBuffer(&ibd, &initData, &IndexBuffer_); if (FAILED(hr)) { Close(); throw std::runtime_error("Failed to create index buffer."); diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp index 806320144..94df02c47 100644 --- a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp @@ -1,12 +1,12 @@ #include "ModelLoader.h" ModelLoader::ModelLoader() : - dev(nullptr), - devcon(nullptr), - meshes(), - directory(), - textures_loaded(), - hwnd(nullptr) { + dev_(nullptr), + devcon_(nullptr), + meshes_(), + directory_(), + textures_loaded_(), + hwnd_(nullptr) { // empty } @@ -25,11 +25,11 @@ bool ModelLoader::Load(HWND hwnd, ID3D11Device * dev, ID3D11DeviceContext * devc if (pScene == NULL) return false; - this->directory = filename.substr(0, filename.find_last_of("/\\")); + this->directory_ = filename.substr(0, filename.find_last_of("/\\")); - this->dev = dev; - this->devcon = devcon; - this->hwnd = hwnd; + this->dev_ = dev; + this->devcon_ = devcon; + this->hwnd_ = hwnd; processNode(pScene->mRootNode, pScene); @@ -37,8 +37,8 @@ bool ModelLoader::Load(HWND hwnd, ID3D11Device * dev, ID3D11DeviceContext * devc } void ModelLoader::Draw(ID3D11DeviceContext * devcon) { - for (int i = 0; i < meshes.size(); ++i ) { - meshes[i].Draw(devcon); + for (int i = 0; i < meshes_.size(); ++i ) { + meshes_[i].Draw(devcon); } } @@ -88,7 +88,7 @@ Mesh ModelLoader::processMesh(aiMesh * mesh, const aiScene * scene) { textures.insert(textures.end(), diffuseMaps.begin(), diffuseMaps.end()); } - return Mesh(dev, vertices, indices, textures); + return Mesh(dev_, vertices, indices, textures); } std::vector ModelLoader::loadMaterialTextures(aiMaterial * mat, aiTextureType type, std::string typeName, const aiScene * scene) { @@ -98,9 +98,9 @@ std::vector ModelLoader::loadMaterialTextures(aiMaterial * mat, aiTextu mat->GetTexture(type, i, &str); // Check if texture was loaded before and if so, continue to next iteration: skip loading a new texture bool skip = false; - for (UINT j = 0; j < textures_loaded.size(); j++) { - if (std::strcmp(textures_loaded[j].path.c_str(), str.C_Str()) == 0) { - textures.push_back(textures_loaded[j]); + for (UINT j = 0; j < textures_loaded_.size(); j++) { + if (std::strcmp(textures_loaded_[j].path.c_str(), str.C_Str()) == 0) { + textures.push_back(textures_loaded_[j]); skip = true; // A texture with the same filepath has already been loaded, continue to next one. (optimization) break; } @@ -113,34 +113,34 @@ std::vector ModelLoader::loadMaterialTextures(aiMaterial * mat, aiTextu texture.texture = getTextureFromModel(scene, textureindex); } else { std::string filename = std::string(str.C_Str()); - filename = directory + '/' + filename; + filename = directory_ + '/' + filename; std::wstring filenamews = std::wstring(filename.begin(), filename.end()); - hr = CreateWICTextureFromFile(dev, devcon, filenamews.c_str(), nullptr, &texture.texture); + hr = CreateWICTextureFromFile(dev_, devcon_, filenamews.c_str(), nullptr, &texture.texture); if (FAILED(hr)) - MessageBox(hwnd, "Texture couldn't be loaded", "Error!", MB_ICONERROR | MB_OK); + MessageBox(hwnd_, "Texture couldn't be loaded", "Error!", MB_ICONERROR | MB_OK); } texture.type = typeName; texture.path = str.C_Str(); textures.push_back(texture); - this->textures_loaded.push_back(texture); // Store it as texture loaded for entire model, to ensure we won't unnecesery load duplicate textures. + this->textures_loaded_.push_back(texture); // Store it as texture loaded for entire model, to ensure we won't unnecesery load duplicate textures. } } return textures; } void ModelLoader::Close() { - for (auto& t : textures_loaded) + for (auto& t : textures_loaded_) t.Release(); - for (int i = 0; i < meshes.size(); i++) { - meshes[i].Close(); + for (int i = 0; i < meshes_.size(); i++) { + meshes_[i].Close(); } } void ModelLoader::processNode(aiNode * node, const aiScene * scene) { for (UINT i = 0; i < node->mNumMeshes; i++) { aiMesh* mesh = scene->mMeshes[node->mMeshes[i]]; - meshes.push_back(this->processMesh(mesh, scene)); + meshes_.push_back(this->processMesh(mesh, scene)); } for (UINT i = 0; i < node->mNumChildren; i++) { @@ -179,9 +179,9 @@ ID3D11ShaderResourceView * ModelLoader::getTextureFromModel(const aiScene * scen int* size = reinterpret_cast(&scene->mTextures[textureindex]->mWidth); - hr = CreateWICTextureFromMemory(dev, devcon, reinterpret_cast(scene->mTextures[textureindex]->pcData), *size, nullptr, &texture); + hr = CreateWICTextureFromMemory(dev_, devcon_, reinterpret_cast(scene->mTextures[textureindex]->pcData), *size, nullptr, &texture); if (FAILED(hr)) - MessageBox(hwnd, "Texture couldn't be created from memory!", "Error!", MB_ICONERROR | MB_OK); + MessageBox(hwnd_, "Texture couldn't be created from memory!", "Error!", MB_ICONERROR | MB_OK); return texture; } diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.h b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.h index 18ad03fa0..9d3ed50b3 100644 --- a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.h +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.h @@ -25,12 +25,12 @@ public: void Close(); private: - ID3D11Device *dev; - ID3D11DeviceContext *devcon; - std::vector meshes; - std::string directory; - std::vector textures_loaded; - HWND hwnd; + ID3D11Device *dev_; + ID3D11DeviceContext *devcon_; + std::vector meshes_; + std::string directory_; + std::vector textures_loaded_; + HWND hwnd_; void processNode(aiNode* node, const aiScene* scene); Mesh processMesh(aiMesh* mesh, const aiScene* scene); diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp index 781fe89e5..1ef4a401f 100644 --- a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp @@ -56,7 +56,7 @@ const char g_szClassName[] = "directxWindowClass"; static std::string g_ModelPath; UINT width, height; -HWND hwnd = nullptr; +HWND g_hwnd = nullptr; // ------------------------------------------------------------ // DirectX Variables @@ -120,8 +120,8 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) return 0; } -int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, - LPWSTR lpCmdLine, int nCmdShow) +int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, + LPWSTR /*lpCmdLine*/, int nCmdShow) { int argc; LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); @@ -182,7 +182,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, RECT wr = { 0,0, SCREEN_WIDTH, SCREEN_HEIGHT }; AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); - hwnd = CreateWindowEx( + g_hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, g_szClassName, " Simple Textured Directx11 Sample ", @@ -191,21 +191,21 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, NULL, NULL, hInstance, NULL ); - if (hwnd == NULL) + if (g_hwnd == NULL) { MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } - ShowWindow(hwnd, nCmdShow); - UpdateWindow(hwnd); + ShowWindow(g_hwnd, nCmdShow); + UpdateWindow(g_hwnd); width = wr.right - wr.left; height = wr.bottom - wr.top; try { - InitD3D(hInstance, hwnd); + InitD3D(hInstance, g_hwnd); while (true) { @@ -225,17 +225,17 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, CleanD3D(); return static_cast(msg.wParam); } catch (const std::exception& e) { - MessageBox(hwnd, e.what(), TEXT("Error!"), MB_ICONERROR | MB_OK); + MessageBox(g_hwnd, e.what(), TEXT("Error!"), MB_ICONERROR | MB_OK); CleanD3D(); return EXIT_FAILURE; } catch (...) { - MessageBox(hwnd, TEXT("Caught an unknown exception."), TEXT("Error!"), MB_ICONERROR | MB_OK); + MessageBox(g_hwnd, TEXT("Caught an unknown exception."), TEXT("Error!"), MB_ICONERROR | MB_OK); CleanD3D(); return EXIT_FAILURE; } } -void InitD3D(HINSTANCE hinstance, HWND hWnd) +void InitD3D(HINSTANCE /*hinstance*/, HWND hWnd) { HRESULT hr; @@ -362,7 +362,7 @@ void InitD3D(HINSTANCE hinstance, HWND hWnd) } // Note this tutorial doesn't handle full-screen swapchains so we block the ALT+ENTER shortcut - dxgiFactory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER); + dxgiFactory->MakeWindowAssociation(g_hwnd, DXGI_MWA_NO_ALT_ENTER); dxgiFactory->Release(); @@ -564,7 +564,7 @@ void InitGraphics() m_View = XMMatrixLookAtLH(Eye, At, Up); ourModel = new ModelLoader; - if (!ourModel->Load(hwnd, dev, devcon, g_ModelPath)) + if (!ourModel->Load(g_hwnd, dev, devcon, g_ModelPath)) Throwanerror("Model couldn't be loaded"); } From 4bae1d2596572c4103cdfce5ab7a6eb6067d346f Mon Sep 17 00:00:00 2001 From: Marc-Antoine Lortie Date: Fri, 3 Apr 2020 10:07:44 -0400 Subject: [PATCH 6/6] Fixed warning C4018: '<': signed/unsigned mismatch --- .../SimpleTexturedDirectx11/ModelLoader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp index 94df02c47..c8f86bbec 100644 --- a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp @@ -37,7 +37,7 @@ bool ModelLoader::Load(HWND hwnd, ID3D11Device * dev, ID3D11DeviceContext * devc } void ModelLoader::Draw(ID3D11DeviceContext * devcon) { - for (int i = 0; i < meshes_.size(); ++i ) { + for (size_t i = 0; i < meshes_.size(); ++i ) { meshes_[i].Draw(devcon); } } @@ -132,7 +132,7 @@ void ModelLoader::Close() { for (auto& t : textures_loaded_) t.Release(); - for (int i = 0; i < meshes_.size(); i++) { + for (size_t i = 0; i < meshes_.size(); i++) { meshes_[i].Close(); } }