Toggling Fullscreen/Windowed mode via a panel will generate error W1246 (D3DERR_INVALIDCALL). Calling the exact same function through a keystroke will cause no such error.

Full source code:
Code:
#include <acknex.h>
#include <default.c>

var use_fullscreen = 0;
BMAP* square_bmap = "square.png";

function toggle_fullscreen() {
   use_fullscreen = !use_fullscreen;

   if(use_fullscreen) { video_switch (0,0,1); }
   else               { video_switch (0,0,2); }
}

PANEL* test_pan = {
   button(0, 0, square_bmap, square_bmap, square_bmap, toggle_fullscreen, NULL, NULL);
   flags = VISIBLE;
}

function main() {
   mouse_mode = 4;
   on_u = toggle_fullscreen;
   level_load("TestProject.wmb");
}


Clicking the panel button will cause the error, though only the first time. Pressing 'u' will never cause the error.