Hello,
I have identified an error in the SDK. Here is the series of events that yields the error:
1. Allocate memory in main thread via malloc.
2. Start a thread and pass in a pointer to the allocated memory.
3. Thread runs and uses allocated memory just fine.
4. Thread Deletes allocated memory via free (THREAD CRASHES)
When my thread attempts to delete the memory, it crashes. I have experimented and determined that the address of the memory allocated in main does not match the address of the memory passed into the created thread. I print the addess in both locations and they differ.
But... I know the memoy being used by my thread has somehow been initialized correctly. When I allocate the memory in main, I initilize it with ceratin values. When the thread accesses its copy of the memory, it has all the correct values. Only when I attempt to free this memory does my system crash.
I was using the origional PSP toolchain and SDK, and did not have this problem. The exact same code ran fine. Has anyone else seen this issue?
SDK 4.01 memory free error
Well install an exception handler using pspDebugInstallErrorHandler(NULL) in a kernel mode thread and you should get an error display when it crashes. If you need to know how to setup an exception handler look at the exception sample in pspsdk.
It could be dodgy free code but italso could be a stack overflow somewhere corrupting your pointer or any number of other things, the exception handler might at least point to what is going awry.
It could be dodgy free code but italso could be a stack overflow somewhere corrupting your pointer or any number of other things, the exception handler might at least point to what is going awry.
The thread actually receives a pointer to an area of memory that has been initialized correctly. It's just the pointer in the thread points to an area of memory at a different address than what was created in the main thread.
It is as if a the area of memory in main was coppied and created within the thread's memory area. But.. calling free on the memory addess in the thread results in the PSP crashing. This is consistent with the behavior you get when you try to free memory that was not allocated via malloc/new.
I have a strong fealing the debug info would only tell me I am trying to free memory which was not allocated via maloc, which I allready know. In fact, I imagine the debug info won't even display, as the PSP is crashing when free is called, but I will give it a try and see what it shakes out.
It is as if a the area of memory in main was coppied and created within the thread's memory area. But.. calling free on the memory addess in the thread results in the PSP crashing. This is consistent with the behavior you get when you try to free memory that was not allocated via malloc/new.
I have a strong fealing the debug info would only tell me I am trying to free memory which was not allocated via maloc, which I allready know. In fact, I imagine the debug info won't even display, as the PSP is crashing when free is called, but I will give it a try and see what it shakes out.