Oic. I guess i got that error too. So how should i solve it?
Main Topics
Browse All TopicsHi, right now i'm testing motion tracker with optical flow. When i run it, it appears to have error.
How should i solve it? I'm new to c++
First-chance exception at 0x00411b98 in Motion Tracker with Optical Flow.exe: 0xC0000005: Access violation writing location 0x02ba9000.
Unhandled exception at 0x00411b98 in Motion Tracker with Optical Flow.exe: 0xC0000005: Access violation writing location 0x02ba9000.
The program '[1540] Motion Tracker with Optical Flow.exe: Native' has exited with code 0 (0x0).
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
As the points should be array of pointers, the allocated memory should be big enough to store the pointers. You want to allocate the space for MAX_COUNT pointers. This means that you multiply the MAX_COUNT by the size of space needed for storing a single pointer. The space for storing a single pointer to the object of "theType" is sizeof(theType*).
However, space for storing a pointer is always independent on the pointed type. This way, you can also write
points[0] = (CvPoint2D32f*)cvAlloc(MAX
By static operation here I mean that the sizeof(void*) is evaluated during the compilation. Depending on the target operating system, it is 4 bytes (32bit OS), or 8 bytes (64bit OS).
Hi, i still got error.
When i click on the output view, it shows this error:
First-chance exception at 0x00411b28 in Motion Tracker with Optical Flow.exe: 0xC0000005: Access violation writing location 0x02401000.
Unhandled exception at 0x00411b28 in Motion Tracker with Optical Flow.exe: 0xC0000005: Access violation writing location 0x02401000.
The program '[3456] Motion Tracker with Optical Flow.exe: Native' has exited with code 0 (0x0).
Working with pointers does not depend on a concrete OS, nor on the disk size. This is also completely unrelated to OpenCV. By the way, I do not use OpenCV at all, so I can give you some general hints related to C++. To simplify the command, you could use:
point[0] = cvAlloc(8000);
i.e. allocate 8000 bytes of memory and give me back the pointer to that memory space (the address of the first byte). However, compiler would complain as the cvAlloc() returns the void pointer -- pointer to the void type. This should be mentally interpreted as "pointer to any type". However, the point[0] is declared as pointer to CvPoint2D32f. This way you have to convert the returned type or using the older, C syntax...
point[0] = (CvPoint2D32f*)cvAlloc(800
or using the newer C++ syntax
point[0] = static_cast<CvPoint2D32f*>(c
Now, you may sometimes want to change the MAX_COUNT. This way the 8000 is not that much visible to say that it is related. Because of that the 8000 is replaced by the
point[0] = (CvPoint2D32f*)cvAlloc(MAX
Here you assume that the single pointer consumes 4 bytes. However, it may happen one day that you switch to the 64bit target executable. Then your code would be incorrect. Technically, the 4 bytes are just enough to store one pointer value. Logically, the 4 on its own says nothing related to pointers. This way it is better to write the 4 as sizeof(void*) which means "that many bytes that are enough for storing a pointer" -- and it will work also for 64bit case because then sizeof(void*) would be 8 instead.
For the error, you may have some problem with pointer again. However, it may be difficult to spot the place where it happens unless you have some more detailed info. Try to debug your application.
Well, call it a program if you wish. I am not that good in English. A console program differs from a windowing program only in human interface: one is using textual interface, the othe graphical interface. This is not the core of your problem.
Your problem is that you have quite a lot of code and you do not know where the bug is. I do not know how you got the source, if you wrote if from scratch, or if you got some other application, some skeleton or like that. Definitely, the problem with accessing memory is not related to the human interface (textual or graphic).
Basically, you may try to debug, you may try to look at the code to understand what each line exactly means, you may try to comment-out some parts of the code to find where the bug is. Unfortunately, you probably should learn the basics (like what the pointer is and how it is implemented) if you want to understand what happens in your code.
>>>> points[0] = (CvPoint2D32f*)cvAlloc(MAX
Change it to
points[0] = (CvPoint2D32f*)cvAlloc(MAX
points[1] = (CvPoint2D32f*)cvAlloc(MAX
If it still crashes, goto menu Debug - Exceptions - Win32 Exceptions and check the c0000005 Access violation to get a break if the exception was thrown.
That way you'll get the exact line where the access violation happened (look at call stack).
Note, the count variable is a global variable initialized to zero. But I couldn't see any statement where it was reset to 0 after use. So, your prog has one shot and after, it probably will crash.
>>>> This is the line of error..
You definitively need to check for count < MAX_COUNT e. g. like
#include <assert.h>
....
for(i = 0; i < color_img->height; i+=step)
{
for(j = 0; j < color_img->width; j+=step)
{
assert(count < MAX_COUNT); // would break in debugger in case the condition is false
points[0][count] = cvPoint2D32f(j, i);
points[1][count] = cvPoint2D32f(j, i);
count++; // count the number of points
}
}
>>>> I do not know where to find it..
You must not find the final source. Check only the call stack window and click to first function beginning from above where you have the code for. CRTOMSG.C is a C runtime function probably outputting a message. It is most likely that it got a NULL pointer instead of a valid char pointer to some message text.
Business Accounts
Answer for Membership
by: peprPosted on 2009-08-07 at 00:40:41ID: 25040559
This often means accessing the memory via uninitialized pointer. I suspect the initialization lines 77 and 78 (at least), namely the
_COUNT*siz eof(points [0][0]));
points[0] = (CvPoint2D32f*)cvAlloc(MAX
Firstly sizeof() should be considered a static operation. Next, the points[0][0] means accessing the first element of memory that is pointed to via points[0]. But the points[0] was not initialized, yet. In other words, it is "accessing memory via NULL pointer".