Page 1 of 1

Qt - FreeImage problem

Posted: Tue Mar 10, 2020 8:26 pm
by wombats
I'm not sure if this is a bug. I can't figure out why it's happening.

Code: Select all

If IsImage(*dat\image)
  FreeImage(*dat\image)
EndIf
I'm getting 'Invalid memory access.' on the second line. I can't reproduce it in a small example, but surely the IsImage command should prevent FreeImage from even being executed if the image is invalid? It does the same whether 'image' is an integer or pointer in the structure. No problem at all on macOS and Windows.

Re: Qt - FreeImage problem

Posted: Wed Mar 11, 2020 8:15 am
by #NULL
Buggy threading code can cause weird things like that.

Re: Qt - FreeImage problem

Posted: Wed Mar 11, 2020 8:25 am
by wombats
I only use threads in certain parts of my program, and no threads are started when I encounter this problem.

Re: Qt - FreeImage problem

Posted: Wed Mar 11, 2020 5:54 pm
by #NULL
Then I don't know. Maybe try if the Purifier detects anything wrong.

Re: Qt - FreeImage problem

Posted: Wed Mar 11, 2020 8:09 pm
by wombats
The Purifier doesn't tell me anything. I'm at a loss here. It works fine on Windows and macOS, so all I can think is there's a problem with the FreeImage command, but I can't reproduce it outside of my project.

Re: Qt - FreeImage problem

Posted: Wed Mar 11, 2020 11:01 pm
by mk-soft
No problem here with QT ...

Code: Select all

Structure udtData
  Image.i
EndStructure

Global *MyData.udtData = AllocateStructure(udtData)

*MyData\Image = LoadImage(#PB_Any, #PB_Compiler_Home + "examples/sources/Data/PureBasic.bmp")
If *MyData\Image = 0
  Debug "Error load image"
  End
EndIf
  
If OpenWindow(0, 0, 0, 240, 100, "ButtonImage", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonImageGadget(0, 10, 10, 220, 60, ImageID(*MyData\Image))
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

FreeImage(*MyData\Image)

FreeStructure(*MyData)

Delay(100)


Re: Qt - FreeImage problem

Posted: Thu Mar 12, 2020 11:39 am
by Fred
I took a look at the code, and I don't see something obvious. On Linux, you can compile your app with the '-ds' switch (to keep debug symbol) and run it with 'purify' or 'gdb' to try to get a more precise info.

Re: Qt - FreeImage problem

Posted: Thu Mar 12, 2020 1:10 pm
by wombats
I think I've narrowed it down to a problem with CopyImage.