Sfoglia il codice sorgente

Fixed a nasty issue with stack allocation

Marko Pintera 12 anni fa
parent
commit
98445aab08

+ 2 - 0
BansheeMono/Include/BsMonoClass.h

@@ -32,6 +32,8 @@ namespace BansheeEngine
 		MonoField& getField(const CM::String& name);
 		MonoProperty& getProperty(const CM::String& name);
 
+		bool hasField(const CM::String& name) const;
+
 		MonoObject* invokeMethod(const CM::String& name, MonoObject* instance = nullptr, void** params = nullptr, CM::UINT32 numParams = 0);
 		void addInternalCall(const CM::String& name, const void* method);
 

+ 7 - 0
BansheeMono/Source/BsMonoClass.cpp

@@ -80,6 +80,13 @@ namespace BansheeEngine
 		return *newMethod;
 	}
 
+	bool MonoClass::hasField(const String& name) const
+	{
+		MonoClassField* field = mono_class_get_field_from_name(mClass, name.c_str());
+
+		return field != nullptr;
+	}
+
 	MonoField& MonoClass::getField(const String& name)
 	{
 		auto iterFind = mFields.find(name);

+ 5 - 1
BansheeMono/Source/BsMonoManager.cpp

@@ -71,7 +71,11 @@ namespace BansheeEngine
 			for(auto& meta : mTypeMetas)
 			{
 				meta->scriptClass = &assembly->getClass(meta->ns, meta->name);
-				meta->thisPtrField = &meta->scriptClass->getField("mCachedPtr");
+				if(meta->scriptClass->hasField("mCachedPtr"))
+					meta->thisPtrField = &meta->scriptClass->getField("mCachedPtr");
+				else
+					meta->thisPtrField = nullptr;
+
 				meta->initCallback();
 			}
 

+ 0 - 1
CamelotClient/Include/BsEditorApplication.h

@@ -22,7 +22,6 @@ namespace BansheeEditor
 
 		bool isProjectLoaded() const;
 		const CM::WString& getActiveProjectPath() const;
-		CM::WString getResourcesFolderPath() const;
 	private:
 		RenderSystemPlugin mActiveRSPlugin;
 

+ 4 - 1
CamelotClient/Include/BsProjectLibrary.h

@@ -48,7 +48,7 @@ namespace BansheeEditor
 		};
 
 	public:
-		ProjectLibrary();
+		ProjectLibrary(const CM::WString& projectFolder);
 		~ProjectLibrary();
 
 		void update();
@@ -63,6 +63,7 @@ namespace BansheeEditor
 		boost::signal<void(const CM::WString&)> onEntryRemoved;
 		boost::signal<void(const CM::WString&)> onEntryAdded;
 	private:
+		static const CM::WString RESOURCES_DIR;
 		static const CM::WString INTERNAL_RESOURCES_DIR;
 		static const CM::WString LIBRARY_ENTRIES_FILENAME;
 		static const CM::WString RESOURCE_MANIFEST_FILENAME;
@@ -70,6 +71,8 @@ namespace BansheeEditor
 		CM::ResourceManifestPtr mResourceManifest;
 		DirectoryEntry* mRootEntry;
 		CM::FolderMonitor* mMonitor;
+		CM::WString mProjectFolder;
+		CM::WString mResourcesFolder;
 
 		void save();
 		void load();

+ 1 - 6
CamelotClient/Source/BsEditorApplication.cpp

@@ -56,7 +56,7 @@ namespace BansheeEditor
 			inputConfig->registerButton("Paste", BC_V, VButtonModifier::Ctrl);
 		}
 
-		ProjectLibrary::startUp(cm_new<ProjectLibrary>());
+		ProjectLibrary::startUp(cm_new<ProjectLibrary>(getActiveProjectPath()));
 
 		//gApplication().loadPlugin("SBansheeEditor"); // Managed part of the editor
 
@@ -331,11 +331,6 @@ namespace BansheeEditor
 		return dummyProjectPath;
 	}
 
-	WString EditorApplication::getResourcesFolderPath() const
-	{
-		return getActiveProjectPath() + L"\\Resources";
-	}
-
 	const String& EditorApplication::getLibraryNameForRenderSystem(RenderSystemPlugin plugin)
 	{
 		static String DX11Name = "CamelotD3D11RenderSystem";

+ 17 - 20
CamelotClient/Source/BsProjectLibrary.cpp

@@ -1,5 +1,4 @@
 #include "BsProjectLibrary.h"
-#include "BsEditorApplication.h"
 #include "CmPath.h"
 #include "CmFileSystem.h"
 #include "CmException.h"
@@ -20,6 +19,7 @@ using namespace BansheeEngine;
 
 namespace BansheeEditor
 {
+	const WString ProjectLibrary::RESOURCES_DIR = L"Resources";
 	const WString ProjectLibrary::INTERNAL_RESOURCES_DIR = L"Internal\\Resources";
 	const WString ProjectLibrary::LIBRARY_ENTRIES_FILENAME = L"ProjectLibrary.asset";
 	const WString ProjectLibrary::RESOURCE_MANIFEST_FILENAME = L"ResourceManifest.asset";
@@ -36,14 +36,15 @@ namespace BansheeEditor
 		:LibraryEntry(path, name, parent, LibraryEntryType::Directory)
 	{ }
 
-	ProjectLibrary::ProjectLibrary()
-		:mRootEntry(nullptr)
+	ProjectLibrary::ProjectLibrary(const WString& projectFolder)
+		:mRootEntry(nullptr), mProjectFolder(projectFolder)
 	{
+		mResourcesFolder = Path::combine(mProjectFolder, RESOURCES_DIR);
 		mMonitor = cm_new<FolderMonitor>();
 
 		FolderChange folderChanges = (FolderChange)((UINT32)FolderChange::FileName | (UINT32)FolderChange::DirName | 
 				(UINT32)FolderChange::Creation | (UINT32)FolderChange::LastWrite);
-		mMonitor->startMonitor(EditorApplication::instance().getResourcesFolderPath(), true, folderChanges);
+		mMonitor->startMonitor(mResourcesFolder, true, folderChanges);
 
 		mMonitor->onAdded.connect(boost::bind(&ProjectLibrary::onMonitorFileModified, this, _1));
 		mMonitor->onRemoved.connect(boost::bind(&ProjectLibrary::onMonitorFileModified, this, _1));
@@ -56,7 +57,7 @@ namespace BansheeEditor
 
 		gResources().registerResourceManifest(mResourceManifest);
 
-		checkForModifications(EditorApplication::instance().getResourcesFolderPath());
+		checkForModifications(mResourcesFolder);
 	}
 
 	ProjectLibrary::~ProjectLibrary()
@@ -77,12 +78,12 @@ namespace BansheeEditor
 
 	void ProjectLibrary::checkForModifications(const CM::WString& fullPath)
 	{
-		if(!Path::includes(fullPath, EditorApplication::instance().getResourcesFolderPath()))
+		if(!Path::includes(fullPath, mResourcesFolder))
 			return; // Folder not part of our resources path, so no modifications
 
 		if(mRootEntry == nullptr)
 		{
-			WString resPath = EditorApplication::instance().getResourcesFolderPath();
+			WString resPath = mResourcesFolder;
 			mRootEntry = cm_new<DirectoryEntry>(resPath, Path::getFilename(resPath), nullptr);
 		}
 
@@ -375,7 +376,7 @@ namespace BansheeEditor
 				Importer::instance().reimport(importedResource, resource->path, importOptions);
 			}
 
-			WString internalResourcesPath = Path::combine(EditorApplication::instance().getActiveProjectPath(), INTERNAL_RESOURCES_DIR);
+			WString internalResourcesPath = Path::combine(mProjectFolder, INTERNAL_RESOURCES_DIR);
 			if(!FileSystem::isDirectory(internalResourcesPath))
 				FileSystem::createDir(internalResourcesPath);
 
@@ -466,7 +467,7 @@ namespace BansheeEditor
 		if(oldEntry != nullptr) // Moving from the Resources folder
 		{
 			// Moved outside of Resources, delete entry & meta file
-			if(!Path::includes(newPath, EditorApplication::instance().getResourcesFolderPath()))
+			if(!Path::includes(newPath, mResourcesFolder))
 			{
 				if(oldEntry->type == LibraryEntryType::File)
 				{
@@ -638,18 +639,16 @@ namespace BansheeEditor
 	{
 		std::shared_ptr<ProjectLibraryEntries> libEntries = ProjectLibraryEntries::create(*mRootEntry);
 
-		WString projectPath = EditorApplication::instance().getActiveProjectPath();
-
-		WString libraryEntriesPath = Path::combine(projectPath, INTERNAL_RESOURCES_DIR);
+		WString libraryEntriesPath = Path::combine(mProjectFolder, INTERNAL_RESOURCES_DIR);
 		libraryEntriesPath = Path::combine(libraryEntriesPath, LIBRARY_ENTRIES_FILENAME);
 
 		FileSerializer fs;
 		fs.encode(libEntries.get(), libraryEntriesPath);
 
-		WString resourceManifestPath = Path::combine(projectPath, INTERNAL_RESOURCES_DIR);
+		WString resourceManifestPath = Path::combine(mProjectFolder, INTERNAL_RESOURCES_DIR);
 		resourceManifestPath = Path::combine(resourceManifestPath, RESOURCE_MANIFEST_FILENAME);
 
-		ResourceManifest::save(mResourceManifest, resourceManifestPath, projectPath);
+		ResourceManifest::save(mResourceManifest, resourceManifestPath, mProjectFolder);
 	}
 
 	void ProjectLibrary::load()
@@ -660,12 +659,10 @@ namespace BansheeEditor
 			mRootEntry = nullptr;
 		}
 
-		WString projectPath = EditorApplication::instance().getActiveProjectPath();
-
-		WString resPath = EditorApplication::instance().getResourcesFolderPath();
+		WString resPath = mResourcesFolder;
 		mRootEntry = cm_new<DirectoryEntry>(resPath, Path::getFilename(resPath), nullptr);
 
-		WString libraryEntriesPath = Path::combine(projectPath, INTERNAL_RESOURCES_DIR);
+		WString libraryEntriesPath = Path::combine(mProjectFolder, INTERNAL_RESOURCES_DIR);
 		libraryEntriesPath = Path::combine(libraryEntriesPath, LIBRARY_ENTRIES_FILENAME);
 
 		if(FileSystem::exists(libraryEntriesPath))
@@ -716,12 +713,12 @@ namespace BansheeEditor
 		}
 
 		// Load resource manifest
-		WString resourceManifestPath = Path::combine(projectPath, INTERNAL_RESOURCES_DIR);
+		WString resourceManifestPath = Path::combine(mProjectFolder, INTERNAL_RESOURCES_DIR);
 		resourceManifestPath = Path::combine(resourceManifestPath, RESOURCE_MANIFEST_FILENAME);
 
 		if(FileSystem::exists(resourceManifestPath))
 		{
-			mResourceManifest = ResourceManifest::load(resourceManifestPath, projectPath);
+			mResourceManifest = ResourceManifest::load(resourceManifestPath, mProjectFolder);
 		}
 	}
 }

+ 2 - 2
CamelotUtility/Include/CmMemStack.h

@@ -28,7 +28,7 @@ namespace CamelotFramework
 			~MemBlock()
 			{ }
 
-			UINT8* alloc(UINT8 amount)
+			UINT8* alloc(UINT32 amount)
 			{
 				UINT8* freePtr = &mData[mFreePtr];
 				mFreePtr += amount;
@@ -36,7 +36,7 @@ namespace CamelotFramework
 				return freePtr;
 			}
 
-			void dealloc(UINT8* data, UINT8 amount)
+			void dealloc(UINT8* data, UINT32 amount)
 			{
 				mFreePtr -= amount;
 				assert((&mData[mFreePtr]) == data && "Out of order stack deallocation detected. Deallocations need to happen in order opposite of allocations.");

+ 5 - 1
CamelotUtility/Source/CmMemorySerializer.cpp

@@ -35,7 +35,11 @@ namespace CamelotFramework
 		UINT32 offset = 0;
 		for(auto iter = mBufferPieces.begin(); iter != mBufferPieces.end(); ++iter)
 		{
-			memcpy(resultBuffer + offset, iter->buffer, iter->size);
+			if(iter->size > 0)
+			{
+				memcpy(resultBuffer + offset, iter->buffer, iter->size);
+				offset += iter->size;
+			}
 		}
 
 		for(auto iter = mBufferPieces.rbegin(); iter != mBufferPieces.rend(); ++iter)

+ 4 - 0
ProjectLibrary.txt

@@ -3,6 +3,10 @@
   - Plus modal windows?
  - Implement Delete command for ResourceTreeView
 
+ TODO OTHER:
+  - Shutting down causes a crash in FolderMonitor
+  - During app startup I get ~10 first chance exceptions
+
 -------------------
 
 LOW PRIORITY