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

Error when resizing the window #1

Open
Unique-Digital-Resources opened this issue Feb 10, 2024 · 5 comments
Open

Error when resizing the window #1

Unique-Digital-Resources opened this issue Feb 10, 2024 · 5 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Unique-Digital-Resources
Copy link
Owner

When I resize the window, sometimes get this message:
my_gui_v0.01/target/debug/examples/simple_window` mouse pixel: Color(4294967295) thread 'main' panicked at 'assertion failed: p.x >= 0 && p.x < self.width()', /home/admin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/skia-safe-0.68.0/src/core/pixmap.rs:161:9 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

After some modifications I got this:
thread 'main' panicked at 'index out of bounds: the len is 1114280 but the index is 1114282', ....../my_gui_v0.01/src/uwindow.rs:147:69 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

After some other modifications :
thread 'main' panicked at 'index out of bounds: the len is 787920 but the index is 787922', ......./my_gui_v0.01/src/uwindow.rs:147:69 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@Unique-Digital-Resources Unique-Digital-Resources added bug Something isn't working help wanted Extra attention is needed labels Feb 10, 2024
@leorsousa05
Copy link

This error is not happening on my code, could you send me the code you're trying to do with it?

@leorsousa05
Copy link

So i was trying to fix the code and looks like the pixmap variable on the uwindow.rs is broken. The variable has a length and the length of the variable (that is a &[u8]) is smaller then you are actually trying to access on:

for index in 0..(width * height) as usize {
 buffer[index] = pixmap[index * 4 + 2] as u32
| (pixmap[index * 4 + 1] as u32) << 8
| (pixmap[index * 4] as u32) << 16;
}

@leorsousa05
Copy link

So i tried removing this block of code and it started working properly... When you have free time, post an explanation of what this does!

@Unique-Digital-Resources
Copy link
Owner Author

Unique-Digital-Resources commented Feb 11, 2024

Screencast.2024-02-11.20.08.30.webm

As shown in the video, when you change the size of the window, the location of the button changes as required, but sometimes the error mentioned previously appears.
I think I understood the cause of the problem. When the size of the window is reduced, the canvas or the buffer does not shrink with it at the same speed. Therefore, when the mouse touches the button, which is what happened in the video, the size of the buffer has not yet decreased, so the window suddenly disappears due to this error.

@Unique-Digital-Resources
Copy link
Owner Author

So i tried removing this block of code and it started working properly... When you have free time, post an explanation of what this does!

I appreciate your suggestion, but I don't think this is the desired solution
The block you removed is responsible for converting the skia pixmap to the a buffer that is displayed on the screen

The problem lies in this block:

WindowEvent::CursorMoved { position,device_id , modifiers } 
                    => {
                        let x = position.x as i32;
                        let y = position.y as i32;
                        
                        if (x <=  screenoff_buffer.image_info().bounds().width()) &&(y <= screenoff_buffer.image_info().bounds().height()) && (x>0) && (y>0){
                            _current_pixel = screenoff_buffer.peek_pixels().unwrap().get_color((x,y));
                        }
                        if last_pixel != _current_pixel {
                            last_pixel = _current_pixel;
                            println!("mouse pixel: {last_pixel:?}");

The current possible solution is to add a condition to prevent the pixel color from being read when the window size is changed, but the problem remains that the buffer with the window does not change quickly enough (I do not know if this is due to the LXDE desktop environment for Linux, or due to a problem with the code structure).

I have added some information in the read.me file if you want to know briefly how the code works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants