Too many faces? Windows 8 vs Windows 7


I am creating faces this way:

 while faceIndex <= faceCount

      if((faceIndex) == faceCount)
        placeComponentTool(newComponent, true)

      pts[0] = [rpc_face_array[faceIndex], rpc_face_array[faceIndex + 1], rpc_face_array[faceIndex + 2]]

      pts[1] = [rpc_face_array[faceIndex + 3], rpc_face_array[faceIndex + 4], rpc_face_array[faceIndex + 5]]

      pts[2] = [rpc_face_array[faceIndex + 6], rpc_face_array[faceIndex + 7], rpc_face_array[faceIndex + 8]]
      face = entities.add_face pts

      face.edges[0].soft = true
      face.edges[1].soft = true
      face.edges[2].soft = true

      face.edges[0].smooth = true
      face.edges[1].smooth = true
      face.edges[2].smooth = true

      face.edges[0].hidden = true
      face.edges[1].hidden = true
      face.edges[2].hidden = true

      faceIndex = faceIndex + 9

It works just fine in Windows 7, but for some reason in Windows 8 it crashes with the larger rpc’s. I checked faceCount and some of the larger one’s have 35000 faces. While the others normally have 3000. I’m confused as to why this is causing issues in Windows 8 but not 7.


When you say “crashes”, what do you mean? Does your code fail to run, or does SketchUp crash? If the former, does it draw anything before crashing? Have you got the Ruby Console open to watch for error messages while your code runs? No idea why Windows 8 vs 7 would cause an error during execution of Ruby…


I get a Runtime Error.


It isn’t like SketchUp to raise that kind of error instead of generating a BugSplat. Are you using any compiled extensions? If so, the error may be from one of them, and you could try to track it down by turning them off one-by-one. It is possible somebody coded in a way that can’t deal with large array indices.


Is your faceIndex, 0 based or 1 based ?

I ask because counts are 1 based, and your while loop may be eval’ing 1 time too many.

I also would advise moving the

     if((faceIndex) == faceCount)
        placeComponentTool(newComponent, true)

block after the while loop.

Changing tools inside such a loop could cause other plugin’s ToolsObserver instances to fire, doing things you might not expect to happen.


Wouldn’t that affect both Win 7 and Win 8, and also cause crashes for small arrays as well as large ones?


I’m just pointing out some general things that are better done in another way.

Another question would be whether the code is wrapped in an undo operation, and/or begin … rescue blocks. Seems like a stack overflow.

Still another would be that it looks like a mesh is being built. Why not build it virtually with Geom::PolygonMesh first, then add it to the model using Face#add_mesh within an undo operation ?

Regarding differences in Win7 vs Win8:

  • different runtime versions ?
  • Different OS bitness ?
  • Different SketchUp bitness ?
  • Different available memory ?


I tried creating the skp file in c++. I save the file out and if I import it, it works fine. But if I try importing it again or even just dragging the skp file into the Sketchup window I get the runtime error.

If I just load the file:

definitions = model.definitions
componentdefinition = definitions.load filename

There are no issues. It’s only when using import. Any suggestions on a good free ruby debugger?


The SketchUp Debugger works with SU2014.
Do the same issues happen in SketchUp 2014 ?

Pinging @bugra on this.


I think its something in my c++ code and not ruby or sketchup. I’ll continue debugging.


I found the issue. It was an issue with getting the parent handle.

Just in case others might have a similar issue. I was using EnumWindows().


That makes sense why it was a C++ Runtime Error. Your code does not trap errors ?


And this yielded the wrong result under Windows 8?

You were obtaining the handle to the SketchUp main window?

BOOL CALLBACK MyEnumWindows(HWND hwnd, LPARAM processId)

	LPDWORD lProcessId;	
        GetWindowThreadProcessId(hwnd, lProcessId);
       if(processId == *lProcessId)
		return FALSE;
	return TRUE;

This was the code I was using to get the handle.

EnumWindows(MyEnumWindows, GetCurrentProcessId());