Well, first of all, I'm actually new to PureBasic ,though I made some cool additions to GPI's Charas.EX, original found on www.charas-project.net. Anyway, on the same project, I wanted to add some things to it, but the source didn't work on 3.90 of PB. Luckily somebody else fixed it (Chronic, on the Charas site). It compiles now, but there was some error that I wanted to fix.
If you downloaded the program (in the menu on top, click on Charas.EX) you can import your own resources you took from the Charas generators (currently only Charsets for Charas.EX). In the new source however there was a bug that when you did that the program would crash (actually, when you saved the imported resource). I've searched and added a lot of times the OpenWindow command, and I stumbled on the PokeB command in a for constructor. After long trying I found out that there probably wasn't enough memory to store, but I wondered how the AllocateMemory command worked.
mem=AllocateMemory(memory_import,#resource_uncompressed_size,0)
This was the original, that didn't work.
mem=AllocateMemory(memory_import)
This caused the crash.
mem=AllocateMemory(#resource_uncompressed_size)
This was the fix.
Well, I now am wondering, what does AllocateMemory do in the new version of PB? Does it now searches for the amount of free memory specified in the function? Because the help manual wasn't clear about that.
AllocateMemory: what changed?
Old Method:
New Method:
Code: Select all
*adr=AllocateMemory(Number,Length)
...
FreeMemory(Number)
Code: Select all
*Adr=AllocateMemory(Length)
...
FreeMemory(*Adr)
And after the allocating, it is a good idea to check the pointer you specified, to be sure it is not 0
If the pointer is 0, the memory could not be allocated, and attempting to use it or free it will cause a crash.
So:
[/code]
If the pointer is 0, the memory could not be allocated, and attempting to use it or free it will cause a crash.
So:
Code: Select all
*Adr=AllocateMemory(Length)
If *Adr
;use the memory here
FreeMemory(*Adr)
Else
;memory allocation failed
;put up error message or something
EndIf
Dr Pixel