Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing sprites when using Element::Clone #191

Closed
Dakror opened this issue May 22, 2021 · 11 comments
Closed

Missing sprites when using Element::Clone #191

Dakror opened this issue May 22, 2021 · 11 comments
Labels
invalid This doesn't seem right

Comments

@Dakror
Copy link
Contributor

Dakror commented May 22, 2021

Since Clone creates a detached copy, Elements like ElementImage fail when looking up sprites that were registered in the stylesheet of the owner document.

Is there another way to currently duplicate an Element inside the same owner document or refresh the image after the fact? If not, it might be worth to add a clone->SetOwnerDocument(GetOwnerDocument()); inside Element::Clone

@mikke89
Copy link
Owner

mikke89 commented May 23, 2021

Does this only occur during drag cloning? Let me know if that fixes it.

We might also want to always reload the texture when attaching img to the document.

@mikke89 mikke89 reopened this May 23, 2021
@Dakror
Copy link
Contributor Author

Dakror commented May 23, 2021

I was manually calling Element::Clone in my application

@mikke89
Copy link
Owner

mikke89 commented May 23, 2021

Hm, that seemed to work fine when I tested it?

Does removing the texture_dirty condition in ElementImage::OnChildAdd fix the issue? If so I'm happy to do that.

@Dakror
Copy link
Contributor Author

Dakror commented May 23, 2021

Nope that did not fix it

@Dakror
Copy link
Contributor Author

Dakror commented May 23, 2021

This is the code I'm using, to essentially duplicate an element:

auto ptr = document->GetElementById("list-selection");
listSelection = document->AppendChild(ptr->Clone());

@mikke89
Copy link
Owner

mikke89 commented May 23, 2021

Hm, strange, that is working well for me. Here is the full example:

static const String document_img_rml = R"(
<rml>
<head>
	<title>Test</title>
	<link type="text/rcss" href="/assets/rml.rcss"/>
	<link type="text/rcss" href="/assets/invader.rcss"/>
	<style>
		body
		{
			left: 0;
			top: 0;
			right: 0;
			bottom: 0;
		}
	</style>
</head>

<body>
<img sprite="icon-invader"/>
</body>
</rml>
)";


TEST_CASE("Element.clone")
{
	Context* context = TestsShell::GetContext();
	REQUIRE(context);

	ElementDocument* document = context->LoadDocumentFromMemory(document_img_rml);
	REQUIRE(document);
	document->Show();

	context->Update();
	context->Render();

	Element* element = document->GetChild(0);
	REQUIRE(element);
	REQUIRE(element->GetTagName() == "img");

	document->AppendChild(element->Clone());

	TestsShell::RenderLoop();

	document->Close();
	TestsShell::ShutdownShell();
}

This renders two images side by side.

@Dakror
Copy link
Contributor Author

Dakror commented May 23, 2021

does it play a role that the element i require was inside a template included into the document maybe?

@mikke89
Copy link
Owner

mikke89 commented May 24, 2021

I'm not sure why that would be a problem, but it would be something to investigate.

@mikke89
Copy link
Owner

mikke89 commented Jun 18, 2021

@Dakror Did you ever figure this out?

@Dakror
Copy link
Contributor Author

Dakror commented Jun 20, 2021

I actually haven't continued to investigate it, busy with other things.

@mikke89
Copy link
Owner

mikke89 commented Jul 19, 2021

Closing this for now due to inactivity and inability to reproduce. Please do re-open if further investigations show issues in the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants