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

display_png crashes display with bad file path #825

Closed
okyeron opened this issue Apr 30, 2019 · 5 comments
Closed

display_png crashes display with bad file path #825

okyeron opened this issue Apr 30, 2019 · 5 comments
Assignees
Labels
bug

Comments

@okyeron
Copy link
Contributor

@okyeron okyeron commented Apr 30, 2019

Using display_png with a path to a non-existent file looks like it crashes the display in some fashion (screen goes black, no other script will show anything) .

;restart brings things back to normal.

Suggestions on debug?

@okyeron
Copy link
Contributor Author

@okyeron okyeron commented May 1, 2019

So here's a possible solution.
screen.c #L139
instead of checking image == NULL, we look at the status instead

        image = cairo_image_surface_create_from_png (filename);
	//if(image == NULL) { return; }
	if (cairo_surface_status (image)) { 
		fprintf(stderr, "display_png: %s\n", cairo_status_to_string (cairo_surface_status(image))); 
		cairo_surface_destroy (image);
		return; 
	}

FWIW - it appears the surface created will still be a valid pointer, but it will return a pointer to a "nil" surface for an error like file not found. I don't understand if that "nil" pointer actually == NULL though.

Also - What I'm not sure about - does the surface need to be destroyed before return;? (Or the filename pointer free'd?)

@tehn
Copy link
Member

@tehn tehn commented Jun 23, 2019

@okyeron did your solution work? please PR if so!

@tehn tehn closed this Jun 23, 2019
@tehn tehn reopened this Jun 23, 2019
@okyeron
Copy link
Contributor Author

@okyeron okyeron commented Jun 24, 2019

I'll need to revisit this and refresh my memory. Will see if I can get a PR together shortly.

Again - was looking for feedback here about: " does the surface need to be destroyed before return;? (Or the filename pointer free'd?)"

@tehn
Copy link
Member

@tehn tehn commented Jun 24, 2019

not sure if the image needs to be destroyed. perhaps try a sizeof and see if memory was allocated?

@okyeron
Copy link
Contributor Author

@okyeron okyeron commented Jun 27, 2019

if file not found, cairo_surface_get_reference_count () returned zero, so I think that means there's no image to be destroyed.

PR sent. Fix prints an error on file not found, does not crash.

@okyeron okyeron closed this Jul 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants