Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Problem with seek (Read 2637 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Problem with seek

I want to seek ahead by 20 sec.

So i made following code:

Quote
service_ptr_t<file> file_io;
abort_callback_dummy abort;
file_io->seek_ex(3528000,file::seek_from_current,abort);


and put it in mainmenu_command's execute method.

Unfortunately this code crashes foobar2000. 

What's wrong?


Problem with seek

Reply #1
I want to seek ahead by 20 sec.
I guess, you want to seek ahead during playback. You need to use static_api_ptr_t<playback_control>()->playback_seek(20) for this purpose. Seeking in a file will not do, what you want.

Unfortunately this code crashes foobar2000.
That is really no suprise. You are using an uninitialised pointer: service_ptr_t<file> file_io

 

Problem with seek

Reply #2
fbuser's assessment is correct, but I'd like to add some further comments.
When programming, do make an effort to understand the platform you're working with instead of writing syntactically correct but semantically nonsensical code. Do not code by coincidence.

Also, there's no such thing as "it just crashed". If you got an access violation, you have at a minimum the address it occured with, which in your case most probably was around null.
Your code is the smart pointer version of  T* p = 0; p->lol(); No matter what T is, you'll blow up.
Stay sane, exile.