Unhandled exception using CANlib

Hi,

I get an error while using CANlib in my application.
The CAN example from Toradex homepage works fine.
Also the functions Imx7Can_Init(), Imx7Can_Write(), Imx7Can_Read(), and so on are working fine in my app.
I can send and receive frames.
At the end I call Imx7Can_Close() and Imx7Can_Deinit().
Close is also successful, but Deinit not.
I get the following error: “Unhandled exception at 0x0026F245 in app.exe 0xC0000005: Access violation reading location 0x332000AD”

624-unhandexcep.jpg

I can’t give you more details, because debugging deeper in the code is not possible.
If I press the Break-Button I get into the file “dbgfree.c” from visual studio.
Not know what this means.
Can you help me solving this problem?

Kind regards,
kuzco

It’s hard to say what exactly wrong without seeing your code.

static ERROR CAN_Dispose(BYTE byNet)
{
	SysTaskDestroy(s_Can[s_byDriver[byNet]].hRxTask);
	s_Can[s_byDriver[byNet]].hRxTask = INVALID_HANDLE;
	SysTaskDestroy(s_Can[s_byDriver[byNet]].hTxTask);
	s_Can[s_byDriver[byNet]].hTxTask = INVALID_HANDLE;
	Imx7Can_Close(s_Can[s_byDriver[byNet]].hCan); // Close CAN channel
	Sleep(1000); // Only test purpose
	Imx7Can_Deinit(s_Can[s_byDriver[byNet]].hCan);// Deinit CAN #TODO errors at the moment
	return NO_ERROR;
}

The function should deinit CAN.
First, I destroy two task which are responsible for sending and receiving.
After that I close the CAN channel and wait for a second.
Calling Imx7Can_Deinit() throws the exception.
The handle I hand over, is not NULL.
It’s the same handle I use to send, receive and close.

@kuzco,
We are looking into it, we will get back by tomorrow.

@kuzzo,

We tested with our CAN_Demo(…\libDemos\Can_Demo) application from Toradex CE Libraries 2.0-20170524 release, not able to reproduce the issue. Could you please try it using Can_Demo application and let us know your feedback.
if it is able to reproduce the issue with modified mode on Can-Demo application then share the same application with us, it will help us to reproduce the issue.

I tried again with Can_Demo. Think the problem lies in Debug and Release configuration. In Release-config everything works fine. But in Debug-config the error occurs: “Unhandled exception at 0x401F8AEB (msvcr110d.dll) in CANTest.exe …”

So I think the dll is the problem. Because with msvcr110.dll it is ok.

@Kuzco,
Could you please share Cantest.exe application code? We are not able to reproduce the same issue here.

Thank a lot.

Yes, you can download the .zip from our cloud
Get the code

@Kuzco,

We are able to reproduce the problem and found the solution, It will be released in next library release. Is it urgent for you? Do you want preliminary release?

This issue is specific to Visual Studio 2015 and application built for WEC2013. We should use LocalFree to free the memory which was allocated by LocalAlloc.

Thank you.

Very good. When do you plan to release the next lib 2.1?
If it’s possible for you to give me a preliminary release then I would take it.
Because I always have to power off my device if I do changes in my CAN app.

@kuzco,

Please download preliminary version and try it.
Let us know if you face any problem on this.