Help - Search - Members - Calendar
Full Version: Runtime error - pure virtual function call
Hydrogenaudio Forums > Hosted Forums > foobar2000 > Development - (fb2k)
halabund
I am trying to build a simple foobar2000 component that allows one to remove items from the playback queue. It seems to work fine, however, when I close foobar2000 I get a "pure virtual function called" error. I believe that I provided implementations for all pure virtual functions in contextmenu_item_simple, so I do not understand why do I get this error.

I posted the full source code of the component (it is very short and simple). Could someone please take a look at it? I am new to both foobar2000 component development and to Microsoft's development tools, so please be gentle.

Is there a way to track down which pure virtual function is being called? I found http://support.microsoft.com/kb/125749 , but couldn't figure out how to set a breakpoint on _purecall(). Opening Debug -> New Breakpoint -> Break at function ... in Visual Studio 2005 Express Edition, and entering "_purecall" does not seem to work.

CODE

#include "../../SDK/foobar2000.h"


DECLARE_COMPONENT_VERSION(
    "Remove from Queue",
    "0.1",
    "Adds a context menu command that removes items from the playback queue.\n"
    "Build date: " __DATE__ "\n"
)


class contextmenu : public contextmenu_item_simple {
public:
    virtual unsigned get_num_items() { return 1; }
    virtual void get_item_name(unsigned p_index, pfc::string_base &p_out) {
        if (p_index == 0)
            p_out = "Remove from Queue";
    }
    virtual void get_item_default_path(unsigned int p_index, pfc::string_base &p_out) {
        if (p_index == 0)
            p_out = "";
    }
    virtual bool get_item_description(unsigned p_index, pfc::string_base &p_out) {
        if (p_index == 0) {
            p_out = "Removes one or more items from the playback queue.";
            return true;
        }
        return false;
    }
    virtual GUID get_item_guid(unsigned p_index) {
        static const GUID myguid = {
            0x7a30812c, 0xce36, 0x4675,
            { 0xbb, 0xfc, 0x3f, 0x3, 0xb, 0xf7, 0x25, 0x68 }
        };
        if (p_index == 0)
            return myguid;
        return pfc::guid_null;
    }
    virtual void context_command(unsigned p_index, const pfc::list_base_const_t<metadb_handle_ptr> &p_data, const GUID &p_caller) {
        if (p_index == 0)
            for (t_size i = 0; i < p_data.get_count(); i++)
                remove_from_queue(p_data[i]);
    }
    void remove_from_queue(metadb_handle_ptr &handle);
};

void contextmenu::remove_from_queue(metadb_handle_ptr &handle) {
    static static_api_ptr_t<playlist_manager> playlist_api;

    if (playlist_api->queue_is_active()) {
        pfc::list_t<t_playback_queue_item> queue_contents;

        playlist_api->queue_get_contents(queue_contents);
        for (int i = int(queue_contents.get_count()-1); i >= 0; i--)
            if (queue_contents[i].m_handle == handle) {
                playlist_api->queue_remove_mask(bit_array_one(i));
                break;
            }
    }
}

static contextmenu_item_factory_t<contextmenu> foo_contextmenu;
Frank Bicking
QUOTE
CODE
void contextmenu::remove_from_queue(metadb_handle_ptr &handle) {
    static static_api_ptr_t<playlist_manager> playlist_api;
    /* ... */
}

This variable should not be declared as static.

CODE
static_api_ptr_t<playlist_manager> playlist_api;

Removing the modifier solved the problem here.
halabund
QUOTE(Frank Bicking @ Jul 13 2007, 11:07) *

CODE
void contextmenu::remove_from_queue(metadb_handle_ptr &handle) {
    static static_api_ptr_t<playlist_manager> playlist_api;
    /* ... */
}

This variable should not be declared as static.

Thanks for the reply! smile.gif

This explains why the error only occurred when the "remove from queue" command has been used at least once.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.