Archive 17/01/2023.

Why Texture2D::Create() pointer is NULL?

simple

Hello I have something weird with my code.
I just code something like this for test:

void test()
{
	Urho3D::Engine *engine = new Urho3D::Engine(g_pEngineContext);
	Urho3D::VariantMap engineParameters;
	engineParameters["FrameLimiter"] = false;
	engineParameters["WindowTitle"] = "Engine";
	engineParameters["LogName"] = "Engine.log";
	engineParameters["FullScreen"] = false;
	engineParameters["ExternalWindow"] = 0;
	if (!engine->Initialize(engineParameters)) return;

	Urho3D::Texture2D *tex = new Urho3D::Texture2D(g_pEngineContext);
	tex->SetSize(2, 2, Urho3D::Graphics::GetRGBAFormat());
};
int main(int argc, char* argv[])
{
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
	g_pEngineContext = new Urho3D::Context();
	test();
	return 0;
};

My code crashing in line: “tex->SetSize(2, 2, Urho3D::Graphics::GetRGBAFormat());”
I just debug what exacly crashing, and here you go:
“Texture2D::Create() pointer is NULL. Why?”

simple

I solved this problem but this is really little weird:

I changed:
return Create();
to:
return Texture2D::Create();

and no longer crashing.

thebluefish

I assume this is in OpenGL? Or are you using the default DX11?

Visual Studio can tell you which function Create(); was originally pointed to. Please let us know where that points to.

Also is this the 1.5 stable release or from the master branch?

simple

OpenGL.

master branch.

I not really sure where exacly show me this. but tooltip show me (0x5417cbc0 where body of Texture2D::Create):

but ‘call edx’ still have NULL address.

simple

Well, i definately found a solution.
In OpenGL Application i need set Preprocessor definition: URHO3D_OPENGL
If i not set this then would cause heap corruptions etc…

Enhex

[quote=“simple”]Well, i definately found a solution.
In OpenGL Application i need set Preprocessor definition: URHO3D_OPENGL
If i not set this then would cause heap corruptions etc…[/quote]
Did u set Urho to use OpenGL in the cmake build options?

thebluefish

[quote=“simple”]Well, i definately found a solution.
In OpenGL Application i need set Preprocessor definition: URHO3D_OPENGL
If i not set this then would cause heap corruptions etc…[/quote]

That would be it! The graphics implementation headers are weird in that regard. I’m hoping this gets changed later down the road.