[SOLVED] ResourceCache and MDLs from inside a DLL

So, I am having trouble with the ResourceCache when it is access from inside a DLL. My setup is this:

I have an app, MyApp.exe, which links to Urho3D.dll (on Win64). I also have MyLib.dll, which is dynamically loaded at runtime. MyLib.dll is linked to Urho3D and contains various utility functions/components.

When I try code like:

Texture* tex = rc->GetResource<Texture>("Textures/TestHeightField.png");

I will always get a null reference, or a message saying that the resource could not be loaded (yes I have check all the paths).
Also, when I write stuff like:

Model* mdl = new Model(context);

My app crashes completely. In this post, the suggestion was to make sure the lib options are the same. I have verified that. Is there a specific reference in the code to where those defines make a difference? Is it simply a case of inserting #define URHO3D_OPENGL and #define URH3D_SSE (or whatever the right options are) somewhere in MyApp?

What you’ve described seems very familiar to something I’ve tried, but with no luck. My current setup uses a statically linked Urho3D lib with my game dll file.

Game.dll (links urho3d lib)
GameLauncher.exe (links game.dll)

You just have to make sure to create the Context/Application object within the Game.dll, otherwise (at least from my experience), you run into issues like the one you’ve described. I’ve seen where the Context, if created from the .exe (in my case), would be null or corrupt when passed and used throughout the dll.

Not sure if this relates to your issues, but I thought I’d share this experience so that perhaps it can give you some clues on solving your issues.

Thanks for the tip. Unfortunately, I’m still getting null resources…Strangely, this code will return the correct file:

SharedPtr<File> f = rc->GetFile("Models/Box.mdl");


Model* mdl = rc->GetResource<Model>("Models/Box.mdl");

returns null…

Could you debug it? ResourceCache::GetResource doesn’t look very complicated.

OK, so debugging dlls at runtime is not fun. BUT, it looks like the problem is here:

if (!Thread::IsMainThread())
    URHO3D_LOGERROR("Attempted to get resource " + name + " from outside the main thread");
    return 0;

That is, when calling the ResourceCache from inside the DLL, this check fails. Is this a bug? Or do DLLs get their own thread?

This explains a lot, actually!

Not sure how to fix it, though… any suggestions?

For now I’ve just commented out that check. Living on the edge…

Main Thread in Urho is just a thread that the Context has born. Could you ensure in debugger that you create Contex is the same thread as use cache?

UPD: You could probably override main thread via Thread::SetMainThread if you want to “move” Context into another thread.

Arg, you beat me too it (you’re too fast Eugene heh)