Jump to content
  • Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

150 Neutral

About CAPE

  • Rank
  1. Oh shit, there my education went out the window. You think you are learnig something, then just: "MINDBLOWN. You dont know anyting. Study harder, douchbag.", or something like that.   Well, seems like it will be back to the drawing board. But, as it is an editor, i guess I can have it not som optimized, i guess... (shiver through my body).   But dudes, thanks for the quick reply. Very helpful.
  2. I'm experience a bit of a small problem. I have implemented a render system with a dll in C++, where the user injects data (model/view/projection matricse, colors, meshes and so on) through void pointers. It is quite handy, as the graphic API's usually don't care about the data type, just the structure and size of the data.   I have been using it as a part of a game that we are developing, and it works out quite good. But now I am in the mood of developing a editor to the render system in C#, and am quite stumped.   When i link an XNA matrix as a pointer to the render dll, the pointer stays intact in teh transfer to the dll, where it is kept for future references when updated in the editor. But, the data that the pointer points at, is not. Here is some code:   Editor (C#): unsafe { [...] Matrix unsafeWorldMatrix = worldMatrix; void* worldMatrixPointer = (void*)(&unsafeWorldMatrix.M11); mRenderInterface.AddData("world", worldMatrixPointer); [...] } While the pointer is in the editor code, the world matrix pointer is able to convert back to the matrix in question, with the data intact. // The data is intact Matrix worldMatrix = *(Matrix*)worldMatrixPointer;   But as soon as I send it to the render system, using the dll, it looses the data. The pointer is the same, but teh first value just points to 0, and the rest is invalid. // Sending the data to the render system // The data is still intact here, and lets say that the pointer value is 0x0c52af32 [DllImport(DllName, SetLastError = true, CallingConvention = CallingConvention.Cdecl)] static extern unsafe void SetSharedData(System.String dataID, void* data); public unsafe void AddData(String id, void* dataPtr) { SetSharedData(id, dataPtr); } In the dll (c++) // Here the data is incorrect // the pointer is the same as before, but with CAPS letter (should not matter though)(0x0C52AF32) void hs::renderer::SetSharedData(const char* id, void* data) { AssertFunctionAndThrow(DirectXManager::GetInstance()->GetContent()->AddSharedData(id, data)); } Both systems are compiled using x86 / Win32 settings, and both are in debug.     What is the deal here? I am aware that it is lack of knowledge, as I´m very unfamiliar with the correct procedures here, but as far as i know, the data should not change, as long as the pointer is intact... BTW, when returning back from saving the pointer in the system, returning to the C# editor, the data in the pointer is intact.... WTF?   So, anyone who can point out my error? And as the rendersystem works as intended in the actual game, I know it is nothing wrong in the dll. And, teh only thing I do is storing the pointer in a map with a string identifier, so no interaction with hte actual pointer,   Any ideas are welcome. // CAPE
  3. I'm currently implementing a render system that are scriptable by XML. While the system is kinda awesome, so far, there is a bit of a steep learning curve for others to use the scripts. So I'm in the process to also implement a editor to the render system. The render system is implemented in C++, the editor will be implemented in Windows Forms (C#).   But im already stumped. I try to call the functions from the dll, but i get a PInvokeStackImbalance was detected. error. While reading on about the error, I realize that there is a problem with calling conventions and parameters, or, like the error tells me: This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature. But, there should match, or am I at fault here?   The call is the following: [DllImport(DllName, SetLastError = true)] static unsafe extern void Initalize(IntPtr hWnd); public unsafe void Start(IntPtr hWnd) { Initalize(hWnd); } The dll entry is as follow: namespace hs { namespace renderer { [...] __declspec(dllexport) void Initalize(HWND hWnd); [...] } } I'm, as I said, stumped. First i thought it was the namespaces, but as it finds the entry point, i don't think thats the problem.   Anyone out there who knows the correct way to do this? Much appreciated.
  4. I don't know how you store your texture pointers, but with an string identifier, i guessing map<string, TexturPtr>. This will need to be extended to support additional data to use as the identifier. Here u can implement a functor to create your own comparison function. Its easy to create, you can variate between different types, and is manageble. The problem that occurs is that that you will need to implement a key-struct for each type and combination. But as you currently need to create a load function for each resource type, this I guess will be a minor problem. struct TextureKey { string name; //texture name int sizeX, sizeY; //texture size bool operator<(const TextureKey &a, const TextureKey &b) { return std::strcmp(a.name, b.name) < 0 &amp;&amp; a.sizeX == b.sizeX &amp;&amp; a.sizeY == b.sizeY; } }; ... map<TextureKey, TexturePtr> mTexturePtrs; (Have not tried the above code, but it looks right )
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!