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
fix writing canvas past bounds #34
Conversation
I get a segfault when the canvas is too short, but not when it is too thin. |
Fixed by messing with some magic numbers in |
|
||
// draw fill in rest of window | ||
for (int x = max_x; x < view_max_x; x++) { | ||
for (int y = 0; y < view_max_y; y++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be:
for (int y = 0; y < view_max_y; y++) { | |
for (int y = max_y; y < view_max_y; y++) { |
src/frontend.c
Outdated
|
||
// draw canvas onto window | ||
for (int x = 0; x <= max_x; x++) { | ||
for (int y = 0; y <= max_y; y++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Starting at 0 and drawing at index +1 feels weird to me. Is this to get around the border width?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or is this compensating for the window border?
I took a fresh look at it today. Starting with a view at (0, 0) and a canvas of size 10x10 I only get a usable space of 9x9:
|
Looks like it's overwriting the last row/column:
To replicate: diff --git a/src/frontend.c b/src/frontend.c
index 17fc043..e592c2a 100644
--- a/src/frontend.c
+++ b/src/frontend.c
@@ -51,9 +51,12 @@ int main(int argc, char *argv[]) {
status_win = create_status_win();
cursor = cursor_new();
- Canvas *canvas = canvas_new_blank(1000, 1000);
+ Canvas *canvas = canvas_new_blank(10, 10);
+ canvas_scharyx(canvas, 0, 0, '0');
+ canvas_scharyx(canvas, 8, 8, '8');
+ canvas_scharyx(canvas, 9, 9, '9');
- view = view_new_startpos(canvas, 300, 300);
+ view = view_new_startpos(canvas, 0, 0);
// Enable keyboard mapping
keypad(canvas_win, TRUE);
@@ -71,7 +74,7 @@ int main(int argc, char *argv[]) {
State new_state = {
.ch_in = 0,
.cursor = cursor,
- .current_mode = MODE_INSERT,
+ .current_mode = MODE_PAN,
.last_arrow_direction = KEY_RIGHT,
.last_canvas_mode = MODE_INSERT,
.view = view, |
Yes I know my off-by-ones are messy. I'll clean it up today. |
I got it working in 5253be5 but it doesn't draw to the edge of the screen anymore. I think I have a fix almost done. |
Another bug I found was panning the screen past the end of the canvas overwrites the border. |
Ok, I cleaned it up and added bounds checking |
I fixed the "panning the screen past the end of the canvas overwrites the border." by checking for panning bounds. It will not let you pan past the edge anymore. |
Looks good, but now the cursor can move to the bottom and right border again. |
darn it. Let me dig deeper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me. Do you want to rebase before merging it in?
The function doesn't accept any parameters, but there weren't any compiler warnings. I just learned that `function()` is different from `function(void)` - the former is a prototype, not a function that accepts zero arguments. > Welcome to the C language, this is part of the legacy standard. https://stackoverflow.com/q/12643202
1979d04
to
1a0fa88
Compare
Looks like that had some duplicates of |
It works nicely.
Also fixed not writing last line on the right and bottom.
fixes #31