• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Headkaze

Strange KeyUp event problem

4 posts in this topic

I am writing an engine using SlimDX and as part of its development I am writing an editor so I can easily test things.

So I import the engine as a dll into a standard forms application and then place the SlimDX window inside a scrollable panel.

As part of my testing I am using a KeyUp event to load some textures and display them on some quads. But something strange is happening if I tap the key very fast. It appears to be entering a method twice before it exits like it's being called from another thread.

Here is some code.

[code]private Object m_thisLock = new Object();

private void DisposeLayoutObjects()
{
lock (m_thisLock)
{
Console.WriteLine(String.Format("DisposeLayoutObjects Start (ThreadId:{0})", Thread.CurrentThread.ManagedThreadId));

for (int i = 0; i < MainForm.Layout.ObjectArray.Count; i++)
MainForm.Layout.ObjectArray[i].Dispose();

MainForm.Layout.ObjectArray.Clear();

Console.WriteLine(String.Format("DisposeLayoutObjects End (ThreadId: {0})", Thread.CurrentThread.ManagedThreadId));
}
}
private void LoadLayout()
{
DisposeLayoutObjects()
...
}
protected override void OnKeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Down:
LoadLayout();
break;
}
}
[/code]

I am getting the following output when I tap on the Down key fast.

[code]DisposeLayoutObjects Start (ThreadId:9)
The thread 0xfb8 has exited with code 0 (0x0).
DisposeLayoutObjects Start (ThreadId:9)
DisposeLayoutObjects End (ThreadId: 9)
DisposeLayoutObjects End (ThreadId: 9)[/code]

The thread id is the same, I even added a lock to prevent re-entry. So how is it possible that it's entering DisposeLayoutObjects twice like that?

As a side note my main loop is using Application_Idle event with a PeekMessage for pumping messages. When I tried using a timer I had some UI refresh issues.
0

Share this post


Link to post
Share on other sites
No I'm not registering any other event.

I should have mentioned this earlier but part of the LoadLayout method involves loading a C++/CLI COM dll that uses DirectShow to render video to a texture. It turns out if I don't use this dll the issue does not appear.

I didn't mention it earlier because I didn't think a dll could cause events to go wierd like that but it looks like it can.

I have no idea how the dll is causing this.
0

Share this post


Link to post
Share on other sites
This is driving me insaine. I can not for the life of me figure out how or why DisposeLayoutObjects() can be executed at the same time on the same thread.

Out of interest sake just to prove this is happening if I change the code to the following:

[code]public void DisposeLayoutObjects()
{
lock (m_thisLock)
{
Console.WriteLine(String.Format("DisposeLayoutObjects Start (ThreadId:{0})", Thread.CurrentThread.ManagedThreadId));

foreach (LayoutObject layoutObject in MainForm.Layout.ObjectArray)
layoutObject.Dispose();

MainForm.Layout.ObjectArray.Clear();

Console.WriteLine(String.Format("DisposeLayoutObjects End (ThreadId: {0})", Thread.CurrentThread.ManagedThreadId));
}
}[/code]

Note now I'm using a foreach loop. Now if I press the Down key slowly it works as it should. If I tap the key twice quickly it will break the debugger in the foreach loop with an InvalidOperationException error stating the "Collection was modified; enumeration operation may not execute".
0

Share this post


Link to post
Share on other sites
It turns out it was in my C++/CLI dll afterall. For some reason adding the IsPinDirection check to make sure the pin is PINDIR_OUTPUT fixed the problem. Very strange. If someone could explain to me why I'd very much appreciate it. It's been a long night tracking this issue down.
[source lang="cpp"]HRESULT RenderAllStreams(IFilterGraph2 *pFilterGraph, GUID majortype, BOOL connectExisting)
{
IEnumFilters *pEnumFilters = NULL;
IBaseFilter *pFilter = NULL;
ULONG cFetched;
HRESULT hr;

if (!pFilterGraph)
return E_POINTER;

hr = pFilterGraph->EnumFilters(&pEnumFilters);

if (FAILED(hr))
return hr;

pEnumFilters->Reset();

while(pEnumFilters->Next(1, &pFilter, &cFetched) == S_OK)
{
hr = E_FAIL;

IPin *pPin = NULL, *pPinConnected = NULL;
IEnumPins *pEnumPins = NULL;

pFilter->EnumPins(&pEnumPins);
pEnumPins->Reset();

while (pEnumPins->Next(1, &pPin, NULL) == S_OK)
{
BOOL bMatch = FALSE;
hr = IsPinDirection(pPin, PINDIR_OUTPUT, &bMatch);

if(!bMatch)
{
SAFE_RELEASE(pPin);
continue;
}

if (pPin->ConnectedTo(&pPinConnected) == VFW_E_NOT_CONNECTED)
{
CComPtr <IEnumMediaTypes> piMediaTypes;

if (SUCCEEDED(hr = pPin->EnumMediaTypes(&piMediaTypes)))
{
piMediaTypes->Reset();

AM_MEDIA_TYPE *mediaType;

while (piMediaTypes->Next(1, &mediaType, 0) == NOERROR)
{
if (mediaType->majortype == majortype)
{
hr = pFilterGraph->RenderEx(pPin, connectExisting ? AM_RENDEREX_RENDERTOEXISTINGRENDERERS : 0, NULL);
}

DeleteMediaType(mediaType);
}
}
}

SAFE_RELEASE(pPin);
SAFE_RELEASE(pPinConnected);
}

pEnumPins->Release();
pFilter->Release();
}

pEnumFilters->Release();

return S_OK;
}[/source]
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0