Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » BufferPainter Clip Crash - Fatal error: Invalid memory access!
BufferPainter Clip Crash - Fatal error: Invalid memory access! [message #59548] Wed, 25 January 2023 17:02 Go to next message
devilsclaw is currently offline  devilsclaw
Messages: 72
Registered: August 2022
Member
So I found a combination of actions that will cause clipping to return a invalid pointer in RenderPath of BufferPainter.

1) Use Clip and Draw out side of the clip region
2) Attach the object to follow the mouse
3) Repeatedly move the mouse in and out of the window frame at the bottom in random locations up to 30 seconds.

Attached is an example app in code of how to cause it.

Below is the offending code and the output of it getting a corrupted pointer

Y2 is the pointer getting corrupted. Also I am on linux

if(clip.GetCount()) {
  printf("DC: Y1 = %i\n", y);
  const ClippingLine& s = clip.Top()[y];
  printf("DC: Y2 = %p\n", &s);
  if(s.IsEmpty()) {
    goto empty;
  }
  printf("DC: Y3 = %i\n", y);
  if(!s.IsFull()) {
    mf.Set(rg, s);
    rf = &mf;
  }
}

Results:
DC: Y1 = 525
DC: Y2 = 0x7f82b80571e8
DC: Y1 = 526
DC: Y2 = 0x7f82b80571f0
DC: Y3 = 526
DC: Y1 = 525
DC: Y2 = 0x7f82b80571e8
DC: Y1 = 526
DC: Y2 = 0x7f82b80571f0
DC: Y3 = 526
DC: MouseMove: x 16620 : y 16906 : 00000000
DC: Y1 = 526
DC: Y2 = 0x1070

[Updated on: Wed, 25 January 2023 17:02]

Report message to a moderator

Re: BufferPainter Clip Crash - Fatal error: Invalid memory access! [message #59549 is a reply to message #59548] Wed, 25 January 2023 18:13 Go to previous messageGo to next message
devilsclaw is currently offline  devilsclaw
Messages: 72
Registered: August 2022
Member
I also tested it in windows and it just straight crashes the program with out the crash handler like in linux.
Re: BufferPainter Clip Crash - Fatal error: Invalid memory access! [message #59551 is a reply to message #59548] Mon, 30 January 2023 17:49 Go to previous messageGo to next message
devilsclaw is currently offline  devilsclaw
Messages: 72
Registered: August 2022
Member
So I am guessing no one has a clue how to fix it or could not confirm the bug ?

I am more of a C programmer and not sure how to handle a situation where the pointer should always be valid because of the object& return type and it not being valid.
Re: BufferPainter Clip Crash - Fatal error: Invalid memory access! [message #59774 is a reply to message #59548] Thu, 13 April 2023 16:08 Go to previous messageGo to next message
zouql is currently offline  zouql
Messages: 15
Registered: December 2020
Location: China
Promising Member
hi, all.
I also encountered this exception. If someone has solved this problem, please help.

index.php?t=getfile&id=6797&private=0
Re: BufferPainter Clip Crash - Fatal error: Invalid memory access! [message #59775 is a reply to message #59548] Thu, 13 April 2023 16:36 Go to previous messageGo to next message
devilsclaw is currently offline  devilsclaw
Messages: 72
Registered: August 2022
Member
I re-wrote how the mouse handler works by overloading it and it fixed the problem for me

below is sample code of what I did. I made it work more like how the java mouse handling works

//Header
enum {
  MOUSE_NONE   = (0 << 0),
  MOUSE_LEFT   = (1 << 1),
  MOUSE_RIGHT  = (1 << 2),
  MOUSE_MIDDLE = (1 << 3),
  MOUSE_DOWN   = (1 << 4),
  MOUSE_UP     = (1 << 5),
  MOUSE_DOUBLE = (1 << 6),
  MOUSE_TRIPLE = (1 << 7),
  MOUSE_DRAG   = (1 << 8),
  MOUSE_MOVE   = (1 << 9),
};

virtual Upp::Image MouseEvent(int event, Upp::Point p, int zdelta, Upp::dword keyflags);
virtual void MouseWheel(Upp::Point p, int zdelta, Upp::dword keyflags);
virtual void MouseClicked(Upp::Point p, Upp::dword keyflags, unsigned int type, int clicks);
virtual void MouseReleased(Upp::Point p, Upp::dword keyflags, unsigned int type);
virtual void MouseDrag(Upp::Point p, Upp::dword keyflags, unsigned int type);
virtual void MouseMove(Upp::Point p, Upp::dword keyflags);
virtual void MouseEnter(Upp::Point p, Upp::dword keyflags);
virtual void MouseLeave();

//CPP
void frm_network::MouseWheel(Upp::Point p, int zdelta, Upp::dword keyflags) {
}

void frm_network::MouseEnter(Upp::Point p, Upp::dword keyflags) {
}

void frm_network::MouseLeave() {
}

void frm_network::MouseDrag(Upp::Point p, Upp::dword keyflags,  unsigned int type) {
}

void frm_network::MouseClicked(Upp::Point pos, Upp::dword keyflags, unsigned int type, int clicks) {
}

void frm_network::MouseReleased(Upp::Point p, Upp::dword keyflags, unsigned int type) {
}

void frm_network::MouseMove(Upp::Point p, Upp::dword keyflags) {
}

Upp::Image frm_network::MouseEvent(int event, Upp::Point p, int zdelta, Upp::dword keyflags) {
  int mouse_event = event & ~(LEFT | RIGHT | MIDDLE);
  Upp::dword mouse_flags =  keyflags & (Upp::K_MOUSELEFT | Upp::K_MOUSERIGHT | Upp::K_MOUSEMIDDLE | Upp::K_MOUSEDOUBLE | Upp::K_MOUSETRIPLE);
  if(mouse_event == REPEAT || mouse_event == CURSORIMAGE) {
    goto exit;
  }

  switch(mouse_event) {
    case MOUSEWHEEL: {
      MouseWheel(p, zdelta, keyflags);
      goto exit;
    }
    case MOUSEENTER: {
      MouseEnter(p, keyflags);
      goto exit;
    }
    case MOUSELEAVE: {
      MouseLeave();
      goto exit;
    }
  }

  if(mouse_event != UP && keyflags == 0) {
    mouse_state = 0;
  }

  if((mouse_state & MOUSE_UP)) {
    mouse_state = 0;
  }

  //Add rejection of other buttons once one is in use
  if((mouse_state & MOUSE_LEFT) != 0 && (keyflags & (Upp::K_MOUSERIGHT | Upp::K_MOUSEMIDDLE)) != 0) {
    goto exit;
  }
  if((mouse_state & MOUSE_RIGHT) != 0 && (keyflags & (Upp::K_MOUSELEFT | Upp::K_MOUSEMIDDLE)) != 0) {
    goto exit;
  }
  if((mouse_state & MOUSE_MIDDLE) != 0 && (keyflags & (Upp::K_MOUSERIGHT | Upp::K_MOUSELEFT)) != 0) {
    goto exit;
  }

  if((keyflags & Upp::K_MOUSELEFT) == Upp::K_MOUSELEFT) {
    mouse_state |= MOUSE_LEFT;
  } else if((keyflags & Upp::K_MOUSERIGHT) == Upp::K_MOUSERIGHT) {
    mouse_state |= MOUSE_RIGHT;
  } else if((keyflags & Upp::K_MOUSEMIDDLE) == Upp::K_MOUSEMIDDLE) {
    mouse_state |= MOUSE_MIDDLE;
  }

  if((keyflags & Upp::K_MOUSETRIPLE) == Upp::K_MOUSETRIPLE) {
    mouse_state &= ~(MOUSE_DOWN | MOUSE_UP | MOUSE_DOUBLE | MOUSE_MOVE | MOUSE_DRAG);
    mouse_state |= MOUSE_TRIPLE;
  } else if((keyflags & Upp::K_MOUSEDOUBLE) == Upp::K_MOUSEDOUBLE) {
    mouse_state &= ~(MOUSE_DOWN | MOUSE_UP  | MOUSE_MOVE | MOUSE_DRAG);
    mouse_state |= MOUSE_DOUBLE;
  } else if(mouse_event == DOWN) {
    mouse_state &= ~(MOUSE_UP | MOUSE_MOVE | MOUSE_MOVE | MOUSE_DRAG);
    mouse_state |= MOUSE_DOWN;
  } else if(mouse_event == UP) {
    mouse_state &= ~(MOUSE_DOWN | MOUSE_DOUBLE | MOUSE_TRIPLE | MOUSE_MOVE | MOUSE_DRAG);
    mouse_state |= MOUSE_UP;
  } else if(mouse_event == DRAG) {
    mouse_state &= ~(MOUSE_DOWN | MOUSE_MOVE | MOUSE_UP);
    mouse_state |= MOUSE_DRAG;
  } else if((mouse_state & MOUSE_DRAG) != MOUSE_DRAG) {
    mouse_state |= MOUSE_MOVE;
  }

  if(mouse_state & MOUSE_DRAG) {
    MouseDrag(p, keyflags, mouse_state & (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE));
  } else if((mouse_state & MOUSE_DOWN) && (mouse_state & MOUSE_MOVE) == 0) {
    MouseClicked(p, keyflags, mouse_state & (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE), 1);
  } else if((mouse_state & MOUSE_DOUBLE) && (mouse_state & MOUSE_MOVE) == 0) {
    MouseClicked(p, keyflags, mouse_state & (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE), 2);
  } else if((mouse_state & MOUSE_TRIPLE) && (mouse_state & MOUSE_MOVE) == 0) {
    MouseClicked(p, keyflags, mouse_state & (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE), 3);
  } else if(mouse_state & MOUSE_UP) {
    MouseReleased(p, keyflags, mouse_state & (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE));
  } else if(mouse_state & MOUSE_MOVE) {
    MouseMove(p, keyflags);
  }

exit:
  return Upp::Image::Arrow();
}

Re: BufferPainter Clip Crash - Fatal error: Invalid memory access! [message #59776 is a reply to message #59548] Thu, 13 April 2023 16:39 Go to previous messageGo to next message
devilsclaw is currently offline  devilsclaw
Messages: 72
Registered: August 2022
Member
Yes I know goto statements are frowned on in C++. I come from the linux kernel coding style and embeded programming mostly.

It should be easy enough to remove goto statements.
Re: BufferPainter Clip Crash - Fatal error: Invalid memory access! [message #59777 is a reply to message #59776] Thu, 13 April 2023 18:16 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13994
Registered: November 2005
Ultimate Member
devilsclaw wrote on Thu, 13 April 2023 16:39
Yes I know goto statements are frowned on in C++. I come from the linux kernel coding style and embeded programming mostly.

It should be easy enough to remove goto statements.


goto statements are considered fine in U++, as long as they are the most direct solution to the problem...

However, would it be possible to post complete testcase to save my time? Smile (ideally .zip of whole package)

EDIT: Appologies, I missed it. All is fine now, investigating.

Mirek

[Updated on: Thu, 13 April 2023 18:18]

Report message to a moderator

Re: BufferPainter Clip Crash - Fatal error: Invalid memory access! [message #59778 is a reply to message #59777] Fri, 14 April 2023 05:27 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13994
Registered: November 2005
Ultimate Member
Hopefully fixed in master.

Mirek
icon14.gif  Re: BufferPainter Clip Crash - Fatal error: Invalid memory access! [message #59781 is a reply to message #59778] Sat, 15 April 2023 10:16 Go to previous messageGo to next message
zouql is currently offline  zouql
Messages: 15
Registered: December 2020
Location: China
Promising Member
hi, mirek
The program is working well now, thank you very much.
The clip.Top() may be sometimes empty.
index.php?t=getfile&id=6798&private=0
  • Attachment: render.jpg
    (Size: 40.89KB, Downloaded 470 times)
Re: BufferPainter Clip Crash - Fatal error: Invalid memory access! [message #59782 is a reply to message #59781] Sun, 16 April 2023 08:02 Go to previous message
mirek is currently offline  mirek
Messages: 13994
Registered: November 2005
Ultimate Member
Correct, that is exactly what I have fixed:

https://github.com/ultimatepp/ultimatepp/commit/a2cefe2b6648 006f308c237649f802dc095a4a6d
Previous Topic: Image::GetDPI() doesn't return Size(0, 0)
Next Topic: Mouse Interaction with UI causes Paint to not function
Goto Forum:
  


Current Time: Thu Jul 18 18:26:23 CEST 2024

Total time taken to generate the page: 0.02584 seconds