[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: pointers problem
[Thread Prev] | [Thread Next]
- Subject: Re: pointers problem
- From: Lee <t.lee.davidson@xxxxxxxxx>
- Date: Fri, 16 Oct 2026 15:21:30 -0400
- To: user@xxxxxxxxxxxxxxxxxxxxxx
On 10/16/26 1:26 PM, valaquarus wrote:
Dear Lee,I did what you suggest, changing QRcode_encodeString external function to return a QRcode structure, I can confirm it works fine but I don't know how to free the pointer and the program tells it to me : free() invalid pointer at closing.
You would also need to change the QRcode_free to accept a QRcode structure: Private Extern QRcode_free(qrcode As QRcode) and change where it is freed to: QRcode_free(stQr)I have attached my modified MQRCode.module. But, again I stress that your version and mine both work on my system and do not cause a segmentation fault.
I declare now Library "libqrencode:4.1.1" as my machine doesn't find 4.1.1-4.
The "-4" at the end of the version number is only a Manjaro package build number. That will not be found searching packages with pacman. I got that number using `pacman -Qi qrencode`.
You might want to leave the Library specification as: Library "libqrencode:4". Otherwise, if the library version changes, your program won't run even though the new version is quite likely fully compatible with your code. I mentioned the version number only for comparison between yours and mine.
the program displays an incorrect QR code according to one online generatorHow did you catch it?
I was mistaken. I tried one online QR code generator and it produced a different image than your program did. I have now tried three different online generators, and all three produced different images from each other. But, they all decode to the same text, as does yours.
I made a break point and turn around step by step, I have a segmentation where it wants and when it wants , not in one place and not only one place.
I would put a break point on the two lines that call the external functions. When the program stops, go ahead and continue using the Run button. Perhaps then you can determine which one is the culprit.
-- Lee --- Gambas User List Netiquette [https://gambaswiki.org/wiki/doc/netiquette] ---- --- Gambas User List Archive [https://lists.gambas-basic.org/archive/user] ----
' Gambas module file
Library "libqrencode:4"
Public Struct QRcode
iVersion As Integer ' 4 x
iWidth As Integer ' 4 x
pData As Pointer
End Struct
Private Extern QRcode_encodeString(sText As String, iVersion As Integer, iLevel As Integer, iHint As Integer, iCasesensitive As Integer) As QRcode
Private Extern QRcode_free(qrcode As QRcode)
Public Function GenerateQR(sTextToEncode As String, iLargeur As Integer) As Image
Dim stQr As QRcode
Dim img As Image
Dim iX, iY, iInd As Integer
Dim ibByte As Byte
Dim pixelSize As Float
Dim targetSize As Integer = iLargeur
If IsNull(sTextToEncode) = True Then
Message.Error(("QR code generation stopped!"))
Return Null
Endif
stQr = QRcode_encodeString(sTextToEncode, 0, 2, 2, 1) ' iHint = 2 ou 3
If stQr = Null Then
Message.Error(("QR code generation failed!"))
Return Null
Endif
pixelSize = targetSize / stQr.iWidth
img = New Image(targetSize, targetSize, Color.White, Image.Standard)
Paint.Begin(img)
For iY = 0 To stQr.iWidth - 1
For iX = 0 To stQr.iWidth - 1
ibByte = Byte@(stQr.pData + iInd)
If (ibByte And 1) Then
Paint.Brush = Paint.Color(Color.Black)
Paint.Rectangle(iX * pixelSize, iY * pixelSize, pixelSize, pixelSize)
Paint.Fill
End If
Inc iInd
Next
Next
Paint.End
If Error Then
Message.Error(Str(Error.Class) & ", code : " & Error.Code & ", " & Str(Error.Backtrace) & " à " & Error.Where & "\n" & Error.Text)
Endif
QRcode_free(stQr)
Return img
End Function
| pointers problem | valaquarus <valaquarus@xxxxxxxxx> |
| Re: pointers problem | Lee <t.lee.davidson@xxxxxxxxx> |
| Re: pointers problem | valaquarus <valaquarus@xxxxxxxxx> |